SA-MP Forums Archive
[Tutorial] Using BlueG's MySQL plugin R7 (with cache) - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Using BlueG's MySQL plugin R7 (with cache) (/showthread.php?tid=337810)

Pages: 1 2 3 4 5 6


Re: Using BlueG's MySQL plugin R7 (with cache) - ScriptWriter - 13.10.2012

But if i want return just score (index 2), kills (index 4) and deaths (index 5)? How return only these fields?


Re: Using BlueG's MySQL plugin R7 (with cache) - AndreT - 13.10.2012

Oh god, listen.

The field indexes are RELATIVE TO THE QUERY. Not the MySQL table structure. This means that if your query looks like this:
SELECT score, kills, deaths FROM players WHERE name = 'ScriptWriter'
Then the fields returned will be
score, kills, deaths
Their indexes will be
0, 1, 2

In a more fashionable form:
scorekillsdeaths
012
However, if your query returns a row with 18 fields, you can EASILY get the fields with indexes 2, 4 and 5, since that's what cache_get_row is for. Please head to the first post and see that its syntax is easy:
cache_get_row(row, idx, dest[], connectionHandle = 1)

The second parameter is INDEX. So act like this:
pawn Code:
new temp[12], score, kills, deaths;
cache_get_row(0, 2, temp); score = strval(temp);
cache_get_row(0, 4, temp); kills = strval(temp);
cache_get_row(0, 5, temp); deaths = strval(temp);
printf("The player whose data was just loaded has %d score, %d kills and %d deaths.", score, kills, deaths);



Re: Using BlueG's MySQL plugin R7 (with cache) - ScriptWriter - 01.11.2012

Hey, i have problem with this query...
Line:
Code:
mysql_format(ConnectionHandle, Query, "SELECT `IP`, `Pinigai`, `Banke`, `EXP`, `Level`, `Lytis`, `Skin`, `PosX`, `PosY`, `PosZ`, `PosA`, `Interjeras`, `Health`, `Armor`, `Ispejimai`, `Admin`, `Darbas`, `Gun0`, `Ammo0`, `Gun1`, `Ammo1`, `Gun2`, `Ammo2`, `Gun3`, `Ammo3`, `Gun4`, `Ammo4`, `Gun5`, `Ammo5`, `Gun6`, `Ammo6`, `Gun7`, `Ammo7`, `Gun8`, `Ammo8`, `Gun9`, `Ammo9`, `Gun10`, `Ammo10`, `Gun11`, `Ammo11` FROM `players` WHERE `Vardas` = '%e' AND `Slaptazodis` = '%e'", GetPlayerNameEx(playerid), buffer);
Error:
Code:
error 075: input line too long (after substitutions)
I asked AndreT how fix this problem and he reply to me use strcat, but i want more answer from other scripters how fix this problem with best method or details explane how use strcat in my query.


Re: Using BlueG's MySQL plugin R7 (with cache) - Edvin - 01.11.2012

@ScriptWriter try to use strcat or format? ... that line is too long.


Re: Using BlueG's MySQL plugin R7 (with cache) - ScriptWriter - 01.11.2012

Quote:
Originally Posted by Edvin
View Post
@ScriptWriter try to use strcat or format? ... that line is too long.
Yes, i tried and with strcat worked, but AndreT sayed that:
Notice that this is not probably the best method.
So i want know best method how fix this problem :/


Re: Using BlueG's MySQL plugin R7 (with cache) - IstuntmanI - 01.11.2012

Just change
Code:
mysql_format(ConnectionHandle, Query, "SELECT `IP`, `Pinigai`, `Banke`, `EXP`, `Level`, `Lytis`, `Skin`, `PosX`, `PosY`, `PosZ`, `PosA`, `Interjeras`, `Health`, `Armor`, `Ispejimai`, `Admin`, `Darbas`, `Gun0`, `Ammo0`, `Gun1`, `Ammo1`, `Gun2`, `Ammo2`, `Gun3`, `Ammo3`, `Gun4`, `Ammo4`, `Gun5`, `Ammo5`, `Gun6`, `Ammo6`, `Gun7`, `Ammo7`, `Gun8`, `Ammo8`, `Gun9`, `Ammo9`, `Gun10`, `Ammo10`, `Gun11`, `Ammo11` FROM `players` WHERE `Vardas` = '%e' AND `Slaptazodis` = '%e'", GetPlayerNameEx(playerid), buffer);
to
Code:
mysql_format(ConnectionHandle, Query, "SELECT * FROM `players` WHERE `Vardas` = '%e' AND `Slaptazodis` = '%e'", GetPlayerNameEx(playerid), buffer);
This selects all columns from that row.


Re: Using BlueG's MySQL plugin R7 (with cache) - ScriptWriter - 01.11.2012

Quote:
Originally Posted by costel_nistor96
View Post
Just change
Code:
mysql_format(ConnectionHandle, Query, "SELECT `IP`, `Pinigai`, `Banke`, `EXP`, `Level`, `Lytis`, `Skin`, `PosX`, `PosY`, `PosZ`, `PosA`, `Interjeras`, `Health`, `Armor`, `Ispejimai`, `Admin`, `Darbas`, `Gun0`, `Ammo0`, `Gun1`, `Ammo1`, `Gun2`, `Ammo2`, `Gun3`, `Ammo3`, `Gun4`, `Ammo4`, `Gun5`, `Ammo5`, `Gun6`, `Ammo6`, `Gun7`, `Ammo7`, `Gun8`, `Ammo8`, `Gun9`, `Ammo9`, `Gun10`, `Ammo10`, `Gun11`, `Ammo11` FROM `players` WHERE `Vardas` = '%e' AND `Slaptazodis` = '%e'", GetPlayerNameEx(playerid), buffer);
to
Code:
mysql_format(ConnectionHandle, Query, "SELECT * FROM `players` WHERE `Vardas` = '%e' AND `Slaptazodis` = '%e'", GetPlayerNameEx(playerid), buffer);
This selects all columns from that row.
I can't do this because i using cache_get_row function Maybe anyone knows better method?


Re: Using BlueG's MySQL plugin R7 (with cache) - IstuntmanI - 01.11.2012

A column's index can be found in the phpmyadmin, at structure of that table, or just look in which order you created the columns.


Re: Using BlueG's MySQL plugin R7 (with cache) - ScriptWriter - 01.11.2012

Quote:
Originally Posted by costel_nistor96
View Post
A column's index can be found in the phpmyadmin, at structure of that table, or just look in which order you created the columns.
But must first index be 0?


Re: Using BlueG's MySQL plugin R7 (with cache) - ReneG - 01.11.2012

In pawn, indexes start at 0. In phpmyadmin, they start at 1.


Re: Using BlueG's MySQL plugin R7 (with cache) - ReneG - 11.11.2012

Quote:
Originally Posted by AirKite
Посмотреть сообщение
But i not understand that cached? mysql_fetch_field_row also contains cached data, or i wrong?
mysql_fetch_field_row does not contain cached data. I don't know why, but retrieving data from the cache is faster than mysql_X functions. Also, if you read the tutorial, results are automatically stored/freed so you don't have to use mysql_store_result or mysql_free_result.


Re: Using BlueG's MySQL plugin R7 (with cache) - AirKite - 11.11.2012

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
mysql_fetch_field_row does not contain cached data. I don't know why, but retrieving data from the cache is faster than mysql_X functions. Also, if you read the tutorial, results are automatically stored/freed so you don't have to use mysql_store_result or mysql_free_result.
pff... In this case, what mean cached data? In my understanding, cache data = all data in ram memory from MySQL server. (after query)


Re: Using BlueG's MySQL plugin R7 (with cache) - fordawinzz - 23.11.2012

How about selecting this:

pawn Код:
TIMESTAMPDIFF(MINUTE, NOW(), DATE_ADD(Timestamp, INTERVAL Time MINUTE))
?

How can I do this using cache_get_row


Re: Using BlueG's MySQL plugin R7 (with cache) - AndreT - 23.11.2012

If your query looks something like
SELECT TIMESTAMPDIFF(MINUTE, NOW(), DATE_ADD(Timestamp, INTERVAL Time MINUTE)) FROM ...
then using the cache works similarly to what I've described in previous posts.
pawn Код:
cache_get_row(0, 0, temp);
printf("Difference in minutes: %d", strval(temp));



Re: Using BlueG's MySQL plugin R7 (with cache) - fordawinzz - 24.11.2012

Ok, I got it. Now, how I can select only one string and return it? Because public does not returns arrays. Saving it into a variabile?


Re: Using BlueG's MySQL plugin R7 (with cache) - AndreT - 24.11.2012

Solutions such as
pawn Код:
stock GetPlayerAttribute(playerid)
{
    new ID;
    mysql_query("SELECT attribute FROM players_table WHERE name = 'Player'");
    mysql_store_result();
    if(mysql_num_rows())
    {
        new temp[12];
        mysql_fetch_row(temp);
        mysql_free_result();
        return strval(temp);
    }
    mysql_free_result();
    return false;
}
// tl;dr - this code is crappy...
should be considered obsolete and bad in many many cases since it is a clear hint that the code could use some restructuring and better architecture in general. I have seen plenty of functions like this being called even THREE or more times in one small function whereas only one query would actually suffice or if proper coding methods would be used, there would be no need to make a query to the MySQL server to get frequently-accessed data, it would rather be pre-stored somewhere (arrays, dynamic memory, whatever).


Re: Using BlueG's MySQL plugin R7 (with cache) - EterNo - 26.11.2012

//solved


Re: Using BlueG's MySQL plugin R7 (with cache) - EterNo - 26.11.2012

////


Re: Using BlueG's MySQL plugin R7 (with cache) - CoDeZ - 26.11.2012

Quote:
Originally Posted by EterNo
Посмотреть сообщение
i have:
Код:
cache_get_row(0, 4, temp), g_PlayerInfo[playerid][pHealth] = floatstr(temp); and, 

SetPlayerHealth(playerid, g_PlayerInfo[playerid][pHealth]);
from MySQL R7 - Example Account Scriptby: VincentDunn

for cache_get_row(0, 5, temp), g_PlayerInfo[playerid][pLottoNr] = strval(temp);

how make SetPlayer.. ??
I don't really understand what are you trying to say but there is no native function called SetPlayerLottoNr


Re: Using BlueG's MySQL plugin R7 (with cache) - Marusa - 03.12.2012

How can I load 300 houses and set it to array ?? Can you make simple example ? :/