Example #1
0
	PlayerInfo * db_findPlayerInfo(Connection *conn, const std::string &sql)
	{
		PlayerInfo *info = NULL;
		Statement *stmt = conn->createStatement();
		ResultSet *res = stmt->executeQuery(sql.c_str());

		if (res->next())
		{
			info = new PlayerInfo;

			info->user_id = res->getUInt("user_id");
			std::string user_name = res->getString("user_name");
			size_t size = user_name.size() < MAX_NAME ? user_name.size() : MAX_NAME;
			memcpy(info->user_name, user_name.c_str(), size);
			info->level = res->getInt("level");
			info->gender = res->getInt("gender");
			info->role_id = res->getInt("role_id");
			info->scene_id = res->getInt("scene_id");
			info->x = res->getInt("x");
			info->y = res->getInt("y");
			std::string user_pwd = res->getString("user_pwd");
			size = user_pwd.size() < MAX_PWD ? user_pwd.size() : MAX_PWD;
			memcpy(info->user_pwd, user_pwd.c_str(), size);
		}

		delete stmt;
		delete res;
		return info;
	}
Example #2
0
// Useful callback (maybe) for sqlite3_exec
static int execCallback(void *pCtx, int columns, char *columnData[], char *columnNames[])
{
    ResultSet *pResultSet = static_cast<ResultSet *>(pCtx);
    pResultSet->addRow(columns, columnData, columnNames);

    return 0;
}
Example #3
0
void MergedAuthorDao::load_into(unordered_map<int,int>& id_map)
{
	Connection* conn = NULL;
	Statement* stat = NULL;
	ResultSet* rs = NULL;
	int from, to;
	try
	{
		conn = ConnectionPool::getInstance()->getConnection();
		stat = conn->createStatement();
		rs = stat->executeQuery(sql_fetch);
		while(rs->next())
		{
			from = rs->getInt(1);
			to = rs->getInt(2);
			id_map[from] = to;
		}
		ConnectionPool::close(conn, stat, rs);
	}
	catch (sql::SQLException &e) 
	{
		LOG(ERROR) << boost::str(boost::format("# ERR: SQLException in  %1% %2%") % __FILE__ %__FUNCTION__);
		LOG(ERROR) << boost::str(boost::format("%1% error code %2%") %e.what() % e.getErrorCode());
	}
}
Example #4
0
//验证用户微信号
int ChargeBusiness::VerifyWeixin(string userId, string openId){
    Statement *stmt = NULL;
    int ret = 0;
    try{
        stmt = conn->createStatement(QUERY_USER_SQL);
        stmt->setString(1, userId);
        ResultSet *rs = stmt->executeQuery();
        string user_open_id;
        int id = -1;
        while(rs->next())
        {
            id = rs->getInt(1);
            user_open_id = rs->getString(2);
        }
        if(id == -1){
            ret = 1;
        }else if(user_open_id.empty()){
            conn->terminateStatement(stmt);
            stmt = conn->createStatement(VERIFY_SQL);
            stmt->setString(1, openId);
            stmt->setString(2, userId);
            stmt->executeUpdate();
        }else{
            ret = 2;
        }
        
    }catch(SQLException &sqlExcp){
        HandleException(sqlExcp);
    }catch(std::exception &e){
        HandleException(e);
    }   
    if(stmt)
        conn->terminateStatement(stmt);
    return ret;
}
/**
 * Find the content placeholder with that id
 */
ContentPlaceholder* ContentPlaceholderController::GetContentPlaceholderById(int id)
{
	PreparedStatement* stmt = conn->prepareStatement("SELECT * FROM cph WHERE id = ?");
	
	stmt->setInt(1, id);

	ResultSet* rs = stmt->executeQuery();

	delete stmt;

	if(rs != NULL)
	{
		while(rs->next())
		{
			//Return the content placeholder retrieved by the query
			ContentPlaceholder* c = GenerateContentPlaceholder(*rs);
			delete rs;
			return c;
		}
	}
	else
	{
		return NULL;
	}

	return NULL;
}
Example #6
0
/**
 * Find the latest statistic
 */
Stat* StatController::GetLatestStat()
{
	PreparedStatement* stmt = conn->prepareStatement("SELECT * FROM stats ORDER BY id DESC LIMIT 1");

	ResultSet* rs = stmt->executeQuery();

	delete stmt;

	if(rs != NULL)
	{
		while(rs->next())
		{
			//Return the latest statistic (by id)
			Stat* s = GenerateStat(*rs);
			delete rs;
			return s;
		}
	}
	else
	{
		return NULL;
	}

	return NULL;
}
Example #7
0
void numberOfCCsMaxCC(Graph* g, int* numberOfCCs, int* maxCC) {
	List* intList = g->getAllIDs();
	int numberOfCC = 0;
	int numberOfNodes = 0;
	int maxNumCC = 0;
	LinearHashTable *hashTable = g->getHashTable();
	BucketList **bucketListTable = hashTable->getTable();
	for (int i = 0; i < hashTable->getCurrentBucketNo(); i++) {
		BucketList *bucketList = bucketListTable[i];
		BucketListItem *cur = (BucketListItem*) bucketList->getHead();
		while (cur != NULL) {
			Bucket *bucket = cur->getElement();
			for (int j = 0; j < bucket->getSize(); j++) {
				BucketItem *bi = bucket->getBucketItemByIndex(j);
				int startNodeId = bi->getNodeID();

				numberOfNodes = 0;
				bool skip = true;

				IntegerListItem* listNode = (IntegerListItem*) intList->getHead();
				while (listNode != NULL) {
					if (listNode->getInt() == startNodeId) {
						intList->deleteItem(listNode);
						numberOfCC++;
						numberOfNodes++;
						skip = false;
						break;
					}
					listNode = (IntegerListItem*) listNode->getNext();
				}

				if (!skip) {
					//reachNodeN from each node of the graph
					ResultSet *res = reachNodeN(startNodeId, g);
					Pair* pair;
					while (pair = res->next()) {
						IntegerListItem* searchListNode = (IntegerListItem*) intList->getHead();
						while (searchListNode != NULL) {
							if (searchListNode->getInt() == pair->getNodeId()) {
								intList->deleteItem(searchListNode);
								numberOfNodes++;
								break;
							}
							searchListNode = (IntegerListItem*) searchListNode->getNext();
						}

					}
					//delete res;		//free(): invalid next size (fast):
				}
				if (numberOfNodes > maxNumCC)
					maxNumCC = numberOfNodes;
			}
			cur = (BucketListItem*) cur->getNext();
		}
	}
	delete intList;

	*numberOfCCs = numberOfCC;
	*maxCC = maxNumCC;
}
Example #8
0
   void testExpireOldBindings()
      {
         Url uri;
         //UtlString contact;
         //UtlSList bindings;
         ResultSet results;
         int timeNow = (int)OsDateTime::getSecsSinceEpoch();

         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("getUnexpiredContacts.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         uri.setUserId("900");
         uri.setHostAddress("testdomain.example.com");

         regDb->getUnexpiredContactsUser(uri, timeNow, results);
         int numResults = results.getSize();
         CPPUNIT_ASSERT_EQUAL(2, numResults);

         results.destroyAll();

         regDb->expireOldBindings(uri, "ID9", 900, timeNow, "seqOne", 7);

         regDb->getUnexpiredContactsUser(uri, timeNow, results);
         numResults = results.getSize();
         CPPUNIT_ASSERT_EQUAL(1, numResults);
      }
Example #9
0
attribs_map Catalog::getObjectsNames(ObjectType obj_type, const QString &sch_name, const QString &tab_name, attribs_map extra_attribs)
{
    try
    {
        ResultSet res;
        attribs_map objects;

        extra_attribs[ParsersAttributes::SCHEMA]=sch_name;
        extra_attribs[ParsersAttributes::TABLE]=tab_name;
        executeCatalogQuery(QUERY_LIST, obj_type, res, false, extra_attribs);

        if(res.accessTuple(ResultSet::FIRST_TUPLE))
        {
            do
            {
                objects[res.getColumnValue(ParsersAttributes::OID)]=res.getColumnValue(ParsersAttributes::NAME);
            }
            while(res.accessTuple(ResultSet::NEXT_TUPLE));
        }

        return(objects);
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
Example #10
0
unsigned int CallManager::storeCall(Connection *sqlCon, bool phone, unsigned int client, unsigned int translator)
{
	if (!sqlCon)
		return 0;
	PreparedStatement *pstmt = sqlCon->prepareStatement(
			"INSERT INTO calls SET phone=(?), client=(?), translator=(?), request_time=NOW()");
	pstmt->setInt(1, phone);
	pstmt->setInt(2, client);
	pstmt->setInt(3, translator);

	try {
		pstmt->execute();
	} catch (SQLException &ex) {
		log(LOG_ERROR, "[%s] MySQL error(%d): %s", __func__, ex.getErrorCode(), ex.what());
		delete pstmt;
		return 0;
	}
	delete pstmt;

	pstmt = sqlCon->prepareStatement("SELECT LAST_INSERT_ID()");

	ResultSet *res;
	try {
		res = pstmt->executeQuery();
	} catch (SQLException &ex) {
		log(LOG_ERROR, "[%s] MySQL error(%d): %s", __func__, ex.getErrorCode(), ex.what());
		delete pstmt;
		return 0;
	}
	delete pstmt;
	res->first();
	unsigned int id = res->getInt(1);
	delete res;
	return id;
}
//#include"ui_lineswin.h"
//#include"ui_detailinfowin.h"
TrainLinePanel::TrainLinePanel(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TrainLinePanel)
{
    f_updataDB = true;
    setWindowFlags(Qt::FramelessWindowHint|(windowFlags() & (~Qt::WindowCloseButtonHint)));
    ui->setupUi(this);
//    keyboard = new Soft_Keyboard;

//    connect(ui->listWidget,SIGNAL(doubleClicked(QModelIndex)),keyboard,SLOT(show(QModelIndex)));
//    connect(ui->train_id_lineEdit,SIGNAL(clicked()),keyboard,SLOT(show()));
//    connect(ui->line_name_lineEdit,SIGNAL(clicked()),keyboard,SLOT(show()));


    int trainId = GlobalInfo_t::getCurrentTrainIdFromLocalFile();
    QString sql = QString("select line_name from tb_lines_info where train_id=%1").arg(trainId);
    ResultSet set = GlobalInfo_t::getInstance()->db->query(sql);
    if(set.count()!=0)
    {
        QString lineName = set[0].getPara("line_name");
        ui->currentLineLabel->setText(lineName);
    }
    initLineList();
    initTable();
    ui->stackedWidget->setCurrentIndex(1);
    ui->hideBtn1->setStyleSheet("border:none;background-color: rgba(255, 255, 255, 0);");
    ui->hideBtn2->setStyleSheet("border:none;background-color: rgba(255, 255, 255, 0);");
}
      void testAllNonMatchingDialstrings()
      {
         FallbackRulesUrlMapping* urlmap;
         ResultSet registrations;
         UtlString actual;
         UtlString callTag = "UNK";

         CPPUNIT_ASSERT( urlmap = new FallbackRulesUrlMapping() );
         UtlString simpleXml;
         mFileTestContext->inputFilePath("fallbackrules.xml", simpleXml);
         CPPUNIT_ASSERT( urlmap->loadMappings(simpleXml.data() ) == OS_SUCCESS );

         // use non-matching host name
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations, callTag
                                ) != OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 0 ,  registrations.getSize() );
         registrations.destroyAll();

         // use non-matching user name
         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations, callTag
                                ) != OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 0 ,  registrations.getSize() );
         registrations.destroyAll();

         delete urlmap;         
      }
      void testAllNoDefaultPermutations()
      {
         FallbackRulesUrlMapping* urlmap;
         ResultSet registrations;
         UtlString actual;
         UtlString callTag = "UNK";

         CPPUNIT_ASSERT( urlmap = new FallbackRulesUrlMapping() );
         UtlString simpleXml;
         mFileTestContext->inputFilePath("fallbackrules.xml", simpleXml);
         CPPUNIT_ASSERT( urlmap->loadMappings(simpleXml.data() ) == OS_SUCCESS );

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("boston"),
                                registrations, callTag
                                ) == OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 2 ,  registrations.getSize() );
         getResult( registrations, 0, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         getResult( registrations, 1, "contact", actual);
         ASSERT_STR_EQUAL("sip:[email protected]",actual);
         registrations.destroyAll();

         CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]")
                                ,UtlString("salem"),
                                registrations, callTag
                                ) != OS_SUCCESS );
         CPPUNIT_ASSERT_EQUAL( 0 ,  registrations.getSize() );
         
         delete urlmap;
      }
Example #14
0
//---(*)---Zuskin---20/02/2012---
//void WareCatalog::updateSaleRestrictionByTime(const string& start_time, const string& count_time) {
void WareCatalog::updateSaleRestrictionByTime(const string& start_time, const string& count_time, int id) {
    //ResultSet rs = RDBOperation::getInstance()->getFromTable("sale_time_limit", EmptyObjectFilter(""));
    ResultSet rs = RDBOperation::getInstance()->getFromTable("sale_time_limit", ObjectFilterById(id, "TaxRateGr")); // TaxRateGr because of id field name = 'id'
    //printf("rs.getCountRecord()= %d\n", rs.getCountRecord());
    if ( rs.getCountRecord() > 0 ) {
        //printf("updating record with id=%d\n", id);
        RDBUpdateExpression rdb_expr;
        rdb_expr.addField("start_time", start_time);
        rdb_expr.addField("count_time", count_time);
        //---(+)---
        rdb_expr.where_filter.addWhereCondition("id", "=", id);
        //---------
        
        RDBOperation::getInstance()->updateToDB("sale_time_limit", rdb_expr);
    } else {
        //printf("inserting record with id=%d\n", id);
        RDBInsertExpression rdb_expr;
        rdb_expr.addField("start_time", start_time);
        rdb_expr.addField("count_time", count_time);
        //---(+)---
        rdb_expr.addField("id", id);
        //---------
        RDBOperation::getInstance()->insertToDB("sale_time_limit", rdb_expr);
    }
    
}
Example #15
0
/**
 * Insert the stat into the database
 */
int StatController::AddStat(Stat& stat)
{
	PreparedStatement* stmt = conn->prepareStatement("INSERT INTO stats (users, sheets, feeds, items, comments) VALUES (?,?,?,?,?)");
	//Populate the query based on the passed stat
	stmt->setInt(1, stat.users);
	stmt->setInt(2, stat.sheets);
	stmt->setInt(3, stat.feeds);
	stmt->setInt(4, stat.items);
	stmt->setInt(5, stat.comments);
	//Insert
	stmt->executeUpdate();

	delete stmt;

	//Create another query to get the ID of the inserted stat
	Statement* lastStmt = conn->createStatement();
	ResultSet* rs = lastStmt->executeQuery("SELECT LAST_INSERT_ID()");
	if(rs != NULL)
	{
		while(rs->next())
		{
			int lastId = rs->getInt("LAST_INSERT_ID()");
			delete rs;
			delete lastStmt;
			return lastId;
		}
	}
	else
	{
		delete lastStmt;
		return -1;
	}

	return -1;
}
Example #16
0
attribs_map Catalog::getAttributes(const QString &obj_name, ObjectType obj_type, attribs_map extra_attribs)
{
    try
    {
        ResultSet res;
        attribs_map obj_attribs;

        //Add the name of the object as extra attrib in order to retrieve the data only for it
        extra_attribs[ParsersAttributes::NAME]=obj_name;
        executeCatalogQuery(QUERY_ATTRIBS, obj_type, res, true, extra_attribs);

        if(res.accessTuple(ResultSet::FIRST_TUPLE))
            obj_attribs=changeAttributeNames(res.getTupleValues());

        /* Insert the object type as an attribute of the query result to facilitate the
        import process on the classes that uses the Catalog */
        obj_attribs[ParsersAttributes::OBJECT_TYPE]=QString("%1").arg(obj_type);

        return(obj_attribs);
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
Example #17
0
/**
 * Find the stat with that id
 */
Stat* StatController::GetStatById(int id)
{
	PreparedStatement* stmt = conn->prepareStatement("SELECT * FROM stats WHERE id = ?");
	
	stmt->setInt(1, id);

	ResultSet* rs = stmt->executeQuery();

	delete stmt;

	if(rs != NULL)
	{
		while(rs->next())
		{
			//If a stat matches this id, return it
			Stat* s = GenerateStat(*rs);
			delete rs;
			return s;
		}
	}
	else
	{
		return NULL;
	}

	return NULL;
}
Example #18
0
vector<attribs_map> Catalog::getMultipleAttributes(ObjectType obj_type, attribs_map extra_attribs)
{
    try
    {
        ResultSet res;
        attribs_map tuple;
        vector<attribs_map> obj_attribs;

        executeCatalogQuery(QUERY_ATTRIBS, obj_type, res, false, extra_attribs);
        if(res.accessTuple(ResultSet::FIRST_TUPLE))
        {
            do
            {
                tuple=changeAttributeNames(res.getTupleValues());

                /* Insert the object type as an attribute of the query result to facilitate the
                import process on the classes that uses the Catalog */
                tuple[ParsersAttributes::OBJECT_TYPE]=QString("%1").arg(obj_type);

                obj_attribs.push_back(tuple);
                tuple.clear();
            }
            while(res.accessTuple(ResultSet::NEXT_TUPLE));
        }

        return(obj_attribs);
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
Example #19
0
/**
 * Find the layout with that id
 */
Layout LayoutController::GetLayoutById(int id)
{
	PreparedStatement* stmt = conn->prepareStatement("SELECT * FROM layouts WHERE id = ?");
	
	stmt->setInt(1, id);

	ResultSet* rs = stmt->executeQuery();
	delete stmt;
	
	if(rs != NULL)
	{
		while(rs->next())
		{
			//If a layout matches that id, return it
			return GenerateLayout(*rs);
		}
	}
	else
	{
		Layout l;
		return l;
	}

	Layout l;
	return l;
}
Example #20
0
/**
 * Insert the sheet into the database
 */
int SheetController::AddSheet(Sheet& sheet)
{
	PreparedStatement* stmt = conn->prepareStatement("INSERT INTO sheets (name, username, layoutid) VALUES (?,?,?)");
	//Populate the query with the values from the passed sheet
	stmt->setString(1, sheet.name);
	stmt->setString(2, sheet.username);
	stmt->setInt(3, sheet.layoutId);
	//Insert
	stmt->executeUpdate();

	delete stmt;

	//Create another query to get the ID of the inserted sheet
	Statement* lastStmt = conn->createStatement();
	ResultSet* rs = lastStmt->executeQuery("SELECT LAST_INSERT_ID()");
	if(rs != NULL)
	{
		while(rs->next())
		{
			int lastId = rs->getInt("LAST_INSERT_ID()");
			delete rs;
			delete lastStmt;
			return lastId;
		}
	}
	else
	{
		delete lastStmt;
		return -1;
	}

	return -1;
}
Example #21
0
int ChargeBusiness::GetBalance(string userid, double &balance){
    int ret = 0;
    Statement *stmt = NULL;
    try{
        stmt = conn->createStatement(SQL_BALANCE_UPDATE);
        stmt->setAutoCommit(false);
        stmt->setString(1, userid);
        ResultSet *rs = stmt->executeQuery();
        bool has_result = false;
        while(rs->next())
        {
            balance = rs->getDouble(2);
            has_result = true;
        }
        if(!has_result){
            errors.push_back(string("Exception:can't find customer info!"));
            ret = 1;        
        }
    }catch(SQLException &sqlExcp){
        HandleException(sqlExcp);
        ret = -1;
    }catch(std::exception &e){
        HandleException(e);
        ret = -1;
    }
    Finish();
    if(stmt)
        conn->terminateStatement(stmt);
    return ret;    
}
Example #22
0
bool TEST_CONNECTION(){
	GlobalConfig *gconf = GlobalConfig::Instance();
    if(gconf == NULL || !gconf->Init("../conf/topup.ini")){
	       exit(EXIT_FAILURE);
    }
	ConnectionManager* conn_manager  = ConnectionManager::Instance();
    printf("user:%s\tpasswd:%s\n", gconf->s_db_userName.c_str(), gconf->s_db_passWord.c_str());
    if(conn_manager == NULL || !conn_manager->Init(gconf->s_db_userName,                                                                                                                    
	             gconf->s_db_passWord, gconf->s_db_connString,
	             gconf->n_max_connection, gconf->n_min_connection,
	               gconf->n_inc_connection)){
	       exit(EXIT_FAILURE);
    }	
	Connection *conn = conn_manager->CreateConnection();
	Statement *stmt = conn->createStatement("SELECT ID,ZONE,VALUE,OPERATOR FROM PRODUCT_TBL WHERE ID = :1 AND STATUS != 3");
	stmt->setString(1, "10001");
    ResultSet *rs = stmt->executeQuery();
    while (rs->next())
   {
		string id = rs->getString(1);
		cout << id << endl;
    }
    stmt->closeResultSet(rs);
    conn->terminateStatement(stmt);
	return true;
}
    void authorize(Document & request)
    {
        if(request["data"].Size() > 0)
        {
            if(request["data"][0].HasMember("login") && request["data"][0].HasMember("password"))
            {
                try
                {
                    PreparedStatement * prepstmt;
                    prepstmt = conn->prepareStatement("select ((select pwdhash from users where login=?) = (sha1(?) collate utf8_general_ci) is true) as val;");
                    prepstmt->setString(1, request["data"][0]["login"].GetString());
                    prepstmt->setString(2, request["data"][0]["password"].GetString());
                    ResultSet * rs;
                    rs = prepstmt->executeQuery();
                    rs->next();
                    if(rs->getBoolean("val")) return;
                    throw 4;
                }
                catch(SQLException e)
                {
                    throw 2;
                }

            }
        }
        else throw 0;
    }
Example #24
0
UtlBoolean 
UserLocationDB::hasLocation( const UtlString& identityString ) const
{
   ResultSet resultSet;
   getLocations( identityString, resultSet );
   return ( resultSet.getSize() > 0 );
}
/**
 * Find all content placeholders that belong to the sheet of that id
 */
vector<ContentPlaceholder*> ContentPlaceholderController::GetContentPlaceholdersBySheetId(int sheetId)
{
	PreparedStatement* stmt = conn->prepareStatement("SELECT * FROM cph WHERE sheetid = ?");
	
	stmt->setInt(1, sheetId);

	ResultSet* rs = stmt->executeQuery();

	delete stmt;

	vector<ContentPlaceholder*> cphs;
	if(rs != NULL)
	{
		while(rs->next())
		{
			//For all content placeholders matching the query, add them to the vector
			cphs.push_back(GenerateContentPlaceholder(*rs));
		}

		delete rs;
	}

	return cphs;

}
Example #26
0
void SQLToolWidget::runSQLCommand(void)
{
    try
    {
        ResultSet res;
        QString cmd=sql_cmd_txt->textCursor().selectedText();

        if(cmd.isEmpty())
            cmd=sql_cmd_txt->toPlainText();

        sql_cmd_conn.executeDMLCommand(cmd, res);
        registerSQLCommand(cmd);

        results_parent->setVisible(!res.isEmpty());
        export_tb->setEnabled(!res.isEmpty());
        msgoutput_lst->setVisible(res.isEmpty());

        if(results_tbw->isVisible())
            fillResultsTable(res);
        else
        {
            QLabel *label=new QLabel(trUtf8("SQL command successfully executed. <em>Rows affected <strong>%1</strong></em>").arg(res.getTupleCount()));
            QListWidgetItem *item=new QListWidgetItem;

            item->setIcon(QIcon(":/icones/icones/msgbox_info.png"));
            msgoutput_lst->clear();
            msgoutput_lst->addItem(item);
            msgoutput_lst->setItemWidget(item, label);
        }
    }
    catch(Exception &e)
    {
        showError(e);
    }
}
Example #27
0
        bool
        Find_Impl (ExecutionContextScope *exe_scope,
                   const char *key,
                   ResultSet &results) override
        {
            bool result = false;
            
            Target* target = exe_scope->CalculateTarget().get();
            if (target)
            {
                if (auto clang_modules_decl_vendor = target->GetClangModulesDeclVendor())
                {
                    std::vector <clang::NamedDecl*> decls;
                    ConstString key_cs(key);
                    
                    if (clang_modules_decl_vendor->FindDecls(key_cs, false, UINT32_MAX, decls) > 0 &&
                        !decls.empty())
                    {
                        CompilerType module_type = ClangASTContext::GetTypeForDecl(decls.front());
                        result = true;
                        std::unique_ptr<Language::TypeScavenger::Result> result(new ObjCScavengerResult(module_type));
                        results.insert(std::move(result));
                    }
                }
            }
            
            if (!result)
            {
                Process* process = exe_scope->CalculateProcess().get();
                if (process)
                {
                    const bool create_on_demand = false;
                    auto objc_runtime = process->GetObjCLanguageRuntime(create_on_demand);
                    if (objc_runtime)
                    {
                        auto decl_vendor = objc_runtime->GetDeclVendor();
                        if (decl_vendor)
                        {
                            std::vector<clang::NamedDecl *> decls;
                            ConstString name(key);
                            decl_vendor->FindDecls(name, true, UINT32_MAX, decls);
                            for (auto decl : decls)
                            {
                                if (decl)
                                {
                                    if (CompilerType candidate = ClangASTContext::GetTypeForDecl(decl))
                                    {
                                        result = true;
                                        std::unique_ptr<Language::TypeScavenger::Result> result(new ObjCScavengerResult(candidate));
                                        results.insert(std::move(result));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
Example #28
0
void
DialByNameDB::getContacts (
    const UtlString& digitString,
    ResultSet& rResultSet ) const
{
    // This should erase the contents of the existing resultset
    rResultSet.destroyAll();

    if ( !digitString.isNull() && (m_pFastDB != NULL) )
    {
        // Check the TableInfo table to see whether we need to reload
        // the Tables from the Credential/Permission tables
        SIPDBManager* pSIPDBManager = SIPDBManager::getInstance();
        if ( pSIPDBManager->getDatabaseChangedFlag( "credential" ) || 
             pSIPDBManager->getDatabaseChangedFlag( "permission" )  )
        {
            // Reload this IMDB and rese the changed flags 
            // in the credential and permission tables
            this->load();
        }

        // Thread Local Storage
        m_pFastDB->attach();

        // Search to see if we have a Credential Row
        dbCursor< DialByNameRow > cursor;

        dbQuery query;
        UtlString queryString = "np_digits like '" + digitString + "%'";
        query = queryString;
        if ( cursor.select(query) > 0 ) {
            do {
                UtlHashMap record;
                UtlString* np_identityValue = 
                    new UtlString ( cursor->np_identity );
                UtlString* np_contactValue = 
                    new UtlString ( cursor->np_contact );
                UtlString* np_digitsValue = 
                    new UtlString ( cursor->np_digits );

                // Memory Leak fixes, make shallow copies of static keys
                UtlString* np_identityKey = new UtlString( gNp_identityKey );
                UtlString* np_contactKey = new UtlString( gNp_contactKey );
                UtlString* np_digitsKey = new UtlString( gNp_digitsKey );

                record.insertKeyAndValue ( 
                    np_identityKey, np_identityValue );
                record.insertKeyAndValue ( 
                    np_contactKey, np_contactValue );
                record.insertKeyAndValue ( 
                    np_digitsKey, np_digitsValue );

                rResultSet.addValue(record);
            } while ( cursor.next() );
        }
        // Commit the rows to memory - multiprocess workaround
        m_pFastDB->detach(0);
    }
}
Example #29
0
TEST(mysqlclient, execute_with_result)
{
    CMySQLClient client;
    ASSERT_EQ(0, client.Init());
    ResultSet* rs = client.ExecuteWithResult("select * from t_account", NULL);
    ASSERT_TRUE(rs != NULL);
    ASSERT_TRUE(rs->rowsCount() > 0);
}
Example #30
0
vector<MaintenanceContainer> SqlInterface::getMaintenanceData(){
    ResultSet *rset;
    MaintenanceContainer mContainer;
    int temp2 = 0;
    string query = "select * from maintenance";
    vector<MaintenanceContainer> vContainer;

    if(this == 0 || this == NULL)
        return vContainer;

    stmt = conn->createStatement(query);

    try{
        rset = stmt->executeQuery();
    }
    catch(SQLException ex){
        cout<<"Exception thrown for select"<<endl;
        cout<<"Error number: "<<  ex.getErrorCode() << endl;
        cout<<ex.getMessage() << endl;
    }

    vector<MetaData> data = rset->getColumnListMetaData();

    try{
        while(rset->next()){
            for(unsigned int i = 0; i < data.size(); i++){
                temp = rset->getString(i+1);
                switch(i)
                {
                case 0: temp2 = atoi(temp.c_str());
                    mContainer.setCarId(temp2);
                    break;
                case 1: mContainer.setDamages(temp);
                    break;
                case 2: temp2 = atoi(temp.c_str());
                    mContainer.setCosts(temp2);
                    break;
                case 3: mContainer.setStartDate(temp);
                    break;
                case 4: mContainer.setFinishDate(temp);
                    break;
                }
            }
            vContainer.push_back(mContainer);
        }
    }
    catch(SQLException ex){
        cout<<"Exception thrown for select"<<endl;
        cout<<"Error number: "<<  ex.getErrorCode() << endl;
        cout<<ex.getMessage() << endl;
    }

    stmt->closeResultSet (rset);
    conn->terminateStatement (stmt);

    return vContainer;
}