SA-MP Forums Archive
Problem selecting ID and name from SQLite database - 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: Problem selecting ID and name from SQLite database (/showthread.php?tid=457848)



Problem selecting ID and name from SQLite database - Cypress - 13.08.2013

Hello,

I have a problem selecting ID and name from SQLite databalse.

What I was doing is:

pawn Код:
CMD:savedplayers(playerid, params[])
{
    new string[300], DBResult: result;

    result = db_query(serverDB,  "SELECT `ID` AND  `NAME` FROM `PLAYERS`");

    if (db_num_fields(result))
    {
            format(string, sizeof(string), "%s%s", ...);
            ShowPlayerDialog(playerid, 0, DIALOG_STYLE_LIST, "Saved Player List", string, "Close", "");
        db_free_result(result);
        return 1;
    }
    else
    {
        db_free_result(result);
        return 0;
    }
   return 1;
}
So how do I basically show a list of saved players.. I'm lost.


Re: Problem selecting ID and name from SQLite database - Misiur - 13.08.2013

Change AND to comma.


Re: Problem selecting ID and name from SQLite database - Dubya - 13.08.2013

Not sure with SQLite, but I am 50% sure that that query is wrong.

"SELECT `ID` AND `NAME` FROM `PLAYERS`" isn't a complete query.

"SELECT `ID` AND `NAME` FROM `PLAYERS` WHERE 1" is a complete query.


Re: Problem selecting ID and name from SQLite database - Cypress - 13.08.2013

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Change AND to comma.
You sure that just this will make it work? What about a loop? Is it not needed?

Quote:
Originally Posted by Dubya
Посмотреть сообщение
Not sure with SQLite, but I am 50% sure that that query is wrong.

"SELECT `ID` AND `NAME` FROM `PLAYERS`" isn't a complete query.

"SELECT `ID` AND `NAME` FROM `PLAYERS` WHERE 1" is a complete query.
What does that WHERE 1 do? As I know WHERE is a clause that is used to extract only those records that fulfill a specified criterion.


Re: Problem selecting ID and name from SQLite database - Dubya - 13.08.2013

the one stands for a global where ID and Name are both set to something, it will select them.


Re: Problem selecting ID and name from SQLite database - Misiur - 13.08.2013

SQLite doesn't require WHERE statement (I think, at least looking at http://www.sqlite.org/lang_select.html ). Currently your query selects all names and id's, but the code processes only first row.