AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ability to pass MySQL Results? (https://forums.alliedmods.net/showthread.php?t=17948)

harbu 09-12-2005 08:23

Ability to pass MySQL Results?
 
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.

BAILOPAN 09-12-2005 09:27

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.

harbu 09-12-2005 11:25

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; }

BAILOPAN 09-12-2005 11:59

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.

harbu 09-12-2005 12:01

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 09-12-2005 12:16

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; }

BAILOPAN 09-12-2005 12:34

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.


All times are GMT -4. The time now is 14:19.

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