本文整理汇总了C++中database::Results::Reset方法的典型用法代码示例。如果您正苦于以下问题:C++ Results::Reset方法的具体用法?C++ Results::Reset怎么用?C++ Results::Reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database::Results
的用法示例。
在下文中一共展示了Results::Reset方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InsertGameDefine
//Just a quick utility function to save from writing lots of verbose code.
void InsertGameDefine(Database::Results& kInsertDefine, const char* szValue, int iValue)
{
kInsertDefine.Bind(1, szValue);
kInsertDefine.Bind(2, iValue);
kInsertDefine.Execute();
kInsertDefine.Reset();
}
示例2: PopulateArrayByExistence
//------------------------------------------------------------------------------
bool CvDatabaseUtility::PopulateArrayByExistence(int*& pArray, const char* szTypeTableName, const char* szDataTableName, const char* szTypeColumn, const char* szFilterColumn, const char* szFilterValue)
{
InitializeArray(pArray, MaxRows(szTypeTableName), -1);
std::string strKey = "_PABE_";
strKey.append(szTypeTableName);
strKey.append(szDataTableName);
strKey.append(szFilterColumn);
Database::Results* pResults = GetResults(strKey);
if(pResults == NULL)
{
char szSQL[512];
sprintf_s(szSQL, "select %s.ID from %s inner join %s on %s = %s.Type where %s = ?", szTypeTableName, szDataTableName, szTypeTableName, szTypeColumn, szTypeTableName, szFilterColumn);
pResults = PrepareResults(strKey, szSQL);
if(pResults == NULL)
return false;
}
if(!pResults->Bind(1, szFilterValue, false))
{
CvAssertMsg(false, GetErrorMessage());
return false;
}
int idx = 0;
while(pResults->Step())
{
pArray[idx++] = pResults->GetInt(0);
}
pResults->Reset();
return true;
}
示例3: PopulateArrayByValue
//------------------------------------------------------------------------------
bool CvDatabaseUtility::PopulateArrayByValue(int*& pArray, const char* szTypeTableName, const char* szDataTableName, const char* szTypeColumn, const char* szFilterColumn, const char* szFilterValue, const char* szValueColumn, int iDefaultValue /* = 0 */, int iMinArraySize /* = 0 */)
{
int iSize = MaxRows(szTypeTableName);
InitializeArray(pArray, (iSize<iMinArraySize)?iMinArraySize:iSize, iDefaultValue);
std::string strKey = "_PABV_";
strKey.append(szTypeTableName);
strKey.append(szDataTableName);
strKey.append(szFilterColumn);
strKey.append(szValueColumn);
Database::Results* pResults = GetResults(strKey);
if(pResults == NULL)
{
char szSQL[512];
sprintf_s(szSQL, "select %s.ID, %s from %s inner join %s on %s = %s.Type where %s = ?", szTypeTableName, szValueColumn, szDataTableName, szTypeTableName, szTypeColumn, szTypeTableName, szFilterColumn);
pResults = PrepareResults(strKey, szSQL);
if(pResults == NULL)
return false;
}
if(!pResults->Bind(1, szFilterValue, false))
{
CvAssertMsg(false, GetErrorMessage());
return false;
}
while(pResults->Step())
{
const int idx = pResults->GetInt(0);
const int value = pResults->GetInt(1);
pArray[idx] = value;
}
pResults->Reset();
return true;
}
示例4: CacheResults
//.........这里部分代码省略.........
kUtility.PopulateArrayByValue(m_piYieldFromKills, "Yields", "Unit_YieldFromKills", "YieldType", "UnitType", szUnitType, "Yield");
kUtility.PopulateArrayByExistence(m_pbFreePromotions, "UnitPromotions", "Unit_FreePromotions", "PromotionType", "UnitType", szUnitType);
kUtility.PopulateArrayByExistence(m_pbUpgradeUnitClass, "UnitClasses", "Unit_ClassUpgrades", "UnitClassType", "UnitType", szUnitType);
kUtility.PopulateArrayByExistence(m_pbUnitAIType, "UnitAIInfos", "Unit_AITypes", "UnitAIType", "UnitType", szUnitType);
kUtility.PopulateArrayByExistence(m_pbNotUnitAIType, "UnitAIInfos", "Unit_NotAITypes", "UnitAIType", "UnitType", szUnitType);
kUtility.PopulateArrayByExistence(m_pbBuilds, "Builds", "Unit_Builds", "BuildType", "UnitType", szUnitType);
kUtility.PopulateArrayByExistence(m_pbGreatPeoples, "Specialists", "Unit_GreatPersons", "GreatPersonType", "UnitType", szUnitType);
kUtility.PopulateArrayByExistence(m_pbBuildings, "Buildings", "Unit_Buildings", "BuildingType", "UnitType", szUnitType);
kUtility.PopulateArrayByExistence(m_pbBuildingClassRequireds, "BuildingClasses", "Unit_BuildingClassRequireds", "BuildingClassType", "UnitType", szUnitType);
//TechTypes
{
//Initialize array to NO_TECH
kUtility.InitializeArray(m_piPrereqAndTechs, "Technologies", (int)NO_TECH);
std::string strKey = "Units - TechTypes";
Database::Results* pResults = kUtility.GetResults(strKey);
if(pResults == NULL)
{
pResults = kUtility.PrepareResults(strKey, "select Technologies.ID from Unit_TechTypes inner join Technologies on TechType = Technologies.Type where UnitType = ?");
}
pResults->Bind(1, szUnitType, -1, false);
int i = 0;
while(pResults->Step())
{
m_piPrereqAndTechs[i++] = pResults->GetInt(0);
}
pResults->Reset();
}
//Unit Unique Names Count
{
std::string strKey = "Units - UniqueNameCount";
Database::Results* pUnitNameCount = kUtility.GetResults(strKey);
if(pUnitNameCount == NULL)
{
pUnitNameCount = kUtility.PrepareResults(strKey, "select count(*) from Unit_UniqueNames where UnitType = ?");
}
pUnitNameCount->Bind(1, szUnitType, -1, false);
pUnitNameCount->Step();
m_iNumUnitNames = pUnitNameCount->GetInt(0);
pUnitNameCount->Reset();
}
//Unit Unique Names
{
if(m_iNumUnitNames > 0)
{
m_paszUnitNames = FNEW(CvString[m_iNumUnitNames], c_eCiv5GameplayDLL, 0);
std::string strKey = "Units - UniqueNames";
Database::Results* pResults = kUtility.GetResults(strKey);
if(pResults == NULL)
{
pResults = kUtility.PrepareResults(strKey, "select UniqueName from Unit_UniqueNames where UnitType = ?");
}
示例5: CacheResults
//.........这里部分代码省略.........
std::string strYieldResultsKey = "Improvements - YieldResults";
Database::Results* pYieldResults = kUtility.GetResults(strYieldResultsKey);
if(pYieldResults == NULL)
{
pYieldResults = kUtility.PrepareResults(strYieldResultsKey, "select Yields.ID, Yield from Improvement_ResourceType_Yields inner join Yields on YieldType = Yields.Type where ImprovementType = ? and ResourceType = ?");
}
pResourceTypes->Bind(1, szImprovementType, lenImprovementType, false);
while(pResourceTypes->Step())
{
const int idx = pResourceTypes->GetInt("ID");
CvImprovementResourceInfo& pResourceInfo = m_paImprovementResource[idx];
const char* szResourceType = pResourceTypes->GetText("ResourceType");
pResourceInfo.m_bResourceMakesValid = pResourceTypes->GetBool("ResourceMakesValid");
pResourceInfo.m_bResourceTrade = pResourceTypes->GetBool("ResourceTrade");
pResourceInfo.m_iDiscoverRand = pResourceTypes->GetInt("DiscoveryRand");
m_piResourceQuantityRequirements[idx] = pResourceTypes->GetInt("QuantityRequirement");
//Populate Yields for structure
kUtility.InitializeArray(pResourceInfo.m_piYieldChange, "Yields");
pYieldResults->Bind(1, szImprovementType, lenImprovementType, false);
pYieldResults->Bind(2, szResourceType, -1, false);
while(pYieldResults->Step())
{
const int yieldIdx = pYieldResults->GetInt("ID");
const int yield = pYieldResults->GetInt("Yield");
pResourceInfo.m_piYieldChange[yieldIdx] = yield;
}
pYieldResults->Reset();
}
pResourceTypes->Reset();
}
const int iNumYields = kUtility.MaxRows("Yields");
#if defined(MOD_BALANCE_CORE)
//AdjacentImprovementYieldChanges
{
const int iNumImprovements = kUtility.MaxRows("Improvements");
CvAssertMsg(iNumImprovements > 0, "Num Improvement Infos <= 0");
kUtility.Initialize2DArray(m_ppiAdjacentImprovementYieldChanges, iNumImprovements, iNumYields);
std::string strKey = "Improvements - AdjacentImprovementYieldChanges";
Database::Results* pResults = kUtility.GetResults(strKey);
if(pResults == NULL)
{
pResults = kUtility.PrepareResults(strKey, "select Yields.ID as YieldID, Improvements.ID as ImprovementID, Yield from Improvement_AdjacentImprovementYieldChanges inner join Yields on YieldType = Yields.Type inner join Improvements on OtherImprovementType = Improvements.Type where ImprovementType = ?");
}
pResults->Bind(1, szImprovementType, lenImprovementType, false);
while(pResults->Step())
{
const int yield_idx = pResults->GetInt(0);
CvAssert(yield_idx > -1);
const int improvement_idx = pResults->GetInt(1);
CvAssert(improvement_idx > -1);
const int yield = pResults->GetInt(2);
示例6: CacheResults
//.........这里部分代码省略.........
std::string strYieldResultsKey = "Improvements - YieldResults";
Database::Results* pYieldResults = kUtility.GetResults(strYieldResultsKey);
if(pYieldResults == NULL)
{
pYieldResults = kUtility.PrepareResults(strYieldResultsKey, "select Yields.ID, Yield from Improvement_ResourceType_Yields inner join Yields on YieldType = Yields.Type where ImprovementType = ? and ResourceType = ?");
}
pResourceTypes->Bind(1, szImprovementType, lenImprovementType, false);
while(pResourceTypes->Step())
{
const int idx = pResourceTypes->GetInt("ID");
CvImprovementResourceInfo& pResourceInfo = m_paImprovementResource[idx];
const char* szResourceType = pResourceTypes->GetText("ResourceType");
pResourceInfo.m_bResourceMakesValid = pResourceTypes->GetBool("ResourceMakesValid");
pResourceInfo.m_bResourceTrade = pResourceTypes->GetBool("ResourceTrade");
pResourceInfo.m_iDiscoverRand = pResourceTypes->GetInt("DiscoveryRand");
m_piResourceQuantityRequirements[idx] = pResourceTypes->GetInt("QuantityRequirement");
//Populate Yields for structure
kUtility.InitializeArray(pResourceInfo.m_piYieldChange, "Yields");
pYieldResults->Bind(1, szImprovementType, lenImprovementType, false);
pYieldResults->Bind(2, szResourceType, -1, false);
while(pYieldResults->Step())
{
const int yieldIdx = pYieldResults->GetInt("ID");
const int yield = pYieldResults->GetInt("Yield");
pResourceInfo.m_piYieldChange[yieldIdx] = yield;
}
pYieldResults->Reset();
}
pResourceTypes->Reset();
}
const int iNumYields = kUtility.MaxRows("Yields");
const int iNumTechs = GC.getNumTechInfos();
CvAssertMsg(iNumTechs > 0, "Num Tech Infos <= 0");
//TechYieldChanges
{
kUtility.Initialize2DArray(m_ppiTechYieldChanges, iNumTechs, iNumYields);
std::string strKey = "Improvements - TechYieldChanges";
Database::Results* pResults = kUtility.GetResults(strKey);
if(pResults == NULL)
{
pResults = kUtility.PrepareResults(strKey, "select Yields.ID as YieldID, Technologies.ID as TechID, Yield from Improvement_TechYieldChanges inner join Yields on YieldType = Yields.Type inner join Technologies on TechType = Technologies.Type where ImprovementType = ?");
}
pResults->Bind(1, szImprovementType, lenImprovementType, false);
while(pResults->Step())
{
const int yield_idx = pResults->GetInt(0);
CvAssert(yield_idx > -1);
const int tech_idx = pResults->GetInt(1);
CvAssert(tech_idx > -1);
示例7: PerformDatabasePostProcessing
//------------------------------------------------------------------------------
bool CvDllDatabaseUtility::PerformDatabasePostProcessing()
{
//Insert any database methods that you would like performed after the database
//has been fully loaded. This method will execute every single time the game
//is run.
//Updates performed here are done AFTER the database has been built or read
//from cache.
Database::Connection* db = GC.GetGameDatabase();
//Update Defines table from references in PostDefines table
db->BeginTransaction();
Database::Results kPostDefines;
//Build insertion statement
Database::Results kInsert;
db->Execute(kInsert, "INSERT INTO Defines(Name, Value) VALUES(?, ?)");
db->SelectAll(kPostDefines, "PostDefines");
while(kPostDefines.Step())
{
const char* szName = kPostDefines.GetText("Name");
const char* szKeyName = kPostDefines.GetText("Key");
const char* szTableName = kPostDefines.GetText("Table");
char szSQL[512];
sprintf_s(szSQL, "select ROWID from %s where Type = '%s' LIMIT 1", szTableName, szKeyName);
Database::Results kLookup;
//Compile the command.
if(db->Execute(kLookup, szSQL))
{
//Run the command.
if(kLookup.Step())
{
//Perform insertion
kInsert.Bind(1, szName);
kInsert.Bind(2, kLookup.GetInt(0));
kInsert.Step();
kInsert.Reset();
}
}
}
// ** Modify ResourceUsage of Resources table **
// Set ResourceUsage to 1 if it's referenced in Unit_ResourceQuantityRequirements
// NOTE: This query could be simplified using the IN operator but when analyzed this
// statement generates faster operations.
const char* szStrategicResource
= "UPDATE Resources SET ResourceUsage = 1 WHERE EXISTS (SELECT * FROM Unit_ResourceQuantityRequirements WHERE ResourceType = Type)";
db->Execute(szStrategicResource);
// Set ResourceUsage to 2 if the Resource has a happiness value greater than 0
const char* szLuxoryResource
= "UPDATE Resources SET ResourceUsage = 2 where Happiness > 0";
db->Execute(szLuxoryResource);
//These are hard-coded GameDefines enum values, let's share them with the database so that they
//get the same amount of love as the DB.
Database::Results kInsertDefine;
if(db->Execute(kInsertDefine, "INSERT OR REPLACE INTO Defines(Name, Value) VALUES(?, ?);"))
{
InsertGameDefine(kInsertDefine, "MAX_CIV_PLAYERS", MAX_CIV_PLAYERS);
InsertGameDefine(kInsertDefine, "MAX_CIV_TEAMS", MAX_CIV_TEAMS);
InsertGameDefine(kInsertDefine, "MAX_MAJOR_CIVS", MAX_MAJOR_CIVS);
InsertGameDefine(kInsertDefine, "MAX_MINOR_CIVS", MAX_MINOR_CIVS);
InsertGameDefine(kInsertDefine, "MAX_PLAYERS", MAX_PLAYERS);
InsertGameDefine(kInsertDefine, "MAX_TEAMS", MAX_TEAMS);
InsertGameDefine(kInsertDefine, "BARBARIAN_PLAYER", BARBARIAN_PLAYER);
InsertGameDefine(kInsertDefine, "BARBARIAN_TEAM", BARBARIAN_TEAM);
#if defined(MOD_GLOBAL_CITY_WORKING)
InsertGameDefine(kInsertDefine, "NUM_CITY_PLOTS", AVG_CITY_PLOTS);
InsertGameDefine(kInsertDefine, "MIN_CITY_RADIUS", MIN_CITY_RADIUS);
InsertGameDefine(kInsertDefine, "MAX_CITY_RADIUS", MAX_CITY_RADIUS);
#else
InsertGameDefine(kInsertDefine, "NUM_CITY_PLOTS", NUM_CITY_PLOTS);
#endif
InsertGameDefine(kInsertDefine, "CITY_HOME_PLOT", CITY_HOME_PLOT);
#if defined(MOD_GLOBAL_CITY_WORKING)
InsertGameDefine(kInsertDefine, "MAX_CITY_RADIUS", MAX_CITY_RADIUS);
InsertGameDefine(kInsertDefine, "MAX_CITY_DIAMETER", (2*MAX_CITY_RADIUS+1));
#else
InsertGameDefine(kInsertDefine, "CITY_PLOTS_RADIUS", CITY_PLOTS_RADIUS);
InsertGameDefine(kInsertDefine, "CITY_PLOTS_DIAMETER", CITY_PLOTS_DIAMETER);
#endif
}
db->EndTransaction();
return true;
}