SA-MP Forums Archive
Converting into newer SQL - 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: Converting into newer SQL (/showthread.php?tid=584658)



Converting into newer SQL - TwinkiDaBoss - 06.08.2015

So Ive got some old code I wanna convert into new SQL version but how do I do that? Im not really good with SQL or such.

This is for testing purposes. The goal is to achieve top players.

pawn Код:
CMD:test(playerid,params[])
{
    mysql_query("SELECT `Name`, `Score` FROM `players` ORDER BY `Score` DESC LIMIT 10");
    mysql_store_result();
    new szPrepTD[460], iIterator = 1, iScore, szName[MAX_PLAYER_NAME], szUnload[64];
    while(mysql_fetch_row_format(szUnload))
    {
        sscanf(szUnload, "p<|>sd", szName, iScore);
        if(strlen(szPrepTD) == 0) format(szPrepTD, sizeof(szPrepTD), "#%d - %s (%d score)\n", iIterator, szName, iScore);
        format(szPrepTD, sizeof(szPrepTD), "%s#%d - %s (%d score)\n", szPrepTD, iIterator, szName, iScore);
        iIterator++;
    }
    mysql_free_result();
    return true;
}
1. Yes Im using BlueG's SQL plugin
2. Yes Im aware that some stuff changed
3. Yes im aware a bit bit noobish with SQL

pawn Код:
error 035: argument type mismatch (argument 1)
 error 017: undefined symbol "mysql_store_result"
 error 017: undefined symbol "mysql_fetch_row_format"
 error 017: undefined symbol "mysql_free_result"

The goal is to get top 10 Score's from players database


Re: Converting into newer SQL - Abagail - 06.08.2015

pawn Код:
CMD:test(playerid, params[])
{
       mysql_tquery(dbHandle, query, "SELECT `Name`, `Score` FROM `players` ORDER BY `Score` DESC LIMIT 10", "onTestCallback", "i", playerid);
       return 1;
}

forward onTestCallback(playerid);
public onTestCallback(playerid)
{
    new szPrepTD[460], iIterator = 0, iScore, szName[MAX_PLAYER_NAME], szUnload[64], rows, data;
cache_get_data(rows, data, dbHandle);

if(rows)
{
    while(iIterator < rows)
    {
        sscanf(szUnload, "p<|>sd", szName, iScore);
        if(strlen(szPrepTD) == 0) format(szPrepTD, sizeof(szPrepTD), "#%d - %s (%d score)\n", iIterator, szName, iScore);
        format(szPrepTD, sizeof(szPrepTD), "%s#%d - %s (%d score)\n", szPrepTD, iIterator, szName, iScore);
        iIterator++;
    }
}

else SendClientMessage(playerid, -1, "No query results.");
return 1;



Re: Converting into newer SQL - TwinkiDaBoss - 07.08.2015

Aha, so if I understood correctly from this example, preety much with the newer SQL plugin, I'd have to call it under a function instead?


EDIT: Just a headsup, the command itself doesnt work tho
pawn Код:
mysql_tquery - connection: 0, query: "", callback: "SELECT `Username`, `Score` FROM `players` ORDER BY `Score` DESC LIMIT 10", format: "onTestCallback"



Re: Converting into newer SQL - TwinkiDaBoss - 07.08.2015

Fixed, thanks to Konstantinos!