本文整理汇总了C++中Statement::executeQuery方法的典型用法代码示例。如果您正苦于以下问题:C++ Statement::executeQuery方法的具体用法?C++ Statement::executeQuery怎么用?C++ Statement::executeQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statement
的用法示例。
在下文中一共展示了Statement::executeQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
void GuildUnion::create() throw(Error)
{
__BEGIN_TRY
Statement* pStmt = NULL;
BEGIN_DB
{
pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();
pStmt->executeQuery("INSERT INTO GuildUnionInfo (MasterGuildID) VALUES (%u)", m_MasterGuildID);
m_UnionID = pStmt->getInsertID();
list<GuildID_t>::iterator itr = m_Guilds.begin();
for (; itr != m_Guilds.end() ; ++itr )
{
pStmt->executeQuery("INSERT INTO GuildUnionMember (UnionID, OwnerGuildID) VALUES (%u, %u)", m_UnionID, (*itr));
}
SAFE_DELETE(pStmt);
}
END_DB(pStmt);
__END_CATCH
}
示例2: load
//----------------------------------------------------------------------
// load data from database
//----------------------------------------------------------------------
void UserInfoManager::load ()
throw(Error )
{
__BEGIN_TRY
Statement * pStmt;
BEGIN_DB
{
pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();
Result* pResult = pStmt->executeQuery(
"SELECT MAX(WorldID) FROM GameServerGroupInfo"
);
if (pResult->getRowCount() == 0)
{
throw Error("GameServerGroupInfo TABLE does not exist!");
}
pResult->next();
m_MaxWorldID = pResult->getInt(1) + 2;
SAFE_DELETE(pStmt);
}
END_DB(pStmt)
m_UserInfos= new HashMapUserInfo[m_MaxWorldID];
try {
pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();
Result * pResult = pStmt->executeQuery(
"SELECT WorldID, GroupID FROM GameServerGroupInfo"
);
while (pResult->next() ) {
UserInfo * pUserInfo = new UserInfo();
WorldID_t WorldID = pResult->getInt(1);
pUserInfo->setWorldID(WorldID);
pUserInfo->setServerGroupID(pResult->getInt(2));
pUserInfo->setUserNum(0);
addUserInfo(pUserInfo);
}
} catch (SQLQueryException & sqe ) {
// 필살 삭제!
delete pStmt;
throw Error(sqe.toString());
}
// 필살 삭제!
delete pStmt;
__END_CATCH
}
示例3: main
int main(int argc, char* argv[])
{
//初始化连接,创建参数中maxSize一半的连接
connpool.initPool("tcp://127.0.0.1:3306", "root", "123456", 100);
Connection *con;
Statement *state;
ResultSet *result;
con = connpool.GetConnection();
for(int i = 0; i<2; i++)
{
state = con->createStatement();
state->execute("use mysql");
// 查询
result = state->executeQuery("select host,user from user");
// 输出查询
while (result->next())
{
try{
string user = result->getString("user");
string name = result->getString("host");
cout << user << " : " << name << endl;
}catch(sql::SQLException& e){
std::cout<< e.what() <<std::endl;
}
}
result = state->executeQuery("select cust_id,cust_name from customers");
while (result->next())
{
try{
string user = result->getString("cust_id");
string name = result->getString("cust_name");
cout << user << " : " << name << endl;
}catch(sql::SQLException& e){
std::cout<< e.what() <<std::endl;
}
}
std::cout << i << std::endl;
}
delete result;
delete state;
connpool.ReleaseConnection(con);
return 0;
}
示例4: AddStat
/**
* 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;
}
示例5: load_into
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());
}
}
示例6: TEST_CONNECTION
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;
}
示例7: AddSheet
/**
* 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;
}
示例8: execute
void CGCrashReportHandler::execute (CGCrashReport* pPacket , Player* pPlayer)
throw(ProtocolException, Error)
{
__BEGIN_TRY __BEGIN_DEBUG_EX
#ifdef __GAME_SERVER__
Assert(pPacket != NULL);
Assert(pPlayer != NULL);
GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);
Creature* pCreature = pGamePlayer->getCreature();
Statement* pStmt = NULL;
try
{
BEGIN_DB
{
pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();
pStmt->executeQuery("INSERT INTO `CrashReportLog` (`PlayerID`, `Name`, `ReportTime`, `ExecutableTime`, `Version`, `Address`, `Message`, `OS`, `CallStack`) VALUES ('%s', '%s', now(), '%s', %u, '%s', '%s', '%s', '%s')", pGamePlayer->getID().c_str(), pCreature->getName().c_str(), pPacket->getExecutableTime().c_str(), pPacket->getVersion(), pPacket->getAddress().c_str(), pPacket->getMessage().c_str(), pPacket->getOS().c_str(), pPacket->getCallStack().c_str());
SAFE_DELETE(pStmt);
}
END_DB(pStmt)
// 누가 이상한거 날리면 무시하자
} catch(...) { filelog("CrashReport.log", "%s", pPacket->toString().c_str()); }
#endif // __GAME_SERVER__
__END_DEBUG_EX __END_CATCH
}
示例9: isPossibleCreate
//----------------------------------------------------------------------
// is Possible Create
//----------------------------------------------------------------------
bool UniqueItemManager::isPossibleCreate(Item::ItemClass itemClass, ItemType_t itemType)
throw(Error)
{
__BEGIN_TRY
__BEGIN_DEBUG
Statement* pStmt = NULL;
BEGIN_DB
{
pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();
// DB에서 현재의 값을 읽어온다.
Result* pResult = pStmt->executeQuery(
"SELECT LimitNumber, CurrentNumber FROM UniqueItemInfo WHERE ItemClass=%d AND ItemType=%d",
(int)itemClass, (int)itemType);
if (pResult->next())
{
int limitNumber = pResult->getInt(1);
int currentNumber = pResult->getInt(2);
return limitNumber==0 || currentNumber<limitNumber;
}
SAFE_DELETE(pStmt);
}
END_DB(pStmt);
__END_CATCH
__END_DEBUG
return false;
}
示例10: execute
//////////////////////////////////////////////////////////////////////////////
// 이 패킷은 클라이언트가 아이디와 패스워드를 암호화해서
// 로그인 서버로 전송한다. 로그인 서버는 이 패킷을 받아서
// 플레이어의 아이디와 패스워드가 정확한지 DB로부터 읽어서
// 비교한 후, 로그인의 성공 여부를 전송한다.
//////////////////////////////////////////////////////////////////////////////
void CLAgreementHandler::execute (CLAgreement* pPacket , Player* pPlayer)
throw(ProtocolException , Error)
{
__BEGIN_TRY __BEGIN_DEBUG_EX
#ifdef __LOGIN_SERVER__
#ifdef __NETMARBLE_SERVER__
Assert(pPacket != NULL);
Assert(pPlayer != NULL);
LoginPlayer* pLoginPlayer = dynamic_cast<LoginPlayer*>(pPlayer);
Assert(pLoginPlayer != NULL);
if (pPacket->isAgree() )
{
Statement* pStmt = NULL;
BEGIN_DB
{
//----------------------------------------------------------------------
// 넷마블 약관 미동의 리스트에서 삭제
//----------------------------------------------------------------------
pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();
pStmt->executeQuery("DELETE FROM PrivateAgreementRemain WHERE PlayerID = '%s'", pLoginPlayer->getID().c_str());
// 다음 단계로 진행할 수 있게 설정
pLoginPlayer->setAgree(true);
SAFE_DELETE(pStmt);
}
END_DB(pStmt)
}
示例11: destroy
void GuildUnion::destroy() throw(Error)
{
__BEGIN_TRY
Statement* pStmt = NULL;
BEGIN_DB
{
pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();
pStmt->executeQuery("DELETE FROM GuildUnionInfo WHERE UnionID = %u", m_UnionID);
pStmt->executeQuery("DELETE FROM GuildUnionMember WHERE UnionID = %u", m_UnionID);
}
END_DB(pStmt);
__END_CATCH
}
示例12: VerifyWeixin
//验证用户微信号
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;
}
示例13: SelectBestChannel
//through the product info get the best channel to create order
//@return the channel num
int ChargeBusiness::SelectBestChannel(int value, int province, int op, vector<ChannelInfo>& channels){
int ret = 0;
Statement *stmt = NULL;
try{
stmt = conn->createStatement(SQL_SELECT_CHANNEL);
stmt->setInt(1, value); //product value
stmt->setInt(2, province); //provice of product
stmt->setInt(3, op); //operator of product
ResultSet *rs = stmt->executeQuery();
while(rs->next())
{
ChannelInfo channel;
channel.channelId = rs->getInt(1); //channel id
//channel.channelName = rs->getString(2); //channel name
channel.sname = rs->getString(2); //short name
channel.priority = rs->getInt(3); //priority
channel.repeat = rs->getInt(4); //repeat times
channel.discount = rs->getFloat(5); //discount of product
channel.interfaceName = rs->getString(6); //the interface of channel,through it to find the class to handle order
channel.pid = rs->getString(7); //the product id given by channel
channel.private_key = rs->getString(8); //the private key given by channel
channel.query_interval = rs->getInt(9); //query order interval
channels.push_back(channel);
ret++;
}
stmt->closeResultSet(rs);
}catch(std::exception &e){
HandleException(e);
ret = -1;
}
Finish();
if(stmt)
conn->terminateStatement(stmt);
return ret;
}
示例14: GetTmallProduct
///ret = 2 no such product
///ret = 1 exception not find product
int ChargeBusiness::GetTmallProduct(string productId, Product &product){
int ret = 0;
Statement *stmt = NULL;
try{
//初始化数据库连接
stmt = conn->createStatement(SQL_QUERY_PRODUCT);
stmt->setString(1, productId);
ResultSet *rs = stmt->executeQuery();
while (rs->next())
{
product.productId = rs->getString(1);
product.provinceId = rs->getInt(2);
product.price = rs->getInt(3);
product.op = rs->getInt(4);
}
stmt->closeResultSet(rs);
if(product.productId.empty() || product.provinceId == 0){
ret = 2;
}
}
catch(std::exception &e)
{
HandleException(e);
ret = 1;
}
Finish();
if(stmt)
conn->terminateStatement(stmt);
return ret;
}
示例15: checkCondition
GQuestElement::ResultType GQuestGiveEventQuestItemElement::checkCondition(PlayerCreature* pPC ) const
{
if (m_Grade == 0 )
{
GQuestInventory& inventory = pPC->getGQuestManager()->getGQuestInventory();
ItemType_t base;
if (pPC->isVampire() )
{
base = 4 + m_Type - 1;
}
else if (pPC->isSlayer() )
{
base = 7 + m_Type - 1;
}
else if (pPC->isOusters() )
{
base = 10 + m_Type - 1;
}
inventory.getItems().push_back(base);
pPC->getPlayer()->sendPacket(inventory.getInventoryPacket());
Statement* pStmt = NULL;
BEGIN_DB
{
pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();
pStmt->executeQuery("INSERT INTO GQuestItemObject(ItemType, OwnerID) VALUES (%u, '%s')",
base, pPC->getName().c_str());
SAFE_DELETE(pStmt);
}
END_DB(pStmt)
}