Fixed clientprefs race condition on first run (bug 3294, r=pred).
This commit is contained in:
parent
04b7b7b9ff
commit
4e7000368f
@ -224,33 +224,20 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
{
|
{
|
||||||
driver = DRIVER_SQLITE;
|
driver = DRIVER_SQLITE;
|
||||||
|
|
||||||
TQueryOp *op = new TQueryOp(Query_CreateTable, 0);
|
if (!Database->DoSimpleQuery(
|
||||||
|
|
||||||
op->SetDatabase(Database);
|
|
||||||
IPreparedQuery *pQuery = Database->PrepareQuery(
|
|
||||||
"CREATE TABLE IF NOT EXISTS sm_cookies \
|
"CREATE TABLE IF NOT EXISTS sm_cookies \
|
||||||
( \
|
( \
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
||||||
name varchar(30) NOT NULL UNIQUE, \
|
name varchar(30) NOT NULL UNIQUE, \
|
||||||
description varchar(255), \
|
description varchar(255), \
|
||||||
access INTEGER \
|
access INTEGER \
|
||||||
)",
|
)"))
|
||||||
error, sizeof(error), &errCode);
|
|
||||||
|
|
||||||
if (pQuery == NULL)
|
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query CreateTable sm_cookies: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to CreateTable sm_cookies: %s", Database->GetError());
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
op->SetCustomPreparedQuery(pQuery);
|
if (!Database->DoSimpleQuery(
|
||||||
|
|
||||||
dbi->AddToThreadQueue(op, PrioQueue_High);
|
|
||||||
|
|
||||||
op = new TQueryOp(Query_CreateTable, 0);
|
|
||||||
op->SetDatabase(Database);
|
|
||||||
|
|
||||||
pQuery = Database->PrepareQuery(
|
|
||||||
"CREATE TABLE IF NOT EXISTS sm_cookie_cache \
|
"CREATE TABLE IF NOT EXISTS sm_cookie_cache \
|
||||||
( \
|
( \
|
||||||
player varchar(65) NOT NULL, \
|
player varchar(65) NOT NULL, \
|
||||||
@ -258,27 +245,17 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
value varchar(100), \
|
value varchar(100), \
|
||||||
timestamp int, \
|
timestamp int, \
|
||||||
PRIMARY KEY (player, cookie_id) \
|
PRIMARY KEY (player, cookie_id) \
|
||||||
)",
|
)"))
|
||||||
error, sizeof(error), &errCode);
|
|
||||||
|
|
||||||
if (pQuery == NULL)
|
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query CreateTable sm_cookie_cache: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to CreateTable sm_cookie_cache: %s", Database->GetError());
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
op->SetCustomPreparedQuery(pQuery);
|
|
||||||
|
|
||||||
dbi->AddToThreadQueue(op, PrioQueue_High);
|
|
||||||
}
|
}
|
||||||
else if (strcmp(identifier, "mysql") == 0)
|
else if (strcmp(identifier, "mysql") == 0)
|
||||||
{
|
{
|
||||||
driver = DRIVER_MYSQL;
|
driver = DRIVER_MYSQL;
|
||||||
|
|
||||||
TQueryOp *op = new TQueryOp(Query_CreateTable, 0);
|
if (!Database->DoSimpleQuery(
|
||||||
op->SetDatabase(Database);
|
|
||||||
|
|
||||||
IPreparedQuery *pQuery = Database->PrepareQuery(
|
|
||||||
"CREATE TABLE IF NOT EXISTS sm_cookies \
|
"CREATE TABLE IF NOT EXISTS sm_cookies \
|
||||||
( \
|
( \
|
||||||
id INTEGER unsigned NOT NULL auto_increment, \
|
id INTEGER unsigned NOT NULL auto_increment, \
|
||||||
@ -286,23 +263,13 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
description varchar(255), \
|
description varchar(255), \
|
||||||
access INTEGER, \
|
access INTEGER, \
|
||||||
PRIMARY KEY (id) \
|
PRIMARY KEY (id) \
|
||||||
)",
|
)"))
|
||||||
error, sizeof(error), &errCode);
|
|
||||||
|
|
||||||
if (pQuery == NULL)
|
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query CreateTable sm_cookies: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to CreateTable sm_cookies: %s", Database->GetError());
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
op->SetCustomPreparedQuery(pQuery);
|
if (!Database->DoSimpleQuery(
|
||||||
|
|
||||||
dbi->AddToThreadQueue(op, PrioQueue_High);
|
|
||||||
|
|
||||||
op = new TQueryOp(Query_CreateTable, 0);
|
|
||||||
op->SetDatabase(Database);
|
|
||||||
|
|
||||||
pQuery = Database->PrepareQuery(
|
|
||||||
"CREATE TABLE IF NOT EXISTS sm_cookie_cache \
|
"CREATE TABLE IF NOT EXISTS sm_cookie_cache \
|
||||||
( \
|
( \
|
||||||
player varchar(65) NOT NULL, \
|
player varchar(65) NOT NULL, \
|
||||||
@ -310,27 +277,16 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
value varchar(100), \
|
value varchar(100), \
|
||||||
timestamp int NOT NULL, \
|
timestamp int NOT NULL, \
|
||||||
PRIMARY KEY (player, cookie_id) \
|
PRIMARY KEY (player, cookie_id) \
|
||||||
)",
|
)"))
|
||||||
error, sizeof(error), &errCode);
|
|
||||||
|
|
||||||
if (pQuery == NULL)
|
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query CreateTable sm_cookie_cache: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to CreateTable sm_cookie_cache: %s", Database->GetError());
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
op->SetCustomPreparedQuery(pQuery);
|
|
||||||
|
|
||||||
dbi->AddToThreadQueue(op, PrioQueue_High);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_pSM->LogError(myself, "Unsupported driver \"%s\"", identifier);
|
g_pSM->LogError(myself, "Unsupported driver \"%s\"", identifier);
|
||||||
Database->Close();
|
goto fatal_fail;
|
||||||
Database = NULL;
|
|
||||||
databaseLoading = false;
|
|
||||||
ProcessQueryCache();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (driver == DRIVER_MYSQL)
|
if (driver == DRIVER_MYSQL)
|
||||||
@ -343,7 +299,7 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
if (InsertCookieQuery == NULL)
|
if (InsertCookieQuery == NULL)
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query InsertCookie: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to prepare query InsertCookie: %s (%i)", error, errCode);
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
InsertDataQuery = Database->PrepareQuery(
|
InsertDataQuery = Database->PrepareQuery(
|
||||||
@ -355,7 +311,7 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
if (InsertDataQuery == NULL)
|
if (InsertDataQuery == NULL)
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query InsertData: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to prepare query InsertData: %s (%i)", error, errCode);
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -368,7 +324,7 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
if (InsertCookieQuery == NULL)
|
if (InsertCookieQuery == NULL)
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query InsertCookie: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to prepare query InsertCookie: %s (%i)", error, errCode);
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
InsertDataQuery = Database->PrepareQuery(
|
InsertDataQuery = Database->PrepareQuery(
|
||||||
@ -379,7 +335,7 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
if (InsertDataQuery == NULL)
|
if (InsertDataQuery == NULL)
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query InsertData: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to prepare query InsertData: %s (%i)", error, errCode);
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,7 +350,7 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
if (SelectDataQuery == NULL)
|
if (SelectDataQuery == NULL)
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query SelectData: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to prepare query SelectData: %s (%i)", error, errCode);
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectIdQuery = Database->PrepareQuery(
|
SelectIdQuery = Database->PrepareQuery(
|
||||||
@ -406,15 +362,40 @@ void ClientPrefs::DatabaseConnect()
|
|||||||
if (SelectIdQuery == NULL)
|
if (SelectIdQuery == NULL)
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Failed to prepare query SelectId: %s (%i)", error, errCode);
|
g_pSM->LogMessage(myself, "Failed to prepare query SelectId: %s (%i)", error, errCode);
|
||||||
return;
|
goto fatal_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
databaseLoading = false;
|
databaseLoading = false;
|
||||||
cell_t result = 0;
|
|
||||||
|
|
||||||
ProcessQueryCache();
|
ProcessQueryCache();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
fatal_fail:
|
||||||
|
if (SelectIdQuery != NULL)
|
||||||
|
{
|
||||||
|
SelectIdQuery->Destroy();
|
||||||
|
SelectIdQuery = NULL;
|
||||||
|
}
|
||||||
|
if (SelectDataQuery != NULL)
|
||||||
|
{
|
||||||
|
SelectDataQuery->Destroy();
|
||||||
|
SelectDataQuery = NULL;
|
||||||
|
}
|
||||||
|
if (InsertCookieQuery != NULL)
|
||||||
|
{
|
||||||
|
InsertCookieQuery->Destroy();
|
||||||
|
InsertCookieQuery = NULL;
|
||||||
|
}
|
||||||
|
if (InsertDataQuery != NULL)
|
||||||
|
{
|
||||||
|
InsertDataQuery->Destroy();
|
||||||
|
InsertDataQuery = NULL;
|
||||||
|
}
|
||||||
|
Database->Close();
|
||||||
|
Database = NULL;
|
||||||
|
databaseLoading = false;
|
||||||
|
ProcessQueryCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientPrefs::AddQueryToQueue( TQueryOp *query )
|
bool ClientPrefs::AddQueryToQueue( TQueryOp *query )
|
||||||
|
@ -63,13 +63,6 @@ void TQueryOp::RunThinkPart()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Query_CreateTable:
|
|
||||||
{
|
|
||||||
m_pQuery->Destroy();
|
|
||||||
m_pQuery = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@ -241,11 +234,6 @@ void TQueryOp::SetPreparedQuery()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TQueryOp::SetCustomPreparedQuery(IPreparedQuery *query)
|
|
||||||
{
|
|
||||||
m_pQuery = query;
|
|
||||||
}
|
|
||||||
|
|
||||||
ParamData::~ParamData()
|
ParamData::~ParamData()
|
||||||
{
|
{
|
||||||
if (cookie)
|
if (cookie)
|
||||||
|
@ -42,7 +42,6 @@ enum querytype
|
|||||||
Query_SelectData,
|
Query_SelectData,
|
||||||
Query_InsertData,
|
Query_InsertData,
|
||||||
Query_SelectId,
|
Query_SelectId,
|
||||||
Query_CreateTable,
|
|
||||||
Query_Connect,
|
Query_Connect,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,7 +78,6 @@ public:
|
|||||||
|
|
||||||
void SetDatabase(IDatabase *db);
|
void SetDatabase(IDatabase *db);
|
||||||
void SetPreparedQuery();
|
void SetPreparedQuery();
|
||||||
void SetCustomPreparedQuery(IPreparedQuery *wrapper);
|
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user