[Tutorial] Using BlueG's MySQL plugin R7 (with cache)
#61

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

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);
Reply
#63

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.
Reply
#64

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

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 :/
Reply
#66

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.
Reply
#67

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?
Reply
#68

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.
Reply
#69

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?
Reply
#70

In pawn, indexes start at 0. In phpmyadmin, they start at 1.
Reply
#71

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.
Reply
#72

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)
Reply
#73

How about selecting this:

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

How can I do this using cache_get_row
Reply
#74

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));
Reply
#75

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?
Reply
#76

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).
Reply
#77

//solved
Reply
#78

////
Reply
#79

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
Reply
#80

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


Forum Jump:


Users browsing this thread: 2 Guest(s)