20.11.2009, 13:32
Out of interest do you have any information on this problem? Such as cases where the problem occurred?
#define GAMEMODE_DATABASE "Gamemode.sqlite"
public OnGameModeInit()
{
new DB:db = db_open(GAMEMODE_DATABASE);
if(db) {
db_free_result(db_query(db, "CREATE TABLE IF NOT EXISTS `Users` ( `name` TEXT NOT NULL PRIMARY KEY , `skin` INTEGER NOT NULL DEFAULT 0 )"));
db_close(db);
}
}
public OnPlayerConnect(playerid)
{
if(!IsPlayerNPC(playerid)) {
new DB:db = db_open(GAMEMODE_DATABASE);
if(db) {
new string[128];
format(string, sizeof(string), "SELECT * FROM `Users` WHERE ( `name` = '%s' ) LIMIT 1", ReturnPlayerName(playerid));
new DBResult:result = db_query(db, string);
if(db_num_rows(result)) {
db_get_field_assoc(result, "skin", string, sizeof(string));
gPlayerSkin[playerid] = strval(string);
}
db_free_result(result);
db_close(db);
}
}
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
if(!IsPlayerNPC(playerid)) {
new DB:db = db_open(GAMEMODE_DATABASE);
if(db) {
new string[128];
format(string, sizeof(string), "SELECT * FROM `Users` WHERE ( `name` = '%s' ) LIMIT 1", ReturnPlayerName(playerid));
new DBResult:result = db_query(db, string);
if(db_num_rows(result)) {
format(string, sizeof(string), "UPDATE `Users` SET `skin` = %i WHERE ( `name` = '%s' )", gPlayerSkin[playerid], ReturnPlayerName(playerid));
} else {
format(string, sizeof(string), "INSERT INTO `Users` ( `name` , `skin` ) VALUES ( '%s' , %i )", ReturnPlayerName(playerid), gPlayerSkin[playerid]);
}
db_free_result(result);
db_free_result(db_query(db, string));
db_close(db);
}
}
return 1;
}
stock DBResult:debug_db_query(DB:db, query[])
{
print(query);
return db_query(db, query);
}
#define db_query debug_db_query
strreplace(string "'", "''");