Raised This Month: $ Target: $400
 0% 

[MYSQL] Query Problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HENNESSY
Member
Join Date: Sep 2013
Location: Russian Federation, Bela
Old 07-16-2014 , 05:49   [MYSQL] Query Problem
Reply With Quote #1

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!

Last edited by YamiKaitou; 07-18-2014 at 06:24. Reason: Problem fixed!
HENNESSY is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-16-2014 , 07:52   Re: [MYSQL] Query Problem
Reply With Quote #2

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.
__________________

Last edited by Black Rose; 07-16-2014 at 07:54.
Black Rose is offline
HENNESSY
Member
Join Date: Sep 2013
Location: Russian Federation, Bela
Old 07-16-2014 , 09:16   Re: [MYSQL] Query Problem
Reply With Quote #3

Quote:
Originally Posted by Black Rose View Post
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!

Last edited by HENNESSY; 07-16-2014 at 09:20.
HENNESSY is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 07-18-2014 , 06:16   Re: [MYSQL] Query Problem
Reply With Quote #4

don't edit out your post
someone might need it later
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever 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 13:18.


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