SA-MP Forums Archive
Passing array to MySQL callback - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Passing array to MySQL callback (/showthread.php?tid=534070)



Passing array to MySQL callback - Catalyst- - 27.08.2014

I've been stuck with this for a while and it's bugging me. I'm unable to figure out the correct way to pass an array to a MySQL callback after the query is complete.
This is my attempt:

Query:
pawn Код:
new array[5] = {0,1,2,3,4};
mysql_function_query(1, "SELECT * FROM `table` WHERE `id` = 1", false, "Test", "s", array);
Callback:
pawn Код:
forward Test(array[]);
public Test(array[])
{
    for(new i = 0; i != 5; i++)
        printf("array[%d] = %d", i, array[i]);
}
Output:
pawn Код:
array[0] = 0
array[1] = 0
array[2] = 0
array[3] = 0
array[4] = 0
The output will be correct if I change the array to (remove '0'):
pawn Код:
new array[5] = {1,1,2,3,4};
However, it will wrap back to 0 if I use a value higher than 255.

Hope someone can see what I'm doing wrong and help me out, thanks!

- Using BlueG's MySQL plugin (R7)


Re: Passing array to MySQL callback - Catalyst- - 29.08.2014

Bump


Re: Passing array to MySQL callback - Catalyst- - 03.09.2014

Would really appreciate any help with this.


Re: Passing array to MySQL callback - Fred1993 - 03.09.2014

Quote:

g_mysql_handle = mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_DATABASE ,MYSQL_PASSWORD);

mysql_function_query(g_mysql_handle, "SELECT * FROM `table` WHERE `id` = 1", false, "Test", "s", array);

first connect your sql and store the information in "g_mysql_handle" then use this in "mysql_function_query"
This is the corrent way to perform a query


Re: Passing array to MySQL callback - Catalyst- - 03.09.2014

Quote:
Originally Posted by Fred1993
Посмотреть сообщение
first connect your sql and store the information in "g_mysql_handle" then use this in "mysql_function_query"
This is the corrent way to perform a query
I think you may have misunderstood the problem...I didn't bother to post the irrelevant code.
I'm not having problems with performing a query or connecting to the database; I'm unaware of how I am able to pass an array from a threaded query to the function which it calls.


Re: Passing array to MySQL callback - Catalyst- - 04.09.2014

Bump


Re: Passing array to MySQL callback - Catalyst- - 06.09.2014

Quote:
Originally Posted by Catalyst-
Посмотреть сообщение
Would really appreciate any help with this.
Bump


Re: Passing array to MySQL callback - Catalyst- - 07.09.2014

Quote:
Originally Posted by ******
Посмотреть сообщение
"s" is "string", arrays are USUALLY "a" but I don't know if the plugin supports them in callbacks. However, there are several work-arounds: use inline functions or copy the data to a global arary and pass an index instead.
I've already tried 'a' and didn't work, so if there's no other alternative it looks like arrays are not supported by the plugin. I'll likely just use a global array.

Thanks for your help.