SA-MP Forums Archive
Load Settings from db - MYSQL R34 - 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: Load Settings from db - MYSQL R34 (/showthread.php?tid=484935)



Load Settings from db - MYSQL R34 - Ballu Miaa - 02.01.2014

Dear Members,

I recently updated to BlueG's MYSQL Plugin R34. I somehow managed to make a player registration system successfully with the use of all the new cache functions but am still not sure as i wanted to load settings data of the server from 'settings' table. It will have only 1 row of data to load from. I coded it all and nothing loaded actually. I think i am doing something wrong. I thought maybe i should take some help. Therefore am posting the codes here.

Structure of the table.
pawn Код:
mysql_function_query(g_Database, "CREATE TABLE IF NOT EXISTS `settings` ( \
        `id` int(5) NOT NULL, \
        `servername` varchar(24) NOT NULL, \
        `defaultX` float NOT NULL, \
        `defaultY` float NOT NULL, \
        `defaultZ` float NOT NULL, \
        `defaultA` float NOT NULL, \
        `interior` int(5) NOT NULL, \
        `vw` int(20) NOT NULL, \
        `skin` int(5) NOT NULL, \
        `cash` int(5) NOT NULL, \
        `bank` int(5) NOT NULL, \
        PRIMARY KEY (`id`) \
    )"
, false, "EmptyQuery", "");
This code creates the table successfully if it doesn't exists.

Loading data from settings table.

pawn Код:
forward LoadSettings();
public LoadSettings()
{
    new query[158];
    format(query, sizeof(query), "SELECT * FROM `settings` WHERE `id` = 0");

    mysql_function_query(g_Database, query, true, "SendQuery", "");

    cache_get_row(0, 1, g_ServerInfo[sServername], g_Database, 170);
    g_ServerInfo[sPos][0] = cache_get_row_float(0, 2, g_Database);
    g_ServerInfo[sPos][1] = cache_get_row_float(0, 3, g_Database);
    g_ServerInfo[sPos][2] = cache_get_row_float(0, 4, g_Database);
    g_ServerInfo[sPos][3] = cache_get_row_float(0, 5, g_Database);
    g_ServerInfo[sInterior] = cache_get_row_int(0, 6, g_Database);
    g_ServerInfo[sVirtualWorld] = cache_get_row_int(0, 7, g_Database);
    g_ServerInfo[sSkin] = cache_get_row_int(0, 8, g_Database);
    g_ServerInfo[sCash] = cache_get_row_int(0, 9, g_Database);
    g_ServerInfo[sBank] = cache_get_row_int(0, 10, g_Database);
       
    printf("<!> %s,%f,%f,%f,%f,%d,%d,%d,%d,%d"
    ,g_ServerInfo[sServername]
    ,g_ServerInfo[sPos][0]
    ,g_ServerInfo[sPos][1]
    ,g_ServerInfo[sPos][2]
    ,g_ServerInfo[sPos][3]
    ,g_ServerInfo[sInterior]
    ,g_ServerInfo[sVirtualWorld]
    ,g_ServerInfo[sSkin]
    ,g_ServerInfo[sCash]
    ,g_ServerInfo[sBank]);
    return 1;
}
Now when this code executes, it does not write any value in the printf other then zero's and nulls.

I am sure that there is something am doing wrong. I am trying to load the data WHERE id=0. Hope someone call tell me what is wrong which am doing.

Regards,
Ballu Miaa



Re: Load Settings from db - MYSQL R34 - Vince - 02.01.2014

You cannot, repeat cannot, retrieve a result immediately after sending a query while using threads. That's pretty much the whole point. What do you think the parameter "callback" is used for?


Re: Load Settings from db - MYSQL R34 - Konstantinos - 02.01.2014

pawn Код:
stock LoadSettings()
{
    mysql_tquery(g_Database, "SELECT * FROM `settings`", "OnSettingsLoad", "");
}

forward OnSettingsLoad();
public OnSettingsLoad()
{
    cache_get_row(0, 1, g_ServerInfo[sServername], g_Database, 170);
    g_ServerInfo[sPos][0] = cache_get_row_float(0, 2, g_Database);
    g_ServerInfo[sPos][1] = cache_get_row_float(0, 3, g_Database);
    g_ServerInfo[sPos][2] = cache_get_row_float(0, 4, g_Database);
    g_ServerInfo[sPos][3] = cache_get_row_float(0, 5, g_Database);
    g_ServerInfo[sInterior] = cache_get_row_int(0, 6, g_Database);
    g_ServerInfo[sVirtualWorld] = cache_get_row_int(0, 7, g_Database);
    g_ServerInfo[sSkin] = cache_get_row_int(0, 8, g_Database);
    g_ServerInfo[sCash] = cache_get_row_int(0, 9, g_Database);
    g_ServerInfo[sBank] = cache_get_row_int(0, 10, g_Database);
}
Vince, actually you can by using inline.


Re: Load Settings from db - MYSQL R34 - Ballu Miaa - 03.01.2014

Hey thanks Vince for the suggestion. I will keep in mind next time.

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
stock LoadSettings()
{
    mysql_tquery(g_Database, "SELECT * FROM `settings`", "OnSettingsLoad", "");
}
Vince, actually you can by using inline.
Hey Konstantinos my friend. Thanks for the reply. It worked. But whats the difference between mysql_tquery and mysql_function_query. Cause i used the code below.
pawn Код:
stock LoadSettings()
{
    mysql_function_query(g_Handle,  "SELECT * FROM `settings` WHERE id=0", true, "OnSettingsLoad", "");
}



Re: Load Settings from db - MYSQL R34 - newbienoob - 03.01.2014

It's just the same. If you opened a_mysql.inc;
#define mysql_function_query(%0,%1,%2,%3,"%4"%5) mysql_tquery(%0,%1,%3,#%4%5)
They just renamed it.