Raised This Month: $ Target: $400
 0% 

Sql Queries


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zeus
Senior Member
Join Date: Jul 2008
Old 11-30-2010 , 15:11   Sql Queries
Reply With Quote #1

I have a big small problem...
I have this code
Code:
        new szTemp[1024];
	format(szTemp,charsmax(szTemp),
	"INSERT INTO `%s` 
	(`authid`,`name`,`tkills`,`theadshots`,`deaths`)VALUES \
	('%s','%s','0','0','0') \
	(`damage`,`points`,`c4p`,`c4d`)VALUES \
	('0','0','0','0') \
	(`m4a1hs`,`ak47hs`,`awphs`,`famashs`,`galilhs`)VALUES \
	('0','0','0','0','0') \
	(`knifehs`,`deaglehs`,`usphs`,`glockhs`)VALUES \
	('0','0','0',0') \
	(`hekills`,`m4a1kills`,`ak47kills`,`awpkills`,`famaskills`)VALUES \
	('0','0','0','0','0') \
	(`galilkills`,`knifekills`,`deaglekills`,`uspkills`,`glockkills`)VALUES \
	('0','0','0','0','0') \
	(`status`)VALUES('%s');",
	gTn,gTn,szSteamId,szName,gTn,gTn,gTn,gTn,gTn,gTn,status);
How to make it work?, i'm rubbish at sql
The error I get is :
Code:
error 037 : invalid string ( possibly non-terminated string)

Last edited by zeus; 11-30-2010 at 15:16.
zeus is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 11-30-2010 , 15:19   Re: Sql Queries
Reply With Quote #2

"INSERT INTO `%s`

You forget \
__________________
xPaw is offline
zeus
Senior Member
Join Date: Jul 2008
Old 11-30-2010 , 16:33   Re: Sql Queries
Reply With Quote #3

That was solverd , thx
But now I have another problem
Code:
Load Query failed. [1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\' at line 1
zeus is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-30-2010 , 16:41   Re: Sql Queries
Reply With Quote #4

Code:
        new szTemp[1024];
	format(szTemp,charsmax(szTemp),
	"INSERT INTO `%s` \
	(`authid`,`name`,`tkills`,`theadshots`,`deaths \
	`damage`,`points`,`c4p`,`c4d` \
	`m4a1hs`,`ak47hs`,`awphs`,`famashs`,`galilhs` \
	`knifehs`,`deaglehs`,`usphs`,`glockhs` \
	`hekills`,`m4a1kills`,`ak47kills`,`awpkills`,`famaskills` \
	`galilkills`,`knifekills`,`deaglekills`,`uspkills`,`glockkills` \
	`status`) \
        VALUES \
	('%s','%s','0','0','0' \
	'0','0','0','0' \
	'0','0','0','0','0' \
	'0','0','0',0' \
	'0','0','0','0','0' \
	'0','0','0','0','0' \
        '%s');",
	gTn,szSteamId,szName,status);
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 11-30-2010 at 17:42.
Exolent[jNr] is offline
zeus
Senior Member
Join Date: Jul 2008
Old 11-30-2010 , 17:32   Re: Sql Queries
Reply With Quote #5

I get these errors
Code:
L 12/01/2010 - 00:35:29: [MySQL] Invalid info tuple handle: 1
L 12/01/2010 - 00:35:29: [AMXX] Displaying debug trace (plugin "xpmod_tbdm_ham2.amxx")
L 12/01/2010 - 00:35:29: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")
L 12/01/2010 - 00:35:29: [AMXX]    [0] xpmod_tbdm_ham2.sma::Load_MySql (line 150)
L 12/01/2010 - 00:35:29: [AMXX]    [1] xpmod_tbdm_ham2.sma::client_putinserver (line 267)
L 12/01/2010 - 00:36:48: [MySQL] Invalid info tuple handle: 1
L 12/01/2010 - 00:36:48: [AMXX] Displaying debug trace (plugin "xpmod_tbdm_ham2.amxx")
L 12/01/2010 - 00:36:48: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")
L 12/01/2010 - 00:36:48: [AMXX]    [0] xpmod_tbdm_ham2.sma::Save_MySql (line 255)
L 12/01/2010 - 00:36:48: [AMXX]    [1] xpmod_tbdm_ham2.sma::client_disconnect (line 272)
This is the code
Code:
public Load_MySql(id)
{
    new szSteamId[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
    
    new Data[1]
    Data[0] = id
    
    format(szTemp,charsmax(szTemp),
    "SELECT * FROM `%s` \ 
    WHERE (`%s`.`authid` = '%s')",
    gTn,gTn,szSteamId);
    SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
    
    SQL_FreeHandle(g_SqlConnection)
}

public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED)
    {
        log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
    }
    else if(FailState == TQUERY_QUERY_FAILED)
    {
        log_amx("Load Query failed. [%d] %s", Errcode, Error)
    }

    new id
    id = Data[0]
    
    if(SQL_NumResults(Query) < 1) 
    {
        //.if there are no results found
        
        new szSteamId[32]
        get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
	new szName[32]
        get_user_name(id, szName, charsmax(szName)) // get user's name
        
        //  if its still pending we can't do anything with it
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED
            
	new status[10]
	if(is_user_connected(id)) 
	{
		status="Online"
	}
	else 
	{
		status="Offline"
	}
        new szTemp[1024];
	format(szTemp,charsmax(szTemp),
	"INSERT INTO `%s` \
	(`authid`,`name`,`tkills`,`theadshots`,`deaths \
	`damage`,`points`,`c4p`,`c4d` \
	`m4a1hs`,`ak47hs`,`awphs`,`famashs`,`galilhs` \
	`knifehs`,`deaglehs`,`usphs`,`glockhs` \
	`hekills`,`m4a1kills`,`ak47kills`,`awpkills`,`famaskills` \
	`galilkills`,`knifekills`,`deaglekills`,`uspkills`,`glockkills` \
	`status`) \
        VALUES \
	('%s','%s','0','0','0' \
	'0','0','0','0' \
	'0','0','0','0','0' \
	'0','0','0',0' \
	'0','0','0','0','0' \
	'0','0','0','0','0' \
        '%s');",
	gTn,gTn,szSteamId,szName,gTn,gTn,gTn,gTn,gTn,gTn,status);
    } 
    else 
    {
        // if there are results found
        g_iPoints[id]         = SQL_ReadResult(Query, 1)
    }
    
    return PLUGIN_HANDLED
}

public Save_MySql(id)
{
	new szSteamId[32],szTemp[1024]
	get_user_authid(id, szSteamId, charsmax(szSteamId))

	new status[10]
	if(is_user_connected(id)) 
	{
		status="Online"
	}
	else 
	{
		status="Offline"
	}

	new szName[32]
	get_user_name(id, szName, charsmax(szName))

	format(szTemp,charsmax(szTemp),
	"UPDATE `%s` SET \
	(`name`='%s',`tkills`='%d',`theadshots`='%d',`deaths`='%d',`damage`='%d' \
        `c4p ='%d',`c4d ='%d' \
	`m4a1hs`='%d',`ak47hs`='%d',`awphs`='%d',`famashs`='%d',`galilhs`='%d' \
	`knifehs`='%d',`deaglehs`='%d',`usphs`='%d',`glockhs`='%d' \
	`hekills`='%d',`m4a1kills`='%d',`ak47kills`='%d',`awpkills`='%d' \
	`galilkills`='%d',`knifekills`='%d',`deaglekills`='%d',`uspkills`='%d' \
	`glockkills`='%d',`famaskills`='%d',`status`='%s',`points`='%i') \
	WHERE (`%s`.`authid`='%s')",
	gTn,szName,g_Kills[id],g_TotalHs[id],g_Deaths[id],g_Damage[id],
	g_BombsPlanted[id],g_BombsDefused[id],g_M4a1Hs[id],g_Ak47Hs[id],g_AwpHs[id],
	g_FamasHs[id],g_GalilHs[id],g_KnifeHs[id],g_DeagleHs[id],g_UspHs[id],
	g_GlockHs[id],g_HeKills[id],g_M4a1Kills[id],g_Ak47Kills[id],g_AwpKills[id],
	g_GalilKills[id],g_KnifeKills[id],g_DeagleKills[id],g_UspKills[id],g_GlockKills[id],
	g_FamasKills[id],status,g_iPoints[id],gTn,szSteamId)

	SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    SQL_FreeHandle(Query)
    
    return PLUGIN_HANDLED
}

Last edited by zeus; 11-30-2010 at 17:45. Reason: update...
zeus is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-30-2010 , 17:43   Re: Sql Queries
Reply With Quote #6

I edited my post above.
You had too many formatting variables, so I removed to what it should be.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
zeus
Senior Member
Join Date: Jul 2008
Old 11-30-2010 , 18:05   Re: Sql Queries
Reply With Quote #7

Code:
L 12/01/2010 - 01:03:05: [MySQL] Invalid handle: 2
L 12/01/2010 - 01:03:05: [AMXX] Displaying debug trace (plugin "xpmod_tbdm_ham2.amxx")
L 12/01/2010 - 01:03:05: [AMXX] Run time error 10: native error (native "SQL_FreeHandle")
L 12/01/2010 - 01:03:05: [AMXX]    [0] xpmod_tbdm_ham2.sma::Load_MySql (line 152)
L 12/01/2010 - 01:03:05: [AMXX]    [1] xpmod_tbdm_ham2.sma::client_putinserver (line 267)
At line 152 I have this
Code:
SQL_FreeHandle(g_SqlConnection)
And at line 267 I have this
Code:
Load_MySql(id)
zeus is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 11-30-2010 , 18:20   Re: Sql Queries
Reply With Quote #8

Show here the lines on that g_SqlConnection is used.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
zeus
Senior Member
Join Date: Jul 2008
Old 11-30-2010 , 18:26   Re: Sql Queries
Reply With Quote #9

Code:
new Handle:g_SqlConnection
public MySql_Init()
{
    g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
    new ErrorCode
    g_SqlConnection=SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(g_SqlConnection == Empty_Handle)
        set_fail_state(g_Error)
    SQL_FreeHandle(g_SqlConnection)
}

public Load_MySql(id)
{
    new szSteamId[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
    
    new Data[1]
    Data[0] = id
    
    format(szTemp,charsmax(szTemp),
    "SELECT * FROM `%s` \ 
    WHERE (`%s`.`authid` = '%s')",
    gTn,gTn,szSteamId);
    SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
    
    SQL_FreeHandle(g_SqlConnection)
}
zeus is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 11-30-2010 , 18:29   Re: Sql Queries
Reply With Quote #10

The SQL_FreeHandle usage on Load_MySql function is totally useless. Why did you put that line there, if no connection stablished?
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS 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 11:20.


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