当前位置: 首页>>代码示例>>C++>>正文


C++ Query函数代码示例

本文整理汇总了C++中Query函数的典型用法代码示例。如果您正苦于以下问题:C++ Query函数的具体用法?C++ Query怎么用?C++ Query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Query函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: strcpy

query::query(int orderid) {
	orderkey = orderid;
	numOfPage = 0;
	offsetOfKey = 0;
	
	for (int i = 0; i < 4; i++)
		result[i] = 0;
	
	result2 = 0;

	for (int i = 0; i < 4; i++)
		fIn[i] = NULL;

	page_int = NULL;
	fIndex = NULL;
	fDec = NULL;

	strcpy(file_name[0], "orderkey.fjl");
	strcpy(file_name[1], "custkey.fjl");
	strcpy(file_name[2], "totalprice.fjl");
	strcpy(file_name[3], "shippriority.fjl");

	Query();
}
开发者ID:OptimusV5,项目名称:C-store,代码行数:24,代码来源:query.cpp

示例2: GuiWarning

void Dialog_Mail::SlotSave()
{
    if (Subj->text().trimmed().isEmpty()) {
        GuiWarning("Предмет сообщения не может быть пустыми!");
        return;
    }
    QSqlQuery Query(Global.DataBase);
    if (Mode == DialogEdit) {
        Query.prepare("UPDATE public.\"Mail\" "
                      "SET \"Sender\"=:Sender,\"Receiver\"=:Receiver,\"Subj\"=:Subj,\"Body\"=:Body "
                      "WHERE \"Id\"=:Idx;");
        Query.bindValue(":Idx",*Idx);
    } else {
        Query.prepare("INSERT INTO public.\"Mail\" "
                      "(\"Sender\",\"Receiver\",\"Subj\",\"Body\") "
                      "VALUES(:Sender,:Receiver,:Subj,:Body)");
    }
    Query.bindValue(":Sender",Global.UserId);
    Query.bindValue(":Receiver",Users[Receiver->currentText()]);
    Query.bindValue(":Subj",Subj->text().trimmed());
    Query.bindValue(":Body",Message->toHtml().trimmed());
    if (!Query.exec()) { GuiSqlError("Ошибка при работе с БД!"); }
    accept();
}
开发者ID:Majestio,项目名称:RegClient,代码行数:24,代码来源:Dialog_Mail.cpp

示例3: Query

void Browse_User::UpdateFunc()
{
    QSqlQuery Query(Global.DataBase);
    QString SearchString = QuoteString(FilterBy->text().trimmed());
    QString Where = "";
    QString QueryString;
    QStringList SearchList;

    if (Mode == buWidget) {
        Where = SearchPrepare(
                    "  POSITION (LOWER(?) IN LOWER(f.\"Name\")) > 0 OR "
                    "  POSITION (LOWER(?) IN LOWER(f.\"Role\")) > 0 OR  "
                    "  POSITION (LOWER(?) IN LOWER(to_char(f.\"StartDate\"::date ,'DD.MM.YYYY' ))) > 0 OR  "
                    "  POSITION (LOWER(?) IN LOWER(f.\"StopDate\")) > 0 OR  "
                    "  POSITION (LOWER(?) IN LOWER(f.\"Position\")) > 0 ",
                &SearchList, SearchString);

        QString QueryString =
                "SELECT * FROM ("
                " SELECT "
                "  u.\"Id\" AS \"Id\", "
                "  u.\"Name\" AS \"Name\", "
                "  COALESCE(r.\"Name\",'-') AS \"Role\", "
                "  u.\"StartDate\" AS \"StartDate\", "
                "  CASE WHEN (u.\"StopDate\" = to_date('1980-01-01', 'YYYY-MM-DD')) THEN 'в штате' ELSE to_char(u.\"StopDate\",'DD-MM-YYYY') END AS \"StopDate\", "
                "  COALESCE(d.\"Name\",'-') AS \"Position\", "
                "  u.\"LongName\" AS \"LongName\" "
                " FROM public.\"Users\" as u "
                " LEFT OUTER JOIN public.\"Rubricator\" AS r ON (r.\"GroupId\" = 1 AND r.\"Id\" = u.\"Role\") "
                " LEFT OUTER JOIN public.\"Rubricator\" AS d ON (d.\"GroupId\" = 2 AND d.\"Id\" = u.\"Position\") "
                " GROUP BY u.\"Id\", r.\"Name\", d.\"Name\" "
                ") AS f "
                +Where
                +OrderBy;
        Query.prepare(QueryString);
        SearchBind(SearchList,&Query,5);
        if (!Query.exec()) { GuiSqlError("Ошибка при работе с БД!"); return; }
        Model->setQuery(Query);
        Model->setHeaderData(0,Qt::Horizontal,tr("Ид"));
        Model->setHeaderData(1,Qt::Horizontal,tr("ФИО"));
        Model->setHeaderData(2,Qt::Horizontal,tr("Права"));
        Model->setHeaderData(3,Qt::Horizontal,tr("Прием"));
        Model->setHeaderData(4,Qt::Horizontal,tr("Увольнение"));
        Model->setHeaderData(5,Qt::Horizontal,tr("Подразделение"));
        Model->setHeaderData(6,Qt::Horizontal,tr("ФИО(полностью)"));

        Table->setModel(Model);
        Table->setItemDelegate(new NotEditableDelegate());
        Table->setColumnHidden(0,true);
        Table->setColumnHidden(6,true);
        TuneTable(Table);
        Table->setSortingEnabled(true);
        Table->horizontalHeader()->setSortIndicator(SortColumn, SortOrder);
        Table->resizeColumnsToContents();
        Table->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
    }
    if (Mode == buService) {
        Where = SearchPrepare(
                    " POSITION (LOWER(?) IN LOWER(f.\"Name\")) > 0",
                &SearchList, SearchString);

        QueryString =
                "SELECT * FROM ( "
                "  SELECT u.\"Id\" AS \"Id\", "
                "  u.\"Name\" AS \"Name\" "
                "  FROM public.\"Users\" AS u, public.\"Service2Users\" AS s "
                "  WHERE u.\"Id\" = s.\"User\" AND s.\"Service\" ="+(*Ref)["Id"].toString()+" "
                ") AS f "
                +Where
                +OrderBy;
        Query.prepare(QueryString);
        SearchBind(SearchList,&Query,1);
        if (!Query.exec()) { GuiSqlError("Ошибка при работе с БД!"); return; }
        Model->setQuery(Query);
        Model->setHeaderData(0,Qt::Horizontal,tr("Ид"));
        Model->setHeaderData(1,Qt::Horizontal,tr("ФИО"));
        Table->setModel(Model);
        Table->setColumnHidden(0,true);
        TuneTable(Table);
        Table->setSortingEnabled(true);
        Table->horizontalHeader()->setSortIndicator(SortColumn, SortOrder);
        Table->resizeColumnsToContents();
        Table->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
    }
    if (Mode == buSelect) {
        Where = SearchPrepare(
                    " POSITION (LOWER(?) IN LOWER(f.\"Name\")) > 0",
                &SearchList, SearchString);


        QueryString =
                " SELECT * FROM ( "
                " SELECT u.\"Id\", u.\"Name\" FROM public.\"Users\" AS u "
                " WHERE u.\"Id\" NOT IN ( "
                "   SELECT u1.\"Id\" FROM public.\"Users\" AS u1, public.\"Service2Users\" AS s "
                "   WHERE s.\"Service\" = 1 AND s.\"User\" = u1.\"Id\" "
                " )) AS f "
                +Where
                +OrderBy;
        Query.prepare(QueryString);
//.........这里部分代码省略.........
开发者ID:Majestio,项目名称:RegClient,代码行数:101,代码来源:Browse_User.cpp

示例4: IsConnected

			bool IsConnected() const throw()
			{
				return Query();
			}
开发者ID:FossilizedCarlos,项目名称:nestopia,代码行数:4,代码来源:NstApiTapeRecorder.hpp

示例5: run

 virtual void run(){
     client().update( "", Query(), BSON( "$set" << BSON( "x" << 1 )) );
     ASSERT( !client().getLastError().empty() );
 }
开发者ID:7segments,项目名称:mongo,代码行数:4,代码来源:directclienttests.cpp

示例6: LOG

BOOL CSplitLayer::Insert(IN LPTSTR lpFileName)
{
    BOOL					bResult			= FALSE;
    HMODULE					hModule			= NULL;
    LPSPLIT_MOD_INFO		pModInfoAddr	= NULL;

    GETINDEX				fpGetIndex;
    SPLIT					fpSplit;
    MERGE					fpMerge;

    do
    {
        hModule = ::LoadLibrary(lpFileName);
        if (!hModule)
        {
            if (GetLastError() != 193)
            {
                //LOG(ErrorLevel, _SPLIT_LAYER_MOD_, _T("加载破碎算法文件 %S 失败 (%d)"), lpFileName, ::GetLastError());
                LOG(_T("插入破入碎算法文件失败!"));
            }
            break;
        }

        //获取导出各函数地址
        //使用编号导出进行验证Dll有效性
        fpGetIndex = (GETINDEX)GetProcAddress(hModule, "GetIndex");
        fpSplit = (SPLIT)GetProcAddress(hModule, "Split");
        fpMerge = (MERGE)GetProcAddress(hModule, "Merge");

        if (!fpGetIndex || !fpSplit || !fpMerge)
        {
            break;
        }

        //查询链表中是否存在节点,存在则不用添加
        pModInfoAddr = Query(fpGetIndex());
        if (pModInfoAddr)
        {
            FreeLibrary(hModule);
            bResult = TRUE;
            break;
        }

        //申请内存块,存放节点
        pModInfoAddr = (LPSPLIT_MOD_INFO)::HeapAlloc(ms_Heap, HEAP_ZERO_MEMORY, sizeof(SPLIT_MOD_INFO));
        if(!pModInfoAddr)
        {
            //LOG(ErrorLevel, _SPLIT_LAYER_MOD_, _T("申请内存失败 (%d)"), ::GetLastError());
            LOG(_T("申请内存失败!"));
            break;
        }

        //初始化
        pModInfoAddr->Index = fpGetIndex();
        pModInfoAddr->fpSplit = fpSplit;
        pModInfoAddr->fpMerge = fpMerge;
        pModInfoAddr->hMod = hModule;

        //将其插入到链表中
        ::WaitForSingleObject(ms_hSynObject, INFINITE);

        pModInfoAddr->NextNode = ms_ListHead;
        ms_ListHead = pModInfoAddr;

        ::SetEvent(ms_hSynObject);

        //所有操作成功
        bResult = TRUE;

    } while (FALSE);


    if(!bResult && hModule)
        ::FreeLibrary(hModule);

    return bResult;
}
开发者ID:zjstest,项目名称:MyManager,代码行数:77,代码来源:SplitLayer.cpp

示例7: Query

//使用Class查询	
bool AnalyseClassCallRelation::QuerybyClass(const string &str, deque<ClassResourceRelation> &qCallPath)
{
	return Query(str, true, qCallPath); 
}
开发者ID:anzizhao,项目名称:MFCSofewareQuery,代码行数:5,代码来源:CreateClassData.cpp

示例8: run

 void run() {
     const char *ns = "querytests.EmptyTail";
     ASSERT_EQUALS( 0, client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, Option_CursorTailable )->getCursorId() );
     insert( ns, BSON( "a" << 0 ) );
     ASSERT( 0 != client().query( ns, QUERY( "a" << 1 ).hint( BSON( "$natural" << 1 ) ), 2, 0, 0, Option_CursorTailable )->getCursorId() );
 }
开发者ID:tanfulai,项目名称:mongo,代码行数:6,代码来源:querytests.cpp

示例9: createOplog

    void createOplog() {
        Lock::GlobalWrite lk;

        const char * ns = "local.oplog.$main";

        bool rs = !cmdLine._replSet.empty();
        if( rs )
            ns = rsoplog;

        Client::Context ctx(ns);

        NamespaceDetails * nsd = nsdetails( ns );

        if ( nsd ) {

            if ( cmdLine.oplogSize != 0 ) {
                int o = (int)(nsd->storageSize() / ( 1024 * 1024 ) );
                int n = (int)(cmdLine.oplogSize / ( 1024 * 1024 ) );
                if ( n != o ) {
                    stringstream ss;
                    ss << "cmdline oplogsize (" << n << ") different than existing (" << o << ") see: http://dochub.mongodb.org/core/increase-oplog";
                    log() << ss.str() << endl;
                    throw UserException( 13257 , ss.str() );
                }
            }

            if( rs ) return;

            DBDirectClient c;
            BSONObj lastOp = c.findOne( ns, Query().sort(reverseNaturalObj) );
            if ( !lastOp.isEmpty() ) {
                OpTime::setLast( lastOp[ "ts" ].date() );
            }
            return;
        }

        /* create an oplog collection, if it doesn't yet exist. */
        BSONObjBuilder b;
        double sz;
        if ( cmdLine.oplogSize != 0 )
            sz = (double)cmdLine.oplogSize;
        else {
            /* not specified. pick a default size */
            sz = 50.0 * 1000 * 1000;
            if ( sizeof(int *) >= 8 ) {
#if defined(__APPLE__)
                // typically these are desktops (dev machines), so keep it smallish
                sz = (256-64) * 1000 * 1000;
#else
                sz = 990.0 * 1000 * 1000;
                boost::intmax_t free = File::freeSpace(dbpath); //-1 if call not supported.
                double fivePct = free * 0.05;
                if ( fivePct > sz )
                    sz = fivePct;
#endif
            }
        }

        log() << "******" << endl;
        log() << "creating replication oplog of size: " << (int)( sz / ( 1024 * 1024 ) ) << "MB..." << endl;

        b.append("size", sz);
        b.appendBool("capped", 1);
        b.appendBool("autoIndexId", false);

        string err;
        BSONObj o = b.done();
        userCreateNS(ns, o, err, false);
        if( !rs )
            logOp( "n", "", BSONObj() );

        /* sync here so we don't get any surprising lag later when we try to sync */
        MemoryMappedFile::flushAll(true);
        log() << "******" << endl;
    }
开发者ID:JakubOboza,项目名称:mongo,代码行数:75,代码来源:oplog.cpp

示例10: Query

void AlertLog::LoadList()
{
    QSqlDatabase db = QSqlDatabase::database();
    QString TextLine, SelectStatement, TimeFilter, NameFilter, PageFilter, LevelFilter;
    QSqlQuery Query(db);
    SelectStatement = "SELECT * FROM Alerts";
    TimeFilter = "Timestamp >= '" + ui->dateTimeEdit_From->text() + "' AND Timestamp <= '" + ui->dateTimeEdit_To->text() + "'";
    if(ui->lineEdit_Name->text().length()>0)
    {
        NameFilter = "Name LIKE '%" + ui->lineEdit_Name->text() + "%'";
    }
    if(ui->comboBox_Level->currentIndex() != 3)
    {
        LevelFilter = "Alert = '" + QString::number(ui->comboBox_Level->currentIndex() - 3) + "'";
    }
    if(ui->comboBox_Page->currentIndex() > 0)
    {
        PageFilter = "Page = '" + ui->comboBox_Page->currentText() + "'";
    }
    QueryString = SelectStatement + " WHERE " + TimeFilter;
    if(NameFilter.length() > 0)
    {
        QueryString = QueryString + " AND " + NameFilter;
    }
    if(PageFilter.length() > 0)
    {
        QueryString = QueryString + " AND " + PageFilter;
    }
    if(LevelFilter.length() > 0)
    {
        QueryString = QueryString + " AND " + LevelFilter;
    }
    Query.exec(QueryString);
    if(!Query.isActive())
    {
        ui->listWidget->clear();
        ui->listWidget->addItem("Failed to open log");
        ui->listWidget->addItem(QueryString);
    }
    else
    {
        ui->listWidget->clear();
        TextLine = "Date/Time";
        TextLine = TextLine.leftJustified(26, ' ');
        TextLine = TextLine + "Page";
        TextLine = TextLine.leftJustified(46, ' ');
        TextLine = TextLine + "Name";
        TextLine = TextLine.leftJustified(66, ' ');
        TextLine = TextLine + "L";
        TextLine = TextLine.leftJustified(71, ' ');
        TextLine = TextLine + "Description";
        TextLine = TextLine.leftJustified(99, ' ');
        ui->listWidget->addItem(TextLine);
        while(Query.next() and ui->listWidget->count() < 10000)
        {
            TextLine = Query.value(0).toString();
            TextLine.truncate(25);
            TextLine = TextLine.leftJustified(26, ' ');
            TextLine = TextLine + Query.value(1).toString();
            TextLine.truncate(45);
            TextLine = TextLine.leftJustified(46, ' ');
            TextLine = TextLine + Query.value(2).toString();
            TextLine.truncate(65);
            TextLine = TextLine.leftJustified(66, ' ');
            TextLine = TextLine + Query.value(3).toString();
            TextLine.truncate(70);
            TextLine = TextLine.leftJustified(71, ' ');
            TextLine = TextLine + Query.value(4).toString();
            TextLine = TextLine.leftJustified(99, ' ');
            ui->listWidget->addItem(TextLine);
        }
        if(ui->listWidget->count() >= 10000)ui->listWidget->addItem("Stopped at 10000 records, you might want to filter that a little");
    }
}
开发者ID:bilenadam,项目名称:aqtlow,代码行数:74,代码来源:alertlog.cpp

示例11: reload

        void reload() {

            list<BSONObj> all;
            {
                scoped_ptr<ScopedDbConnection> conn( ScopedDbConnection::getScopedDbConnection(
                        configServer.getPrimary().getConnString() ) );
                auto_ptr<DBClientCursor> c = conn->get()->query( ShardNS::shard , Query() );
                massert( 13632 , "couldn't get updated shard list from config server" , c.get() );
                while ( c->more() ) {
                    all.push_back( c->next().getOwned() );
                }
                conn->done();
            }

            scoped_lock lk( _mutex );

            // We use the _lookup table for all shards and for the primary config DB. The config DB info,
            // however, does not come from the ShardNS::shard. So when cleaning the _lookup table we leave
            // the config state intact. The rationale is that this way we could drop shards that
            // were removed without reinitializing the config DB information.

            ShardMap::iterator i = _lookup.find( "config" );
            if ( i != _lookup.end() ) {
                ShardPtr config = i->second;
                _lookup.clear();
                _lookup[ "config" ] = config;
            }
            else {
                _lookup.clear();
            }
            _rsLookup.clear();
            
            for ( list<BSONObj>::iterator i=all.begin(); i!=all.end(); ++i ) {
                BSONObj o = *i;
                string name = o["_id"].String();
                string host = o["host"].String();

                long long maxSize = 0;
                BSONElement maxSizeElem = o[ ShardFields::maxSize.name() ];
                if ( ! maxSizeElem.eoo() ) {
                    maxSize = maxSizeElem.numberLong();
                }

                bool isDraining = false;
                BSONElement isDrainingElem = o[ ShardFields::draining.name() ];
                if ( ! isDrainingElem.eoo() ) {
                    isDraining = isDrainingElem.Bool();
                }

                ShardPtr s( new Shard( name , host , maxSize , isDraining ) );

                if ( o["tags"].type() == Array ) {
                    vector<BSONElement> v = o["tags"].Array();
                    for ( unsigned j=0; j<v.size(); j++ ) {
                        s->addTag( v[j].String() );
                    }
                }

                _lookup[name] = s;
                _installHost( host , s );
            }

        }
开发者ID:paulpedersen,项目名称:mongo,代码行数:63,代码来源:shard.cpp

示例12: strlen

bool MySQLConnection::Query(const char* sql, ResultSet* & ref_ptr_set, bool commit_flags)
{
	if (NULL == this->mysql_ || NULL == sql)
	{
		return false;
	}
	else
	{
		//如果查询成功,返回0。如果出现错误,返回非0值
		long len = strlen(sql);
		if (mysql_real_query(this->mysql_, sql, len))
		{
			uint32_t last_errno = mysql_errno(this->mysql_);

			if (HandleMySQLErrno(last_errno))  // If it returns true, an error was handled successfully (i.e. reconnection)
			{
				return Query(sql, ref_ptr_set, commit_flags);             // Try again
			}

			return false;
		}
		else
		{
			MYSQL_RES* ptr_mysql_res = mysql_store_result(this->mysql_);

			if(ptr_mysql_res != NULL)
			{
				my_ulonglong num_rows = mysql_num_rows(ptr_mysql_res);
				if( num_rows > 0x00 )
				{
					ref_ptr_set = new ResultSet(ptr_mysql_res);
				}
				else
				{
					if(ptr_mysql_res != NULL)
					{
						mysql_free_result(ptr_mysql_res);
					}
				}

				if(commit_flags)
				{
					mysql_commit(this->mysql_);
				}
			}
			else // mysql_store_result() returned nothing; should it have?
			{
				uint32_t query_field_count = mysql_field_count(this->mysql_);
				if(0 == query_field_count)
				{
					// query does not return data
					// (it was not a SELECT)
					my_ulonglong affected_rows = mysql_affected_rows(this->mysql_);
					//std::cout << "affected_rows : " << affected_rows << std::endl;
				}
				else // mysql_store_result() should have returned data
				{
					std::cout << "Error: " << mysql_error(this->mysql_) << std::endl;
					return false;
				}
			}
		}
	}

	return true;
}
开发者ID:wuqunyong,项目名称:Timeline,代码行数:66,代码来源:MySQLConnection.cpp

示例13: Query

void LogManager::LoginLog(bool isLogin, DWORD dwAccountID, DWORD dwPID, int bLevel, BYTE bJob, DWORD dwPlayTime)
{
	Query("INSERT DELAYED INTO loginlog%s (type, time, channel, account_id, pid, level, job, playtime) VALUES (%s, NOW(), %d, %u, %u, %d, %d, %u)",
			get_table_postfix(), isLogin ? "'LOGIN'" : "'LOGOUT'", g_bChannel, dwAccountID, dwPID, bLevel, bJob, dwPlayTime);
}
开发者ID:cCorax2,项目名称:Source_code,代码行数:5,代码来源:log.cpp

示例14: run

        virtual bool run(const string& dbname, BSONObj& cmdObj, int x, string& errmsg, BSONObjBuilder& result, bool y) {
            static DBDirectClient db;

            if ( cmdObj["sort"].eoo() )
                return runNoDirectClient( dbname , cmdObj , x, errmsg , result, y );

            string ns = dbname + '.' + cmdObj.firstElement().valuestr();

            BSONObj origQuery = cmdObj.getObjectField("query"); // defaults to {}
            Query q (origQuery);
            BSONElement sort = cmdObj["sort"];
            if (!sort.eoo())
                q.sort(sort.embeddedObjectUserCheck());

            bool upsert = cmdObj["upsert"].trueValue();

            BSONObj fieldsHolder (cmdObj.getObjectField("fields"));
            const BSONObj* fields = (fieldsHolder.isEmpty() ? NULL : &fieldsHolder);

            Projection projection;
            if (fields) {
                projection.init(fieldsHolder);
                if (!projection.includeID())
                    fields = NULL; // do projection in post-processing
            }

            BSONObj out = db.findOne(ns, q, fields);
            if (out.isEmpty()) {
                if (!upsert) {
                    result.appendNull("value");
                    return true;
                }

                BSONElement update = cmdObj["update"];
                uassert(13329, "upsert mode requires update field", !update.eoo());
                uassert(13330, "upsert mode requires query field", !origQuery.isEmpty());
                db.update(ns, origQuery, update.embeddedObjectUserCheck(), true);

                BSONObj gle = db.getLastErrorDetailed(dbname);
                result.append("lastErrorObject", gle);
                if (gle["err"].type() == String) {
                    errmsg = gle["err"].String();
                    return false;
                }

                if (cmdObj["new"].trueValue()) {
                    BSONElement _id = gle["upserted"];
                    if (_id.eoo())
                        _id = origQuery["_id"];

                    out = db.findOne(ns, QUERY("_id" << _id), fields);
                }

            }
            else {

                if (cmdObj["remove"].trueValue()) {
                    uassert(12515, "can't remove and update", cmdObj["update"].eoo());
                    db.remove(ns, QUERY("_id" << out["_id"]), 1);

                    BSONObj gle = db.getLastErrorDetailed(dbname);
                    result.append("lastErrorObject", gle);
                    if (gle["err"].type() == String) {
                        errmsg = gle["err"].String();
                        return false;
                    }

                }
                else {   // update

                    BSONElement queryId = origQuery["_id"];
                    if (queryId.eoo() || getGtLtOp(queryId) != BSONObj::Equality) {
                        // need to include original query for $ positional operator

                        BSONObjBuilder b;
                        b.append(out["_id"]);
                        BSONObjIterator it(origQuery);
                        while (it.more()) {
                            BSONElement e = it.next();
                            if (strcmp(e.fieldName(), "_id"))
                                b.append(e);
                        }
                        q = Query(b.obj());
                    }

                    if (q.isComplex()) // update doesn't work with complex queries
                        q = Query(q.getFilter().getOwned());

                    BSONElement update = cmdObj["update"];
                    uassert(12516, "must specify remove or update", !update.eoo());
                    db.update(ns, q, update.embeddedObjectUserCheck());

                    BSONObj gle = db.getLastErrorDetailed(dbname);
                    result.append("lastErrorObject", gle);
                    if (gle["err"].type() == String) {
                        errmsg = gle["err"].String();
                        return false;
                    }

                    if (cmdObj["new"].trueValue())
//.........这里部分代码省略.........
开发者ID:10genReviews,项目名称:mongo,代码行数:101,代码来源:find_and_modify.cpp

示例15: update

 static void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) {
     client_.update( ns, Query( q ), o, upsert );
 }
开发者ID:tanfulai,项目名称:mongo,代码行数:3,代码来源:querytests.cpp


注:本文中的Query函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。