Raised This Month: $51 Target: $400
 12% 

sourcemod sqlite problems


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrancK
Senior Member
Join Date: Jan 2009
Location: Netherlands
Old 10-21-2010 , 06:57   sourcemod sqlite problems
Reply With Quote #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(clientargs)
{
    if(
pluginEnabled)
    {
        if(
CreateDBPlayerEntry(client))
        {
            
ReplyToCommand(client"player added to database");
        }
        else
        {
            
ReplyToCommand(client"error: player not added to database");
        }
    }
}

public 
Action:Command_CheckMe(clientargs)
{
    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"trueerrorsizeof(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(querysizeof(query), "CREATE TABLE IF NOT EXISTS 'Players' ( 'steamId' VARCHAR(32) NOT NULL PRIMARY KEY, 'nickName' VARCHAR(32) NOT NULL)");
            if (!
SQL_Query(dbcSkillsquery))
            {
                
SQL_GetError(dbcSkillserrorsizeof(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"trueerrorsizeof(error));
        if (
dbcSkills == INVALID_HANDLE)
        {
            
PrintToServer("Could not connect to skillrank: %s,"error);
        } 
        else 
        {
            
Format(querysizeof(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(dbcSkillsquery))
            {
                
SQL_GetError(dbcSkillserrorsizeof(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"trueerrorsizeof(error));
        if (
dbcSkills == INVALID_HANDLE)
        {
            
PrintToServer("Could not connect to skillrank: %s,"error);
        } 
        else 
        {
            
Format(querysizeof(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(dbcSkillsquery))
            {
                
SQL_GetError(dbcSkillserrorsizeof(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"trueerrorsizeof(error));
        
decl String:query[512];
        new 
String:cname[64]; GetClientName(clientcnamesizeof(cname));
        
GetClientAuthString(clientsteamIdsizeof(steamId));
        if (
dbcSkills == INVALID_HANDLE)
        {
            
PrintToServer("Could not connect to skillrank: %s"error);
        } 
        else 
        {
            
Format(querysizeof(query), "INSERT INTO 'Players' ( 'steamId', 'nickName' ) VALUES ( '%s', '%s' )"steamIdcname);
            if (!
SQL_Query(dbcSkillsquery))
            {
                
SQL_GetError(dbcSkillserrorsizeof(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"trueerrorsizeof(error));
        new 
String:query[512];
        new 
Handle:results;
        
GetClientAuthString(clientsteamIdsizeof(steamId));
        if (
dbcSkills == INVALID_HANDLE)
        {
            
PrintToServer("Could not connect to skillrank: %s"error);
        } 
        else 
        {
            
Format(querysizeof(query), "SELECT * from 'Players' WHERE 'steamId'='%s'"steamId);
            
results SQL_Query(dbcSkillsquery);
            if (
results==INVALID_HANDLE//
            
{
                
SQL_GetError(dbcSkillserrorsizeof(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....
CrancK is offline
CrancK
Senior Member
Join Date: Jan 2009
Location: Netherlands
Old 10-23-2010 , 05:17   Re: sourcemod sqlite problems
Reply With Quote #2

*BUMP*


ok, now i've already tried using less complicated SQL statements (only TEXT and INTEGER no NOT NULLs etc), yet still it doesn't seem to work...

now one thing that might be the cause..

when i open the .sq3 file, i can find the statements that'll make the table and all, thats good, but then in the part where i "assume" the data is stored, instead of seeing steamid + nick, i see steamid+nick, + steamid

as in, the first steamid is locked in together with the nickname (which should be different columns at the least) (like : STEAM:1:0:129480CrancK)
and the second steamid is just steamid...

now since im opening that in just notepad and there are several symbols it doesnt recognize, it could just be weird formatting.... but could it also be that maybe i'm saving the data wrong?

anyone help?

(also, the sqlite site doesn't really say which types of variables can be used (or at least i can't find it on that site), but floats are possible... right?)

Last edited by CrancK; 10-23-2010 at 05:20.
CrancK is offline
FoxMulder
Senior Member
Join Date: Jan 2009
Location: Orlando, FL
Old 10-23-2010 , 07:00   Re: sourcemod sqlite problems
Reply With Quote #3

Use this to browse SQLite: http://sqlitebrowser.sourceforge.net/
__________________
FoxMulder is offline
CrancK
Senior Member
Join Date: Jan 2009
Location: Netherlands
Old 10-23-2010 , 08:37   Re: sourcemod sqlite problems
Reply With Quote #4

ok cool, i used that, and saw that at least data being saved is correct...
(so the problem is not there)

however, that still leaves me with the question why IsPlayerInDB doesn't return true...

now the 2 obvious things that could be wrong are the SELECT statement and the SQL_Fetch part, though i don't really see anything wrong with it :S
CrancK is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode