SQLite Problem - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread:  SQLite Problem (
/showthread.php?tid=269441)
 
SQLite Problem - 
MJ! -  16.07.2011
I made a command.
pawn Код:
if(!strcmp(cmdtext, "/number", true))
    {
        new query[256], DBResult:Result;
        format(query, sizeof(query), "SELECT * FROM `Users` WHERE `Name` = '%s'", ReturnName(playerid));
        Result = db_query(iDatabase, query);
        if(!db_num_rows(Result))
        {
            new number[10];
            number[0] = '0';
            number[1] = '7';
            number[2] = (1 + random(8)) + '0';
            for(new i = 3; i < 10; i++)
            number[i] = random(10) + '0';
            format(query, sizeof(query), "INSERT INTO `Users` (`Name`,`Number`) VALUES('%s','%s')", ReturnName(playerid), DB_Escape(number));
            db_free_result(db_query(iDatabase, query));
            format(query, 128, "Name: %s | Phone number: %s", ReturnName(playerid), DB_Escape(number));
            SendClientMessage(playerid, -1, query);
        }
        return 1;
}
 
And look what happens:
Database: 
http://imageshack.us/photo/my-images/29/errorem.png/
Message : 
http://imageshack.us/f/121/samp033uy.png/
Re: SQLite Problem - 
Lorenc_ -  16.07.2011
Image is failing to load, therefore I don't know the problem :/
Re: SQLite Problem - 
MJ! -  16.07.2011
Quote:
| 
					Originally Posted by Lorenc_  Image is failing to load, therefore I don't know the problem :/ | 
 http://imageshack.us/photo/my-images/121/samp033uy.png/
Re: SQLite Problem - 
Lorenc_ -  16.07.2011
Why do you need to use DB_Escape? For it? Why not just use 
Db_get_field_assoc instead or just have the query (string) formatted without the DB_escape on the phone number string?
Re: SQLite Problem - 
MJ! -  16.07.2011
Quote:
| 
					Originally Posted by Lorenc_  Why do you need to use DB_Escape? For it? Why not just use Db_get_field_assoc  instead or just have the query (string) formatted without the DB_escape on the phone number string? | 
 Can you show me an example ? Thanks in advice.
PS: But lol, for what db_get_field_assoc ? I don't need it. I must insert the number, lol.
Re: SQLite Problem - 
Lorenc_ -  16.07.2011
pawn Код:
new Field[20], iNumber[20];
db_get_field_assoc(iDatabase, "Number", Field, 20);
format(iNumber, 20, "%s", Field);
 
Re: SQLite Problem - 
MJ! -  16.07.2011
Quote:
| 
					Originally Posted by Lorenc_  
pawn Код: new Field[20], iNumber[20];db_get_field_assoc(iDatabase, "Number", Field, 20);
 format(iNumber, 20, "%s", Field);
 | 
 I'm trying to insert the number in database, not to extract him 

.
Re: SQLite Problem - 
Lorenc_ -  16.07.2011
The only thing I saw wrong in the image is the SendClientMessage thing, thats what i'm trying to help you fix :P
Re: SQLite Problem - 
MJ! -  16.07.2011
Quote:
| 
					Originally Posted by Lorenc_  The only thing I saw wrong in the image is the SendClientMessage thing, thats what i'm trying to help you fix :P | 
 http://imageshack.us/photo/my-images/29/errorem.png/ ( I've changed from Users to Clients )
Re: SQLite Problem - 
Lorenc_ -  16.07.2011
Ohh then, replace ' DB_Escape(number) ' with just ' number ' without the '
After that show me your results.