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 }
//---------------------------------------------------------------------- // 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 }
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; }
/** * 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; }
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()); } }
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; }
/** * 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; }
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 }
//---------------------------------------------------------------------- // 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; }
////////////////////////////////////////////////////////////////////////////// // 이 패킷은 클라이언트가 아이디와 패스워드를 암호화해서 // 로그인 서버로 전송한다. 로그인 서버는 이 패킷을 받아서 // 플레이어의 아이디와 패스워드가 정확한지 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) }
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 }
//验证用户微信号 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; }
//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; }
///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; }
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) }
int ChargeBusiness::QueryOrder(TopupInfo *topupInfo){ int ret = 0; Statement *stmt = NULL; try{ stmt = conn->createStatement(SQL_CREATE_ORDER); string tbOrderNo = topupInfo->qs_info.tbOrderNo; fprintf(stderr, "ChargeBusiness::QueryOrder %s\n", tbOrderNo.c_str()); stmt->setString(1, tbOrderNo); ResultSet *rs = stmt->executeQuery(); while(rs->next()) { topupInfo->qs_info.tbOrderNo = rs->getString(1); topupInfo->qs_info.coopOrderNo = rs->getString(2); topupInfo->status = (OrderStatus)rs->getInt(3); string ts = rs->getString(4); trans_time(ts, topupInfo->update_time); ret++; } conn->terminateStatement(stmt); }catch(SQLException &sqlExcp){ HandleException(sqlExcp); ret = -1; }catch(std::exception &e){ HandleException(e); ret = -1; } Finish(); if(stmt) conn->terminateStatement(stmt); return ret; }
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; }
//---------------------------------------------------------------------- // init //---------------------------------------------------------------------- void UniqueItemManager::init() throw(Error) { __BEGIN_TRY __BEGIN_DEBUG Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); // DB에서 현재의 값을 읽어온다. Result* pResult = pStmt->executeQuery( "SELECT ItemClass, ItemType FROM UniqueItemInfo"); // 지정된 itemClas, itemType을 Unique Item으로 설정한다. while (pResult->next()) { Item::ItemClass itemClass = (Item::ItemClass)pResult->getInt(1); int itemType = pResult->getInt(2); ItemInfo* pItemInfo = g_pItemInfoManager->getItemInfo(itemClass, itemType); Assert(pItemInfo!=NULL); pItemInfo->setUnique(); } SAFE_DELETE(pStmt); } END_DB(pStmt); __END_CATCH __END_DEBUG }
int main(int argc, char** argv) { USE_NETWORK; using namespace sql; Statement *state; ResultSet *result; Connection *con = DbLib::instance().connect("tcp://127.0.0.1:3306", "root", ""); state = con->createStatement(); state->execute("use net_db"); result = state->executeQuery("select * from g_user"); //printf(" id user_id user_name level profession\n"); printf("%7s%10s%20s%7s%10s\n", "id", "user_id", "user_name", "level", "role_id"); while(result->next()) { int64_t id = result->getInt64("id"); int user_id = result->getInt("user_id"); string user_name = result->getString("user_name"); int level = result->getInt("level"); int profession = result->getInt("role_id"); printf(" %7d ", id); printf(" %10d ", user_id); printf(" %20s ", user_name.c_str()); printf(" %7d ", level); printf(" %10d \n", profession); } delete state; delete con; system("pause"); return 0; }
GQuestElement::ResultType GQuestGiveQuestItemElement::checkCondition(PlayerCreature* pPC ) const { GQuestInventory& inventory = pPC->getGQuestManager()->getGQuestInventory(); inventory.getItems().push_back(m_ItemType); pPC->getPlayer()->sendPacket(inventory.getInventoryPacket()); GCSystemMessage gcSM; gcSM.setMessage("퀘스트 아이템을 획득했습니다."); pPC->getPlayer()->sendPacket(&gcSM); if (m_bSave ) { Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery("INSERT INTO GQuestItemObject(ItemType, OwnerID) VALUES (%u, '%s')", m_ItemType, pPC->getName().c_str()); SAFE_DELETE(pStmt); } END_DB(pStmt) } return OK; }
bool GuildUnion::removeGuild(GuildID_t gID ) throw(Error) { if (m_MasterGuildID == gID ) return false; list<GuildID_t>::iterator itr = findGuildItr(gID); if (itr == m_Guilds.end() ) return false; m_Guilds.erase(itr); Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery("DELETE FROM GuildUnionMember WHERE UnionID = %u and OwnerGuildID = %u", m_UnionID, gID); if (pStmt->getAffectedRowCount() < 1 ) { filelog("GuildUnion.log", "[%u:%u] 탈퇴하려는데 해당 레코드가 없습니다.", m_UnionID, gID); } SAFE_DELETE(pStmt); } END_DB(pStmt); return true; }
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; }
void run() { Connection *con; Statement *state; ResultSet *result; for(int i = 0; i<10000; i++){ con = connpool->GetConnection(); // for(int i = 0; i<1000; 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); }}
/** * The testing logic of the test case. */ dvoid select () { cout << "occipool - Selecting records using ConnectionPool interface" << endl; const string poolUserName = "******"; const string poolPassword = "******"; const string connectString = ""; const string username = "******"; const string passWord = "******"; unsigned int maxConn = 5; unsigned int minConn = 3; unsigned int incrConn = 2; ConnectionPool *connPool; try{ connPool = env->createConnectionPool (poolUserName, poolPassword, connectString, minConn, maxConn, incrConn); if (connPool) cout << "SUCCESS - createConnectionPool" << endl; else cout << "FAILURE - createConnectionPool" << endl; con = connPool->createConnection (username, passWord); if (con) cout << "SUCCESS - createConnection" << endl; else cout << "FAILURE - createConnection" << endl; }catch(SQLException ex) { cout<<"Exception thrown for createConnectionPool"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; return; } cout << "retrieving the data" << endl; try{ stmt = con->createStatement ("SELECT author_id, author_name FROM author_tab"); ResultSet *rset = stmt->executeQuery(); while (rset->next()) { cout << "author_id:" << rset->getInt (1) << endl; cout << "author_name:" << rset->getString (2) << endl; } stmt->closeResultSet (rset); con->terminateStatement (stmt); connPool->terminateConnection (con); env->terminateConnectionPool (connPool); }catch(SQLException ex) { cout<<"Exception thrown for retrieving data"<<endl; cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; } cout << "occipool - done" << endl; } // end of test (Connection *)
void GameServerGroupInfoManager::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("[GameServerGroupInfoManager] GameServerGroupInfo TABLE does not exist!"); pResult->next(); m_MaxWorldID = pResult->getInt(1) + 2; SAFE_DELETE(pStmt); } END_DB(pStmt) m_GameServerGroupInfos = new HashMapGameServerGroupInfo[m_MaxWorldID]; try { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); Result * pResult = pStmt->executeQuery("SELECT `WorldID`, `GroupID`, `GroupName` FROM `GameServerGroupInfo`"); while(pResult->next()) { GameServerGroupInfo * pGameServerGroupInfo = new GameServerGroupInfo(); WorldID_t WorldID = pResult->getInt(1); pGameServerGroupInfo->setWorldID(WorldID); pGameServerGroupInfo->setGroupID(pResult->getInt(2)); pGameServerGroupInfo->setGroupName(pResult->getString(3)); addGameServerGroupInfo(pGameServerGroupInfo, WorldID); } delete pStmt; } catch (SQLQueryException & sqe) { delete pStmt; throw Error(sqe.toString()); } catch (Throwable & t) { cout << t.toString() << endl; } __END_CATCH }
//---------------------------------------------------------------------- // // GSModifyGuildMemberHandler::execute() // //---------------------------------------------------------------------- void GSModifyGuildMemberHandler::execute (GSModifyGuildMember* pPacket, Player* pPlayer ) throw(ProtocolException , Error ) { __BEGIN_TRY __BEGIN_DEBUG_EX #ifdef __SHARED_SERVER__ //cout << "GSModifyGuildMember received" << endl; Assert(pPacket != NULL); // 길드를 가져온다. Guild* pGuild = g_pGuildManager->getGuild(pPacket->getGuildID()); //try { Assert(pGuild != NULL); } catch (Throwable& ) { return; } if (pGuild==NULL) return; // 길드의 멤버인지 확인한다. GuildMember* pGuildMember = pGuild->getMember(pPacket->getName()); //try { Assert(pGuildMember != NULL); } catch (Throwable& ) { return; } if (pGuildMember==NULL) return; // 보낸사람이 길드 마스터인지 확인한다. (길드 마스터를 바꿀때는 예외 ) if (pGuild->getMaster() != pPacket->getSender() && pPacket->getGuildMemberRank() != GuildMember::GUILDMEMBER_RANK_MASTER ) return; if (pGuildMember->getRank() == GuildMember::GUILDMEMBER_RANK_WAIT && pPacket->getGuildMemberRank() == GuildMember::GUILDMEMBER_RANK_NORMAL ) { /////////////////////////////////////////////////////////////////////////////////////// // 길드 멤버 가입을 승인한 경우, DB에 Slayer, Vampire, Ousters 테이블의 GuildID 를 바꾼다. /////////////////////////////////////////////////////////////////////////////////////// Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN" )->createStatement(); if (pGuild->getRace() == Guild::GUILD_RACE_SLAYER ) { pStmt->executeQuery("UPDATE Slayer SET GuildID = %d WHERE Name = '%s'", pGuild->getID(), pGuildMember->getName().c_str()); pStmt->executeQuery("INSERT INTO Messages (Receiver, Message ) VALUES ('%s', '%s' )", pGuildMember->getName().c_str(), g_pStringPool->c_str(STRID_TEAM_JOIN_ACCEPT )); } else if (pGuild->getRace() == Guild::GUILD_RACE_VAMPIRE ) { pStmt->executeQuery("UPDATE Vampire SET GuildID = %d WHERE Name = '%s'", pGuild->getID(), pGuildMember->getName().c_str()); pStmt->executeQuery("INSERT INTO Messages (Receiver, Message ) VALUES ('%s', '%s' )", pGuildMember->getName().c_str(), g_pStringPool->c_str(STRID_CLAN_JOIN_ACCEPT )); } else if (pGuild->getRace() == Guild::GUILD_RACE_OUSTERS ) { pStmt->executeQuery("UPDATE Ousters SET GuildID = %d WHERE Name = '%s'", pGuild->getID(), pGuildMember->getName().c_str()); pStmt->executeQuery("INSERT INTO Messages (Receiver, Message ) VALUES ('%s', '%s' )", pGuildMember->getName().c_str(), g_pStringPool->c_str(STRID_CLAN_JOIN_ACCEPT )); } SAFE_DELETE(pStmt); } END_DB(pStmt) // Guild Member 정보를 변경한다. pGuild->modifyMemberRank(pGuildMember->getName(), pPacket->getGuildMemberRank()); }
int BillingInstance::queryStaticIP(std::string ip, std::string server, queryResult &_rv) { if(_conn == NULL) { return 0; } int retval = 0; Statement *sth = NULL; try { sth = _conn->createStatement(QUERY_STATIC_IP); sth->setAutoCommit(true); sth->setString(1, ip); sth->setString(2, server); std::cerr << "Query execute" << std::endl; ResultSet *rs = sth->executeQuery(); const std::vector<MetaData> md = rs->getColumnListMetaData(); if(rs) { while( rs->next() ) { std::multimap<std::string, std::string> tmp; tmp.clear(); for(int i=0; i < md.size(); ++i) { tmp.insert(std::pair<std::string, std::string>(md.at(i).getString(MetaData::ATTR_NAME), rs->getString(i+1))); } _rv.push_back(tmp); } } sth->closeResultSet(rs); retval = 0; } catch (SQLException &sqlExcp) { std::cerr <<sqlExcp.getErrorCode() << " at " << __FILE__ << "/" << __LINE__ << ": " << sqlExcp.getMessage() << std::endl; retval = sqlExcp.getErrorCode(); } if(sth != NULL) { try { _conn->terminateStatement(sth); } catch (SQLException &sqlExcp) { std::cerr <<sqlExcp.getErrorCode() << " at " << __FILE__ << "/" << __LINE__ << ": " << sqlExcp.getMessage() << std::endl; retval = sqlExcp.getErrorCode(); } } return retval; }
void GQuestStatus::save() throw(Error) { __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery("REPLACE INTO GQuestSave (QuestID, OwnerID, Time, Status) VALUES (%u, '%s', now(), %u)", m_QuestID, m_pOwner->getName().c_str(), m_Status); SAFE_DELETE(pStmt); } END_DB(pStmt); __END_CATCH }
////////////////////////////////////////////////////////////////////////////// // 클라이언트가 PC 의 리스트를 달라고 요청해오면, 로그인 서버는 DB로부터 // PC들의 정보를 로딩해서 LCPCList 패킷에 담아서 전송한다. ////////////////////////////////////////////////////////////////////////////// void CLChangeServerHandler::execute (CLChangeServer* pPacket , Player* pPlayer) throw(ProtocolException , Error) { __BEGIN_TRY __BEGIN_DEBUG_EX #ifdef __LOGIN_SERVER__ Assert(pPacket != NULL); Assert(pPlayer != NULL); LoginPlayer* pLoginPlayer = dynamic_cast<LoginPlayer*>(pPlayer); ServerGroupID_t CurrentServerGroupID = pPacket->getServerGroupID(); pLoginPlayer->setServerGroupID(CurrentServerGroupID); Statement* pStmt = NULL; try { pStmt = g_pDatabaseManager->getConnection("DARKEDEN" )->createStatement(); //---------------------------------------------------------------------- // 이제 LCPCList 패킷을 만들어서 보내자 //---------------------------------------------------------------------- LCPCList lcPCList; pLoginPlayer->makePCList(lcPCList); pLoginPlayer->sendPacket(&lcPCList); pLoginPlayer->setPlayerStatus(LPS_PC_MANAGEMENT); pStmt->executeQuery("UPDATE Player set CurrentServerGroupID = %d WHERE PlayerID = '%s'", (int)pPacket->getServerGroupID(), pLoginPlayer->getID().c_str()); // 쿼리 결과 및 쿼리문 객체를 삭제한다. SAFE_DELETE(pStmt); } catch (SQLQueryException & sce) { //cout << sce.toString() << endl; // 쿼리 결과 및 쿼리문 객체를 삭제한다. SAFE_DELETE(pStmt); throw DisconnectException(sce.toString()); } #endif __END_DEBUG_EX __END_CATCH }
SQL::YKSQLTableSPtr YKOracle::Query(const YKString& sql) { try { Statement* stmt = m_connection->createStatement(sql.ToString()); if (stmt) { ResultSet* rs = stmt->executeQuery(); return YKSQLTableSPtr(new YKOracleTable(rs)); } } catch (SQLException& err) { YK_ExceptionThrow(YKDSException) << YKDSException::E_Query(GetErrorMessage(err)); } return YK_NULL; }