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

Invalid Handle (but it's not O_o)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 02-12-2010 , 07:30   Invalid Handle (but it's not O_o)
Reply With Quote #1

Code:
L 02/12/2010 - 12:06:22: [SM] Native "SQL_FetchRow" reported: Invalid query Handle 0 (error: 4)
PHP Code:
fnCreateTables()
{
    if (!
GetConVarBool(g_pEnableSaving))
    {
        
LogMessage("Saving is disabled")

        return
    }

    
decl String:szError[64]
    
g_hConnection SQL_Connect("crp"falseszError64)

    
decl String:szMode[6]
    
SQL_ReadDriver(g_hConnectionszMode6)

    if (
StrEqual(szMode"mysql"false))
        
g_hMode Mode_MySQL
    
else
        
g_hMode Mode_SQLite

    decl String
:szQuery[128]

    
FormatEx(szQuery128"CREATE TABLE IF NOT EXISTS crp_users (SteamID VARCHAR(40), Wallet INT(12), Bank INT(12), JobName VARCHAR(40), Hunger INT(12), Access INT(12), JobRights INT(12), UNIQUE %s(SteamID))"g_hMode == Mode_MySQL "KEY " "")
    
SQL_TQuery(g_hConnectionfnGenericHandlerszQuery0DBPrio_Normal)

    
FormatEx(szQuery128"CREATE TABLE IF NOT EXISTS crp_jobs (Name VARCHAR(40), Wage INT(12), Access INT(12), UNIQUE %s(Name))"g_hMode == Mode_MySQL "KEY " "")
    
SQL_TQuery(g_hConnectionfnGenericHandlerszQuery0DBPrio_Normal)

    
FormatEx(szQuery128"CREATE TABLE IF NOT EXISTS crp_items (SteamID VARCHAR(40), Item INT(12), Amount INT(12), UNIQUE %s(SteamID))"g_hMode == Mode_MySQL "KEY " "")
    
SQL_TQuery(g_hConnectionfnGenericHandlerszQuery0DBPrio_Normal)

    
CreateTimer(GetConVarFloat(g_pSaveInterval), fnSaveDataINVALID_HANDLETIMER_REPEAT)

PHP Code:
public OnClientAuthorized(id, const String:szSteam[])
{
    
decl String:szQuery[96]
    
FormatEx(szQuery96"SELECT * FROM crp_users WHERE SteamID = \"%s\""szSteam)

    
SQL_TQuery(g_hConnectionfnLoadDataszQueryidDBPrio_Normal)

PHP Code:
public fnLoadData(Handle:hOwnerHandle:hQueryString:szError[], any:_Data)
{
    if (
hQuery == INVALID_HANDLE)
        
LogMessage("Query failed")

    else if (!
IsClientConnected(_Data))
        
LogMessage("User disconnected while query was running")

    else if (
szError[0])
        
LogMessage(szError)

    
decl String:szQuery[96]

    if (!
SQL_FetchRow(hQuery))
    {
        
LogMessage("Failed to load data for \"%N\", creating new account..."_Data)

        
decl String:szSteam[40]
        
GetClientAuthString(_DataszSteam40)

        
FormatEx(szQuery96"INSERT INTO crp_users VALUES (\"%s\", 0, 0, \"Unemployed\", 0, 0, 0)"szSteam)
        
SQL_TQuery(g_hConnectionfnGenericHandlerszQuery0DBPrio_High)

        
g_iWallet[_Data] = 0
        g_iBank
[_Data] = 0
        g_szJobName
[_Data] = "Unemployed"
        
g_iHunger[_Data] = 0
        g_iAccess
[_Data] = 0
        g_iJobRights
[_Data] = 0

        SQL_TQuery
(g_hConnectionfnLoadWage"SELECT * FROM crp_jobs WHERE JobName = \"Unemployed\""_DataDBPrio_High)
    }
    else
    {
        
g_iWallet[_Data] = SQL_FetchInt(hQuery1)
        
g_iBank[_Data] = SQL_FetchInt(hQuery2)
        
SQL_FetchString(hQuery3g_szJobName[_Data], 40)
        
g_iHunger[_Data] = SQL_FetchInt(hQuery4)
        
g_iAccess[_Data] = SQL_FetchInt(hQuery5)
        
g_iJobRights[_Data] = SQL_FetchInt(hQuery6)

        
FormatEx(szQuery96"SELECT * FROM crp_jobs WHERE JobName = \"%s\""g_szJobName[_Data])
        
SQL_TQuery(g_hConnectionfnLoadWageszQuery_DataDBPrio_High)
    }

Spunky is offline
Send a message via AIM to Spunky
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 02-12-2010 , 18:15   Re: Invalid Handle (but it's not O_o)
Reply With Quote #2

When hQuery is invalid you shouldn't continue the function, but return;
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 02-12-2010 , 19:10   Re: Invalid Handle (but it's not O_o)
Reply With Quote #3

It's not invalid though. If it were invalid, it would have logged it like you see in the code. There was no log entry stating the query had failed. So it's not invalid.

Edit: I figured it out. It was a problem with a timer.

Last edited by Spunky; 02-12-2010 at 19:13.
Spunky is offline
Send a message via AIM to Spunky
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 14:48.


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