Raised This Month: $ Target: $400
 0% 

Passing SQL Result handles


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 09-14-2005 , 17:00   Passing SQL Result handles
#1

Not working even yet for me. So I decided to make the most simplest possibe plugin to demonstrate that it's not working at all.

Native function caller
Code:
// Plugin To call native #include <amxmodx> #include <dbi> #include <hrp_save> new Result:g_result; public plugin_init() {     register_plugin( "MySQL Pass Tes", "1.0", "Harbu" );         register_clcmd( "say /value", "get_value" ); } public get_value( id ) {     g_result = hrp_query( "SELECT example_value FROM test" );         new val = dbi_result( g_result, "example_value" );         dbi_free_result( g_result )         client_print( id, print_chat, "VALUE %i", val );         return PLUGIN_HANDLED }

Native function owner
Code:
// Plugin hold native #include <amxmodx> #include <dbi> #include <hrp_save> new Sql:g_db; public plugin_natives() {     register_native( "hrp_query", "h_query", 1);         register_library( "HRPSave" ); } public plugin_init() {     register_plugin( "MySQL Pass Receive", VERSION, "Harbu" );         register_cvar( "hrp_sql_host", "127.0.0.1" , FCVAR_PROTECTED);     register_cvar( "hrp_sql_user", "root", FCVAR_PROTECTED );     register_cvar( "hrp_sql_pass", "", FCVAR_PROTECTED );     register_cvar( "hrp_sql_db", "hrp", FCVAR_PROTECTED );     mysql_init(); } // Estabishing connection to MySQL Database public mysql_init() {     new host[64], user[32], pass[32], db[32], error[64];         get_cvar_string( "hrp_sql_host", host, 63 );     get_cvar_string( "hrp_sql_user", user, 31 );     get_cvar_string( "hrp_sql_pass", pass, 31 );     get_cvar_string( "hrp_sql_db", db, 31 );         g_db = dbi_connect( host, user, pass, db, error, 63 );     if( g_db <= SQL_FAILED )     {         server_print( "[Base] Couldn't establish a connection to MySQL database." );         server_print( "[Base] Error: %s.", error );                 return PLUGIN_HANDLED     }         server_print( "[Base] Connection to MySQL established." );     return PLUGIN_HANDLED } // MySQL Query ( Use hrp_select for selecting data from MySQL ) public Result:h_query( query[]) {     param_convert(1);     new Result:result = dbi_query( g_db, query );         return result; }

The include file:
Code:
// Include file #if defined _hrp_save_included   #endinput #endif #define _hrp_save_included #pragma library HRPSave native Result:hrp_query( const query[] )

Is it not working or am I doing something dumbass?

Errors im receiving:
Code:
Harbu 'Vladimir' Kerensky: /test
L 09/14/2005 - 22:56:27: [AMXX] [MYSQL] No more results in handle 0
L 09/14/2005 - 22:56:27: [AMXX] Displaying call trace (plugin "ts\addons\amxmodx\plugins\caller.amxx")
L 09/14/2005 - 22:56:27: [AMXX]    [0] caller.sma::get_value (line 20)
__________________
harbu is offline
Send a message via MSN to harbu
BAILOPAN
Join Date: Jan 2004
Old 09-14-2005 , 17:10  
#2

Did you bother to debug this?

Code:
// MySQL Query ( Use hrp_select for selecting data from MySQL ) public Result:h_query( query[]) {     param_convert(1);     new Result:result = dbi_query( g_db, query );         return result; }

Print result there... see if it's zero or not? I posted this in your thread in scripting and you never gave a reply.
__________________
egg
BAILOPAN is offline
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 09-14-2005 , 17:26  
#3

Well I turned into that to something like this:
Code:
// MySQL Query ( Use hrp_select for selecting data from MySQL ) public Result:h_query( query[]) {     param_convert(1);     new Result:result = dbi_query( g_db, query );     if( result == RESULT_OK )     {         new a;         a = dbi_result( result, "example_value" );                 server_print( "The value is %i", a );     }         server_print( "Result wasn't ok" );         return result; }

I't gives me the "Result wasn't ok" but that query that I do, does work on MySQL clients.
__________________
harbu is offline
Send a message via MSN to harbu
BAILOPAN
Join Date: Jan 2004
Old 09-14-2005 , 17:39  
#4

You're comparing the result wrong, read the docs. I have to say this way too many times.

== RESULT_FAILED - error
== RESULT_NONE - no result
>= RESULT_OK - result handle with results

print the actual result handle
__________________
egg
BAILOPAN is offline
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 09-15-2005 , 04:49  
#5

Did I get it now right?
Code:
public Result:h_query( query[]) {     param_convert(1);     new Result:result = dbi_query( g_db, query );         server_print( "RESULT HANDLE: %d", result );     if( result >= RESULT_OK )     {         new a;         a = dbi_result( result, "example_value" );                 server_print( "The value is %i", a );     }         server_print( "Result wasn't ok.");         return result; }


Errors now:
Code:
RESULT HANDLE: 1
L 09/15/2005 - 10:46:12: [AMXX] [MYSQL] No more results in handle 0
L 09/15/2005 - 10:46:12: [AMXX] Displaying call trace (plugin "ts\addons\amxmodx\plugins\called.amxx")
L 09/15/2005 - 10:46:12: [AMXX]    [0] called.sma::h_query (line 62)
L 09/15/2005 - 10:46:12: [AMXX] Run time error 10 (native)
L 09/15/2005 - 10:46:12: [AMXX] Displaying call trace (plugin "ts\addons\amxmodx\plugins\called.amxx")
L 09/15/2005 - 10:46:12: [AMXX] [MYSQL] Invalid result handle 0
L 09/15/2005 - 10:46:12: [AMXX] Displaying call trace (plugin "ts\addons\amxmodx\plugins\caller.amxx")
L 09/15/2005 - 10:46:12: [AMXX]    [0] caller.sma::get_value (line 20)
__________________
harbu is offline
Send a message via MSN to harbu
BAILOPAN
Join Date: Jan 2004
Old 09-15-2005 , 10:32  
#6

Sorry, you're also not calling dbi_nextrow(), which begins going through the results. You must call it at least once.
__________________
egg
BAILOPAN is offline
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 09-15-2005 , 12:13  
#7

Ah now yes it's working now. Thanks a lot. ... and sorry for reporting it as a bug.
__________________
harbu is offline
Send a message via MSN to harbu
Closed Thread



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:00.


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