主题:求助:关于缓存变量的用法
情况是这样的。在数据库中循环取出30个人物的数据 姓名 等级 等等 现在的代码是每循环一次就从数据库中读取一次 是否能先一次性读出30人的数据存放到缓存变量里。然后再循环取出每个人的数据。环境是VS2008 MYSQL数据库。本人才刚接触C++。很多东西都不会。请高人帮忙在下面这段代码上改良一下。万分感谢!
QueryResult *result;
int i;
for (i=0;i<30;++i)
{
result = CharacterDatabase.PQuery("select name,race,class,level,zone from characters where online=0 ORDER BY RAND() LIMIT 1");
if (!result)
break;
Field *fields = result->Fetch();
std::string pname = fields[0].GetCppString();
std::string gname = "";
uint32 race = fields[1].GetUInt32();
uint32 class_ = fields[2].GetUInt32();
uint32 lvl = fields[3].GetUInt32();
uint32 pzoneid = fields[4].GetUInt32();
++clientcount;
data << pname; //player name
data << gname; //guild name
data << uint32( lvl ); //player level
data << uint32( class_ ); //player class
data << uint32( race ); //player race
data << uint8(0); // new 2.4.0
data << uint32( pzoneid ); //player zone id
}
delete result;
QueryResult *result;
int i;
for (i=0;i<30;++i)
{
result = CharacterDatabase.PQuery("select name,race,class,level,zone from characters where online=0 ORDER BY RAND() LIMIT 1");
if (!result)
break;
Field *fields = result->Fetch();
std::string pname = fields[0].GetCppString();
std::string gname = "";
uint32 race = fields[1].GetUInt32();
uint32 class_ = fields[2].GetUInt32();
uint32 lvl = fields[3].GetUInt32();
uint32 pzoneid = fields[4].GetUInt32();
++clientcount;
data << pname; //player name
data << gname; //guild name
data << uint32( lvl ); //player level
data << uint32( class_ ); //player class
data << uint32( race ); //player race
data << uint8(0); // new 2.4.0
data << uint32( pzoneid ); //player zone id
}
delete result;