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

Sqlx Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rainin
Member
Join Date: Apr 2011
Location: Estonia
Old 09-22-2011 , 13:30   Sqlx Help
Reply With Quote #1

Hi!

I Need help with sqlx. If someone could fix this, i would be quite thankful.

Error:
PHP Code:
L 09/20/2011 17:30:07: [MySQLInvalid handle0
L 09
/20/2011 17:30:07: [AMXXRun time error 10 (plugin "dr.amxx") (native "SQL_FreeHandle") - debug not enabled!
L 09/20/2011 17:30:07: [AMXXTo enable debug modeadd "debug" after the plugin name in plugins.ini (without quotes). 
Code:
PHP Code:
public MySql_Init()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db);
   
    
// ok, we're ready to connect
    
new ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error));
    if(
SqlConnection == Empty_Handle)
    {
        
// stop the plugin with an error message
        
set_fail_state(g_Error);
      }
       
    new 
Handle:Queries;
    
// we must now prepare some random queries
    
Queries SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS deathrun (nick varchar(255),ip varchar(255),steamid varchar(32),elud int(11))");

    if(!
SQL_Execute(Queries))
    {
        
// if there were any problems the plugin will set itself to bad load.
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error));
        
set_fail_state(g_Error);
       
    }
    
    
// Free the querie
    
SQL_FreeHandle(Queries);
   
    
// you free everything with SQL_FreeHandle
    
SQL_FreeHandle(SqlConnection) ; 
}  

public 
plugin_end()
{
    
// free the tuple - note that this does not close the connection,
    // since it wasn't connected in the first place
    
SQL_FreeHandle(g_SqlTuple);
}

public 
Load_MySql(id)
{
    new 
szPlayerName[32];
    
get_user_name(idszPlayerNamecharsmax(szPlayerName));
    new 
szSteamId[32];
    
get_user_authid(idszSteamIdcharsmax(szSteamId));
    new 
szIp[32];
    
get_user_ip(idszIpcharsmax(szIp));
     
    new 
Data[1
    
Data[0] = id 
     
    
//we will now select from the table `tutorial` where the steamid match 
    
format(szTemp,charsmax(szTemp),"SELECT * FROM `tutorial` WHERE (`tutorial`.`steamid` = '%s')"szSteamId
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1
}  
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"ErrcodeError);
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError);
    }

    new 
id;
    
id Data[0];
    
    
    if(
SQL_NumResults(Query) < 1
    {
         
//.if there are no results found
        
new szIp[32];
        
get_user_ip(idszIpcharsmax(szIp));
        new 
szPlayerName[32];
        
get_user_name(idszPlayerNamecharsmax(szPlayerName));
        new 
szSteamId[32];
        
get_user_authid(idszSteamIdcharsmax(szSteamId)); // get user's steamid
        
        //  if its still pending we can't do anything with it
        
if (equal(szSteamId,"ID_PENDING"))
        return 
PLUGIN_HANDLED;
            
        new 
szTemp[512];
        
        
// now we will insturt the values into our table.
        
format(szTemp,charsmax(szTemp),"INSERT INTO `deathrun` (`nick` , `ip`, `steamid`, `elud`)VALUES ('%s','%s','%s','0');",szIp,szPlayerName,szSteamId);
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
    } 
    else 
    {
        
// if there are results found
        
g_Lifes[id]        = SQL_ReadResult(Query1);
    }
    
    return 
PLUGIN_HANDLED;
}  

public 
Save_MySql(id)
{
        new 
iPlayers32 ], iNumiPlayer;
        
iPlayer iPlayersid ];
        
get_playersiPlayersiNum"c" );
        new 
szIp[32];
        
get_user_ip(idszIpcharsmax(szIp));
        new 
szPlayerName[32];
        
get_user_name(idszPlayerNamecharsmax(szPlayerName));
        new 
szSteamId[32],  szTemp[512];
        
get_user_authid(idszSteamIdcharsmax(szSteamId)); 
        
// get user's steamid
    
        // Here we will update the user hes information in the database where the steamid matches.
        
format(szTemp,charsmax(szTemp),"UPDATE `deathrun` set `elud`= `elud` + '%s' WHERE `deathrun`.`steamid` = %s OR `deathrun`.`nick` = %s OR  `deathrun`.`ip` = %s ;",g_LifesiPlayer ],szSteamId,szPlayerName,szIp);
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
}  

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


Last edited by rainin; 09-23-2011 at 08:19.
rainin is offline
Send a message via MSN to rainin
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-22-2011 , 13:33   Re: Sqlx Help
Reply With Quote #2

OMG, mayby you add debug in your dr.amxx in your plugins.ini, mayby then i can help?
.Dare Devil. is offline
rainin
Member
Join Date: Apr 2011
Location: Estonia
Old 09-22-2011 , 13:34   Re: Sqlx Help
Reply With Quote #3

As you see there is problem with sqlx connect. So i dont think that debug helps.
rainin is offline
Send a message via MSN to rainin
modernwarfare
Senior Member
Join Date: Aug 2011
Location: sweden
Old 09-22-2011 , 15:21   Re: Sqlx Help
Reply With Quote #4

Quote:
Originally Posted by rainin View Post
As you see there is problem with sqlx connect. So i dont think that debug helps.

try to put it debug and try then type if there is anyother errors
__________________
Im supporting/coding XP Mod Plugin
Free Palestine
R.I.P. The 2967 American people that lost their lives 9/11 and R.I.P.
The 48,644 Afghan and 1,690,903 Iraqi people that paid the ultimate price for a crime they did not commit.



modernwarfare is offline
Send a message via MSN to modernwarfare Send a message via Skype™ to modernwarfare
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 09-22-2011 , 18:14   Re: Sqlx Help
Reply With Quote #5

Quote:
Originally Posted by rainin View Post
As you see there is problem with sqlx connect. So i dont think that debug helps.
With debug enabled you get more details in error logs (including line number in code!). When you edit plugin ALWAYS enable debug!

It's not a problem with sqlx connect, but SQL_FreeHandle. There are several of them used in your code. With debug enabled, you would know which one is causing the problem.

Looking at the code I can see some mistakes.
1) You tried to change SqlConnection name to MySQL_Connection, but you didn't change it everywhere.
2) In this piece of code you use invalid g_SqlTuple. You pass SQL_MakeStdTuple() directly to SQL_Connect and never assign anything to g_SqlTuple.
3) Don't use SQL_FreeHandle(Query) in IgnoreHandle or any threaded query handlers.
__________________
Impossible is Nothing
Sylwester is offline
rainin
Member
Join Date: Apr 2011
Location: Estonia
Old 09-23-2011 , 08:10   Re: Sqlx Help
Reply With Quote #6

PHP Code:
L 09/23/2011 16:07:41: [MySQLInvalid info tuple handle0
L 09
/23/2011 16:07:41: [AMXXDisplaying debug trace (plugin "dr.amxx")
L 09/23/2011 16:07:41: [AMXXRun time error 10native error (native "SQL_ThreadQuery")
L 09/23/2011 16:07:41: [AMXX]    [0dr.sma::Load_MySql (line 267)
L 09/23/2011 16:07:41: [AMXX]    [1dr.sma::client_putinserver (line 717
267:
PHP Code:
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"ErrcodeError);
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError);
    }

    new 
id;
    
id Data[0];
    
    
    if(
SQL_NumResults(Query) < 1
    {
         
//.if there are no results found
        
new szIp[32];
        
get_user_ip(idszIpcharsmax(szIp));
        new 
szPlayerName[32];
        
get_user_name(idszPlayerNamecharsmax(szPlayerName));
        new 
szSteamId[32];
        
get_user_authid(idszSteamIdcharsmax(szSteamId)); // get user's steamid
        
        //  if its still pending we can't do anything with it
        
if (equal(szSteamId,"ID_PENDING"))
        return 
PLUGIN_HANDLED;
            
        new 
szTemp[512];
        
        
// now we will insturt the values into our table.
        
format(szTemp,charsmax(szTemp),"INSERT INTO `deathrun` (`nick` , `ip`, `steamid`, `elud`)VALUES ('%s','%s','%s','0');",szIp,szPlayerName,szSteamId);
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
    } 
    else 
    {
        
// if there are results found
        
g_Lifes[id]        = SQL_ReadResult(Query1);
    }
    
    return 
PLUGIN_HANDLED;

717:
PHP Code:
public client_putinserverid )
{
    
Load_MySql(id);
    
g_bConnectedid ] = true;


Last edited by rainin; 09-23-2011 at 08:18.
rainin is offline
Send a message via MSN to rainin
WAW555
Junior Member
Join Date: Dec 2008
Old 09-29-2011 , 10:09   Re: Sqlx Help
Reply With Quote #7

Please help with query

g_i_PlayerID[id] = 116

PHP Code:
public Get_User_Group(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    return 
set_fail_state("Error connect MySql")
    else if(
FailState == TQUERY_QUERY_FAILED)
    return 
set_fail_state("Error Query.")
    
    if(
Errcode)
    return 
log_amx("Error MySql: %s",Error)
    
    new 
id
    id 
Data[0]
    
    if(
SQL_MoreResults(Query))
    {
        new  
s_Request[512]
        
g_i_PlayerGroup[id] = SQL_ReadResult(Query,0)
        
log_to_file(g_szLogFile"13. Get Player Group g_i_PlayerGroup = %d"g_i_PlayerGroup[id])
        if(
g_i_PlayerGroup[id] == 2)
        {
            
g_s_PlayerGroupName[id] = "User"
        
}
        
format(s_Request,charsmax(s_Request), "SELECT parent FROM w4die_community_msg WHERE from = '%d'",g_i_PlayerID[id])
        
SQL_ThreadQuery(g_SqlTuple,"Get_User_Group_Name",s_RequestData1)
        
SQL_NextRow(Query)
    }
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_CONTINUE
}

public 
Get_User_Group_Name(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    return 
set_fail_state("Error connect MySql")
    else if(
FailState == TQUERY_QUERY_FAILED)
    return 
set_fail_state("Error Query.")
    
    if(
Errcode)
    return 
log_amx("Error MySql: %s",Error)
    
    new 
id
    id 
Data[0]
    
    if(
SQL_MoreResults(Query))
    {
        
g_i_Player_Message[id] = SQL_ReadResult(Query,0)
        
log_to_file(g_szLogFile"14. Get user message g_i_Player_Message = %d"g_i_Player_Message[id])
        
        
SQL_NextRow(Query)
    }
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_CONTINUE

error_log

Code:
L 09/29/2011 - 17:56:19: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20110929.log")
L 09/29/2011 - 17:56:19: [AMXX] Plugin ("sql_test.amxx") is setting itself as failed.
L 09/29/2011 - 17:56:19: [AMXX] Plugin says: Ошибка запроса.
L 09/29/2011 - 17:56:19: [AMXX] Displaying debug trace (plugin "sql_test.amxx")
L 09/29/2011 - 17:56:19: [AMXX] Run time error 1: forced exit 
L 09/29/2011 - 17:56:19: [AMXX]    [0] sql_test.sma::Get_User_Group_Name (line 335)
mysql_log

Code:
L 09/29/2011 - 17:56:19: 1. Autorised player SteamID STEAM_0:0:19404857
L 09/29/2011 - 17:56:19: 3. Get SteamID STEAM_0:0:19404857
L 09/29/2011 - 17:56:19: 4. Get player in mysql SteamID STEAM_0:0:19404857
L 09/29/2011 - 17:56:19: 16. Get player Data
L 09/29/2011 - 17:56:19: 13. Get Player Group g_i_PlayerGroup = 2
MySql Data

from parent
116 2
118 2
116 2
WAW555 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 02:58.


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