Senior Member
Join Date: Jan 2009
Location: Netherlands
|
10-21-2010
, 06:57
sourcemod sqlite problems
|
#1
|
hey there, i'm trying to use sqlite in a plugin
and so far, it can make the database and tables,
and it can fill one of the tables with info...
however, the function i made to check if that info is there... in this case steamid, then it tells me it's not there
anyway, here's my code:
PHP Code:
#pragma semicolon 1
#include <sourcemod> #include <sdktools> #include <tf2> #include <tf2_stocks> #include <sdkhooks> #define PLUGIN_VERSION "0.0.1"
public Plugin:myinfo = { name = "sqlstuff", author = "CrancK", description = "", version = PLUGIN_VERSION, url = "" };
new Handle:dbcSkills = INVALID_HANDLE; new bool:pluginEnabled = true;
public OnPluginStart() { RegConsoleCmd("sm_regme", Command_RegisterMe); RegConsoleCmd("sm_checkme", Command_CheckMe); dbConnect(); }
public Action:Command_RegisterMe(client, args) { if(pluginEnabled) { if(CreateDBPlayerEntry(client)) { ReplyToCommand(client, "player added to database"); } else { ReplyToCommand(client, "error: player not added to database"); } } }
public Action:Command_CheckMe(client, args) { if(pluginEnabled) { if(IsPlayerInDB(client)) { ReplyToCommand(client, "player found in database"); } else { ReplyToCommand(client, "player not found in database"); } } }
//database functions
dbConnect() { if(pluginEnabled) { PrintToServer("trying to connect to database"); new String:error[255]; dbcSkills = SQL_Connect("dbSkills", true, error, sizeof(error)); new String:query[512]; if (dbcSkills == INVALID_HANDLE) { PrintToServer("Could not connect to skillrank: %s", error); } else { // Create table skillrank if it dont exist Format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS 'Players' ( 'steamId' VARCHAR(32) NOT NULL PRIMARY KEY, 'nickName' VARCHAR(32) NOT NULL)"); if (!SQL_Query(dbcSkills, query)) { SQL_GetError(dbcSkills, error, sizeof(error)); PrintToServer("Failed to query (error: %s)", error); } else { PrintToServer("table Players created if it didn't already exist"); } } CloseHandle(dbcSkills); // Create table skillmaps if it dont exist dbcSkills = SQL_Connect("dbSkills", true, error, sizeof(error)); if (dbcSkills == INVALID_HANDLE) { PrintToServer("Could not connect to skillrank: %s,", error); } else { Format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS 'RunTimes' ('number' INT(11) NOT NULL PRIMARY KEY, 'steamId' VARCHAR(32) NOT NULL, 'mapName' VARCHAR(32) NOT NULL, 'playerClass' INT NOT NULL, 'curDate' VARCHAR(32) NOT NULL, 'curTime' VARCHAR(10) NOT NULL, 'shots' INT NOT NULL, 'runTime' INT NOT NULL)"); if (!SQL_Query(dbcSkills, query)) { SQL_GetError(dbcSkills, error, sizeof(error)); PrintToServer("Failed to query (error: %s)", error); } else { PrintToServer("table RunTimes created if it didn't already exist"); } } CloseHandle(dbcSkills); // Create table skillmaps if it dont exist dbcSkills = SQL_Connect("dbSkills", true, error, sizeof(error)); if (dbcSkills == INVALID_HANDLE) { PrintToServer("Could not connect to skillrank: %s,", error); } else { Format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS 'MapStats' ( 'mapName' VARCHAR(32) NOT NULL PRIMARY KEY, 'difficulty' int(11) NOT NULL, 'startPosX' FLOAT(14,6) NOT NULL, 'startPosY' FLOAT(14,6) NOT NULL, 'startPosZ' FLOAT(14,6) NOT NULL, 'finishPosX' FLOAT(14,6) NOT NULL, 'finishPosY' FLOAT(14,6) NOT NULL, 'finishPosZ' FLOAT(14,6) NOT NULL)"); if (!SQL_Query(dbcSkills, query)) { SQL_GetError(dbcSkills, error, sizeof(error)); PrintToServer("Failed to query (error: %s)", error); } else { PrintToServer("table MapStats created if it didn't already exist"); } } CloseHandle(dbcSkills); } }
CreateDBPlayerEntry(client) { if(pluginEnabled) { new String:error[255], String:steamId[32]; dbcSkills = SQL_Connect("dbSkills", true, error, sizeof(error)); decl String:query[512]; new String:cname[64]; GetClientName(client, cname, sizeof(cname)); GetClientAuthString(client, steamId, sizeof(steamId)); if (dbcSkills == INVALID_HANDLE) { PrintToServer("Could not connect to skillrank: %s", error); } else { Format(query, sizeof(query), "INSERT INTO 'Players' ( 'steamId', 'nickName' ) VALUES ( '%s', '%s' )", steamId, cname); if (!SQL_Query(dbcSkills, query)) { SQL_GetError(dbcSkills, error, sizeof(error)); PrintToServer("CreateDBPlayerEntry: Failed to query (error: %s)", error); } else { PrintToServer("Player %s added to Players", cname); return true; } } CloseHandle(dbcSkills); } return false; }
IsPlayerInDB(client) { if(pluginEnabled) { new String:error[255], String:steamId[32]; dbcSkills = SQL_Connect("dbSkills", true, error, sizeof(error)); new String:query[512]; new Handle:results; GetClientAuthString(client, steamId, sizeof(steamId)); if (dbcSkills == INVALID_HANDLE) { PrintToServer("Could not connect to skillrank: %s", error); } else { Format(query, sizeof(query), "SELECT * from 'Players' WHERE 'steamId'='%s'", steamId); results = SQL_Query(dbcSkills, query); if (results==INVALID_HANDLE) // { SQL_GetError(dbcSkills, error, sizeof(error)); PrintToServer("SelectDBPlayer: Failed to query (error: %s)", error); } else { if(SQL_FetchRow(results)) { CloseHandle(dbcSkills); PrintToServer("SelectDBPlayer: Finished succesfully"); return true; } } } CloseHandle(dbcSkills); } return false; }
can anyone find what i'm doing wrong?
basically the idea is: i go ingame, do !regme, then !checkme, regme tells me i'm added to the database, and checkme tells me im not in there
im guessing the problem is either with CreateDBPlayerEntry or IsPlayerInDB, but i can't seem to find/see it....
|
|