AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [MYSQL] Query Problem (https://forums.alliedmods.net/showthread.php?t=244276)

HENNESSY 07-16-2014 05:49

[MYSQL] Query Problem
 
I'm try to get some data from the database

This is the code:

Code:

#include < amxmodx >
#include < sqlx >

#define hostname        "hidden"
#define sql_user        "hidden"
#define sql_pass        "hidden"
#define sql_db        "hidden"

new Handle:g_hTuple;
new g_szError[ 512 ];

public plugin_init( )
{
g_hTuple =        SQL_MakeDbTuple( hostname, sql_user, sql_pass, sql_db );

register_clcmd( "say vipstatus", "cmd_Vipstatus" );
}

public cmd_Vipstatus( iIndex )
{
new szSteamID[ 35 ];
get_user_authid( iIndex, szSteamID, charsmax( szSteamID ) );

new iError, Handle:hSQLConnection = SQL_Connect( g_hTuple, iError, g_szError, 511 );

if( hSQLConnection == Empty_Handle )
{
set_fail_state( g_szError );
}

new Handle:hQuery = SQL_PrepareQuery( hSQLConnection, "SELECT `package_id`, `server_id` FROM `vips` WHERE `steamid` = '%s';", szSteamID );

static szServerID[ 3 ], iPackageID;

if( !SQL_Execute( hQuery ) )
{
SQL_QueryError( hQuery, g_szError, 511 );
log_amx( "Query Error: %s", g_szError );
}

else if( SQL_NumResults( hQuery ) )
{
iPackageID = SQL_ReadResult( hQuery, 0 );
SQL_ReadResult( hQuery, 1, szServerID, charsmax( szServerID ) );

client_print( iIndex, print_chat, "You are a VIP with the package ID: %i on server %s", iPackageID, szServerID );
}

SQL_FreeHandle( hQuery );
SQL_FreeHandle( hSQLConnection );
}
public plugin_end( )
{
SQL_FreeHandle( g_hTuple );
}

The connection succeed but when i write 'vipstatus' in chat it just lag the server for a second and doesn't show anything.

I run the query on the database and it returning my requested values;

What is the problem with my code?

Thanks for the Help!

Black Rose 07-16-2014 07:52

Re: [MYSQL] Query Problem
 
Put some debug messages in there to find out exactly where it fails.
What values are being returned by the natives and which statement equal to true.

HENNESSY 07-16-2014 09:16

Re: [MYSQL] Query Problem
 
Quote:

Originally Posted by Black Rose (Post 2168616)
Put some debug messages in there to find out exactly where it fails.
What values are being returned by the natives and which statement equal to true.

Ok, i changed it to ThreadQuery so it will work faster and will not interrupt the game.

And i did put some debug message and found the problem in finding the results by specific STEAM_ID.

It wrote STEAM_ID_LAN instead of my real STEAM ID, Then i realise that i run the SteamCMD Server under LAN Connection.

I fixed the problem Thank you Black Rose for the advice! I'll use that for sure in the future!

aron9forever 07-18-2014 06:16

Re: [MYSQL] Query Problem
 
don't edit out your post
someone might need it later


All times are GMT -4. The time now is 13:18.

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