Bazaar developer reference

CvInfosSerializationHelper::ReadDBLookup(FDataStream &, const char *, bool *)

Defined in
CvInfosSerializationHelper.cpp, line 191
Hook name
CivHooks::CvInfosSerializationHelper_ReadDBLookup

Hooks

static bool BeforeCvInfosSerializationHelper_ReadDBLookup(FDataStream& kStream, const char* szTable, bool* bValid, int& result);static void AfterCvInfosSerializationHelper_ReadDBLookup(FDataStream& kStream, const char* szTable, bool* bValid, int& result);static int ReplaceCvInfosSerializationHelper_ReadDBLookup(int (*original)(FDataStream&, const char*, bool*), FDataStream& kStream, const char* szTable, bool* bValid);CivRegisterBefore<CivHooks::CvInfosSerializationHelper_ReadDBLookup>(host, &BeforeCvInfosSerializationHelper_ReadDBLookup);CivRegisterAfter<CivHooks::CvInfosSerializationHelper_ReadDBLookup>(host, &AfterCvInfosSerializationHelper_ReadDBLookup);CivRegisterReplace<CivHooks::CvInfosSerializationHelper_ReadDBLookup>(host, &ReplaceCvInfosSerializationHelper_ReadDBLookup);

Code

189/// Helper function to read a single type (as a string) and find its ID in a database table.190/// Assumes the type is in the table's field "Type"191int ReadDBLookup(FDataStream& kStream, const char* szTable, bool* bValid /*= NULL*/)192{193	FStringFixedBuffer(sTemp, 256);194	kStream >> sTemp;195	if (bValid) *bValid = true;196	if(sTemp.GetLength() > 0 && sTemp != "NO_TYPE")197	{198		Database::Connection* pDB = GC.GetGameDatabase();199		if(pDB)200		{201			Database::Results kResults;202			CvString szCommand;203			szCommand.Format("SELECT ID from %s where Type = ? LIMIT 1", szTable);204			if(pDB->Execute(kResults, szCommand.c_str()))205			{206				kResults.Bind(1, sTemp.c_str());207				if(kResults.Step())208				{209					return kResults.GetInt(0);210				}211				else212					if (bValid) *bValid = false;213			}214		}215		else216			if (bValid) *bValid = false;217	}218	219	return -1;220}

Calls

Called by