SA-MP Forums Archive
Convert 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: Convert SQL (/showthread.php?tid=659061)



Convert SQL - ServerFiles - 21.09.2018

How can I convert this SQL to R39+?

PHP код:
            while(mysql_fetch_row_format(Query,"|"))
            {
                
mysql_fetch_field_row(DupekeyString[playerid][DupekeyCount[playerid]], "dupekey");
                
format(DupekeyName[playerid],126,DupekeyString[playerid][DupekeyCount[playerid]]);
                
DupekeyCount[playerid]++;
            } 



Re: Convert SQL - Calisthenics - 22.09.2018

mysql_fetch_row_format fetches the row and splits the result using the delimiter |
Since while loop is used, it means it moves to the next row as you select more than 1 row.

A SELECT query with the "dupekey" column:
pawn Код:
mysql_format(connectionHandle, query, sizeof query, "SELECT dupekey FROM .. WHERE ...", ...);
mysql_tquery(connectionHandle, query, "OnPlayerDupekeyLoad", "i", playerid);
Alter the rest (table name, column names at WHERE clause).

Now you want to retrieve the value in the callback specified (always a public function + forward).
We'll also use a loop as in the old code in case it retrieves multiple rows and counts:
pawn Код:
forward OnPlayerDupekeyLoad(playerid);
public OnPlayerDupekeyLoad(playerid)
{
    // cache_num_rows() is a macro
    for (new i = 0, j = cache_num_rows(); i < j; i++)
    {
        // mysql_fetch_field_row -> cache_get_field_content  
        // native cache_get_field_content(row, const field_name[], destination[], connectionHandle = 1, max_len = sizeof(destination));
        cache_get_field_content(i, "dupekey", DupekeyString[playerid][DupekeyCount[playerid]], connectionHandle, 126);
        strcpy(DupekeyName[playerid], DupekeyString[playerid][DupekeyCount[playerid]], 126);
        DupekeyCount[playerid]++;
    }
}
After assigning the text to DupekeyString, you copy the text over to DupekeyName. Strcpy (a macro of strcat) is better than format:
pawn Код:
#if !defined strcpy
    #define strcpy(%0,%1) strcat((%0[0] = '\0', %0[0]), %1)
#endif



Re: Convert SQL - ServerFiles - 22.09.2018

thanks, worked now but I have another problem.

When I open the dialog for the first time, it shows no problem but whenever I open it for second time or third or more, it doubles up (example below)

PHP код:
/* What I mean is like this (dialog):
Username 1
Username 2
Username 3
Now when I reopen the dialog 2nd time:
Username 1
Username 2
Username 3
Username 1
Username 2
Username 3
and so on.
*/
                
case 6:
                {
                    if(
strcmp(House[tmpid][tmpowner], PlayerName(playerid), false) && PlayerInfo[playerid][power] < 4) return SendClientError(playerid"You don't own this house!");
                    {
                        new 
Query[256];
                        
mysql_format(sqldbQuerysizeof Query"SELECT * FROM `HouseKeys` WHERE `houseid` = '%d'"tmpid);
                        
mysql_tquery(sqldbQuery"OnPlayerDupekeyLoad""i"playerid);
                        new 
laststring[400],string[400];
                        for(new 
0DupekeyCount[playerid]; i++)
                        {
                            
format(laststring,sizeof(laststring),"%%s\n",laststring,DupekeyString[playerid][i]);
                        }
                        
format(string,sizeof(string),"{FF0000}[+] {FFFFFF}Create a new key\n");
                        
strcat(string,laststring);
                         
ShowPlayerDialog(playerid,3001,DIALOG_STYLE_LIST,"Manage Duplicate Keys",string,"Select","Cancel");
                         return 
1;
                    }
                }