Raised This Month: $ Target: $400
 0% 

Ability to pass MySQL Results?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 09-12-2005 , 08:23   Ability to pass MySQL Results?
Reply With Quote #1

Ok, so I am trying to send a result handle from another plugin to another by a native.

Base:
Code:
// MySQL Query ( Use hrp_select for selecting data from MySQL ) public h_query( query[], Result:result) {     param_convert( 1 );     param_convert( 2 );     result = dbi_query( g_db, query )         new ret;     if( result == RESULT_FAILED ) ret = -1;     if( result == RESULT_NONE )ret = 0;     if( result == RESULT_OK) ret = 1;         return ret; }

Include file:
Code:
native hrp_query( query[], Result:result )

Plugin using the native:
Code:
format( g_query, 255, "SELECT wallet, bank FROM accounts WHERE steamid='%s'", authid );         if( hrp_query( g_query, g_result) == 1 )     {         g_wallet[id] = dbi_result( g_result, "wallet" );         g_bank[id] = dbi_result( g_result, "bank" );                 dbi_free_result( g_result );                 return PLUGIN_CONTINUE     }

I haven't got it to work.
So, is it possible to pass Result handles or not? If it is, what have I done wrong?

Thanks, for your time.
__________________
harbu is offline
Send a message via MSN to harbu
BAILOPAN
Join Date: Jan 2004
Old 09-12-2005 , 09:27  
Reply With Quote #2

yes, you can.

however, you're using param_convert on a byvalue parameter, this will return garbage.

I recommend using the other form if you can as it's harder to run into that type of mistake.
__________________
egg
BAILOPAN is offline
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 09-12-2005 , 11:25  
Reply With Quote #3

You mean using the default mode for register_native(). Okay I did it, but it's still not working, actually it's not even exceuting the query anymore as it did before.

Code:
public plugin_natives() {     register_native( "hrp_query", "h_query");         register_library( "HRPSave" ); } public h_query() {     new query[256], Result:result     get_array( 1, query, 255 );     result = get_param_byref( 2 );         result = dbi_query( g_db, query )         new ret;     if( result == RESULT_FAILED ) ret = -1;     if( result == RESULT_NONE )ret = 0;     if( result == RESULT_OK) ret = 1;         set_param_byref( 2, result );         return ret; }
__________________
harbu is offline
Send a message via MSN to harbu
BAILOPAN
Join Date: Jan 2004
Old 09-12-2005 , 11:59  
Reply With Quote #4

Show me how you're using it for the native. Also! Note unfortunately there was a bug in get_array in 1.55 that makes it not work. This has been fixed in the upcoming 1.60.

So, I guess you should use param_convert method for now after all ;] just make sure you don't use it on non-byref parameters.
__________________
egg
BAILOPAN is offline
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 09-12-2005 , 12:01  
Reply With Quote #5

Code:
    new authid[32];     get_user_authid( id, authid, 31 );         format( g_query, 255, "SELECT wallet, bank FROM accounts WHERE steamid='%s'", authid );         if( hrp_query( g_query, g_result) == 1 )     {         g_wallet[id] = dbi_result( g_result, "wallet" );         g_bank[id] = dbi_result( g_result, "bank" );                 dbi_free_result( g_result );                 return PLUGIN_CONTINUE     }
__________________
harbu is offline
Send a message via MSN to harbu
harbu
Senior Member
Join Date: Aug 2004
Location: Finland
Old 09-12-2005 , 12:16  
Reply With Quote #6

Oh my god even this isn't working...

Code:
public plugin_natives() {     register_native( "hrp_query", "h_query", 1);         register_library( "HRPSave" ); } // MySQL Query ( Use hrp_select for selecting data from MySQL ) public h_query( query[], Result:result) {     param_convert(1);     result = dbi_query( g_db, query )           new ret;     if( result == RESULT_FAILED ) ret = -1;     if( result == RESULT_NONE )ret = 0;     if( result == RESULT_OK) ret = 1;           return ret; }
__________________
harbu is offline
Send a message via MSN to harbu
BAILOPAN
Join Date: Jan 2004
Old 09-12-2005 , 12:34  
Reply With Quote #7

This should work:

Code:
native Result:hrb_query(const query[]); //.... public plugin_natives() {    register_native("hrb_query", "hrb_query") } public Result:hrb_query(query[]) {    param_convert(1)    new Result:res = dbi_query(g_Sql, query)    return res }

If none of this is working for you, I suggest outputting values each step of the way and telling me what they are, and what the expected values are. That way we can debug it.
__________________
egg
BAILOPAN is offline
Reply


Thread Tools
Display Modes

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 14:19.


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