SA-MP Forums Archive
Some Questions [SQLite] - 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: Some Questions [SQLite] (/showthread.php?tid=376905)



Some Questions [SQLite] - Glint - 12.09.2012

Hello guys i have some question about SQLite :

Can you please explain this part :
pawn Код:
public OnFilterScriptExit()
{
    for(new i; i != MAX_PLAYERS; i++) OnPlayerDisconnect(i, 1);
    db_close(Database);
    return 1;
}
I am new to scripting i just want to know why are you looping ? Why don't you just use :
pawn Код:
db_close(Database);
And also Do i need the DB_Escape stock :
pawn Код:
stock DB_Escape(text[])
{
    new
        ret[80 * 2],
        ch,
        i,
        j;
    while ((ch = text[i++]) && j < sizeof (ret))
    {
        if (ch == '\'')
        {
            if (j < sizeof (ret) - 2)
            {
                ret[j++] = '\'';
                ret[j++] = '\'';
            }
        }
        else if (j < sizeof (ret))
        {
            ret[j++] = ch;
        }
        else
        {
            j++;
        }
    }
    ret[sizeof (ret) - 1] = '\0';
    return ret;
}
Because i made the system without using that ^ stock it worked fine.


Thanks in advance.


Re: Some Questions [SQLite] - Guitar - 12.09.2012

I think(not sure) that,

pawn Код:
public OnFilterScriptExit()
{
    for(new i; i != MAX_PLAYERS; i++) OnPlayerDisconnect(i, 1);
    db_close(Database);
    return 1;
}
will save the stats in the "Database" for all the players when they leave. the ( i ) is representing the whole players in the server.


Re: Some Questions [SQLite] - [HiC]TheKiller - 12.09.2012

For the first question, I wouldn't see the point of calling OnPlayerDisconnect when the filterscript exits, it could seriously screw up other things in your code (it's probably done to save all players but you should make a custom function for that) , just close the database if you're not going to be loading and unloading the filterscript constantly.

For the second question, you do need db_escape if you're saving any user input other than someone's name. Hackers could use crafted inputs to select, delete, insert or modify data in your database.


Re: Some Questions [SQLite] - Lorenc_ - 12.09.2012

pawn Код:
for(new i; i != MAX_PLAYERS; i++) OnPlayerDisconnect(i, 1);
Feel free to remove this. This calls OnPlayerDisconnect to ensure they are having their account saved.


Re: Some Questions [SQLite] - Glint - 12.09.2012

Thanks all of you now i get it!