本文整理汇总了C++中QueryResult::fetch方法的典型用法代码示例。如果您正苦于以下问题:C++ QueryResult::fetch方法的具体用法?C++ QueryResult::fetch怎么用?C++ QueryResult::fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryResult
的用法示例。
在下文中一共展示了QueryResult::fetch方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_account
bool RoSql::load_account(int id, UserInfoEx<RoUser>& info)
{
// TODO: Specify the columns. "SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`level`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip` FROM `%s` WHERE `account_id` = %d",
//
std::string sql = "SELECT * FROM `%s` WHERE `account_id`= '%s'";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
RO_ACCOUNT_TB, MAKE_STRING(id));
if (res->get_row_size() != 1)
{
res->Delete();
_LogDebug_(LN, "No account with id : %d ", id);
return false;
}
Field* field = res->fetch();
if (field)
{
if (res->get_field_size() != 12)
{
LogError(LN, "Incorrect result has been queried out!!!!!!!!!!");
res->Delete();
return false;
}
fetch_account_info(field, info);
}
res->Delete();
return true;
}
示例2: init
void RoItemDB::init(short max_id)
{
if (_inited)
return;
_inited = true;
_max_id = max_id;
_items = new RoDBItem[_max_id];
// Do it for ourself.
string sql = "SELECT `id`,`name_english`,`type`,`price_buy`,`price_sell`,`weight`,`attack`,`defence`,`range`,`slots`,`equip_jobs`,`equip_upper`,`equip_genders`,`equip_locations`,`weapon_level`,`equip_level`,`refineable`,`view` FROM `%s`";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
RO_ITEM_DB_TB);
if (!res)
{
LogError("RO_ITEM_DB", "Empty item db");
return;
}
size_t count = res->get_row_size();
size_t i = 0;
for (; i < count; ++i)
{
Field* f = res->fetch();
if (!fetch_item(f))
break;
res->next();
}
LogSuccess("RO_ITEM_DB", "%d items has been loaded!!", i);
res->Delete();
return;
}
示例3: load_friends
bool RoSql::load_friends(int char_id, std::vector<RoCharFriendInfo>& friends)
{
friends.clear();
string sql = "SELECT c.`account_id`, c.`char_id`, c.`name` FROM `%s` c LEFT JOIN `%s` f ON f.`friend_account` = c.`account_id` AND f.`friend_id` = c.`char_id` WHERE f.`char_id`=%d LIMIT %d";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(), RO_CHAR_TB, RO_FRIEND_TB, char_id, MaxFriendCount);
if (res == NULL)
return true;
size_t count = res->get_row_size();
for (size_t n = 0; n < count; ++n)
{
Field* f = res->fetch();
RoCharFriendInfo fr;
fr._account_id = f[0].get<int>();
fr._char_id = f[1].get<int>();
fr._name = f[2].get<string>();
fr._nick_name = f[2].get<string>();
friends.push_back(fr);
res->next();
}
res->Delete();
return true;
}
示例4: load_hotkey
bool RoSql::load_hotkey(int char_id, std::vector<RoCharHotKey>& keys)
{
keys.clear();
string sql = "SELECT `hotkey`, `type`, `itemskill_id`, `skill_lvl` FROM `%s` WHERE `char_id`=%d LIMIT %d";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(), RO_HOTKEY_TB, char_id, MaxHotKeyCount);
if (res == NULL)
return true;;
size_t count = res->get_row_size();
for (size_t n = 0; n < count; ++n)
{
Field* f = res->fetch();
RoCharHotKey key;
key._id = f[0].get<int>();
key._type = f[1].get<uint16>();
key._lvl = f[2].get<uint16>();
keys.push_back(key);
res->next();
}
res->Delete();
return true;
}
示例5: load_cart
bool RoSql::load_cart(int char_id, std::vector<RoCharItem>& cart_items)
{
cart_items.clear();
string sql = "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`";
for (int i = 0; i <MaxSlotCount; ++i)
sql += ", `card" + conversion_cast<string>(i) + "`";
sql += " FROM `%s` WHERE `char_id`=%d LIMIT %d";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(), RO_CART_TB, char_id, MaxCartCount);
if (res == NULL)
return true;
size_t count = res->get_row_size();
for (size_t n = 0; n < count; ++n)
{
Field* f = res->fetch();
RoCharItem info;
info._id = f[0].get<int>();
info._type = f[1].get<short>();
info._amount = f[2].get<short>();
info._equip = f[3].get<uint16>();
info._identify = f[4].get<char>();
info._refine = f[5].get<char>();
info._attrs = f[6].get<char>();
info._expire_time = f[7].get<unsigned int>();
cart_items.push_back(info);
res->next();
}
res->Delete();
return true;
}
示例6: load_skill
bool RoSql::load_skill(int char_id, std::vector<RoCharSkillInfo>& skills)
{
skills.clear();
string sql = "SELECT `id`, `lv` FROM `%s` WHERE `char_id`=%d LIMIT %d";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(), RO_SKILL_TB, char_id, MaxSkillCount);
if (res == NULL)
return true;
size_t count = res->get_row_size();
for (size_t n = 0; n < count; ++n)
{
Field* f = res->fetch();
RoCharSkillInfo skill;
skill._id = f[0].get<int>();
skill._lvl = f[1].get<int>();
skill._flag = f[2].get<int>();
skills.push_back(skill);
res->next();
}
res->Delete();
return true;
}
示例7: load_chars
size_t RoSql::load_chars(int account_id, RoCharInfoBase*& result)
{
std::string sql = "SELECT `char_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`max_hp`,`hp`,`max_sp`,`sp`,`status_point`,`skill_point`,`option`,`karma`,`manner`,`hair`,`hair_color`,`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom` FROM `%s` WHERE `account_id`='%d'";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
RO_CHAR_TB, account_id);
if (!res)
return 0;
size_t count = res->get_row_size();
if (count == 0)
{
res->Delete();
return 0;
}
result = new RoCharInfoBase[count];
size_t i = 0;
for (; i < count; ++i)
{
Field* f = res->fetch();
if (!f)
break;
RoCharInfoBase* info =result + i;
info->_account_id = account_id;
if (!fetch_chars_info(f, *info))
break;
res->next();
}
res->Delete();
return i;
}
示例8: get_max_char_id
int RoSql::get_max_char_id()
{
std::string sql = "SELECT MAX(`char_id`)+1 FROM `%s`";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
RO_CHAR_TB);
if (res == NULL)
{
_LogDebug_(LN, "NO result when select max char_id");
return 1000;
}
Field* f = res->fetch();
if (f == NULL)
{
res->Delete();
return 1000;
}
int max = f[0].get<int>();
if (max < 1000)
max = 1000;
_LogDebug_(LN, "Max char_id is %d", max);
res->Delete();
return max;
}
示例9: get_max_id
int RoSql::get_max_id()
{
std::string sql = "SELECT MAX(`account_id`)+1 FROM `%s`";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
RO_ACCOUNT_TB);
if (res == NULL)
{
return 1000;
}
Field* f = res->fetch();
if (f == NULL)
{
res->Delete();
return 1000;
}
int max = f[0].get<int>();
res->Delete();
return max;
}
示例10: load_char
bool RoSql::load_char(int char_id, RoCharInfo& info, bool load_everything)
{
info._id = char_id;
std::string sql = "SELECT `account_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`max_hp`,`hp`,`max_sp`,`sp`,`status_point`,`skill_point`,`option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`,`homun_id`,`hair`,`hair_color`,`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`,`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`,`partner_id`,`father`,`mother`,`child`,`fame` FROM `%s` WHERE `char_id`=%d LIMIT 1";
QueryResult* res = DatabaseMgr::get_singleton().query(sql.c_str(),
RO_CHAR_TB, char_id);
if (!res)
{
//_LogDebug_("RO_SQL", "Failed to query!!!!!!!!!!!!!");
return false;
}
size_t count = res->get_row_size();
if (count != 1)
{
//_LogDebug_("RO_SQL", "count is not one, means no invald data");
res->Delete();
return false;
}
Field * f = res->fetch();
if (!f)
{
//_LogDebug_("RO_SQL", "No data fields~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
res->Delete();
return false;
}
fetch_char_info(f, info);
res->Delete();
if (!load_everything)
{
return true;
}
// Or we will load other stuff
// Load memory data.
// load items.
if (!load_items(char_id, info._items))
return false;
// Load cart
if (!load_cart(char_id, info._carts))
return false;
// load storage
// load skill
if (!load_skill(char_id, info._skills))
return false;
// load friends
if (!load_friends(char_id, info._friends))
return false;
// load hotkey
if (!load_hotkey(char_id, info._hotkeys))
return false;
// We are ok here.
return true;
}