How to add\remove with SQLite ?
#1

*title*
Like :
pawn Код:
format(Query,sizeof(Query),"ADD COOKIES = 50 REMOVE COOKIES = 49 WHERE `NAME` = '%s'");
Quote:
Originally Posted by Skillet`
Посмотреть сообщение
Oh,sorry,explained bad,how do I add\take(remove) a specific number to\from a value in the database ?
Reply
#2

pawn Код:
format( Query, sizeof( Query ), "UPDATE `TABLE_NAME` SET COOKIES = '%d' WHERE `NAME` = '%s'", cookies, DB_Escape( name ) );
db_free_result( db_query( Database, Query ) );
pawn Код:
format( Query, sizeof( Query ), "DELETE FROM `TABLE_NAME` WHERE `NAME` = '%s'", DB_Escape( name ) );
db_free_result( db_query( Database, Query ) );
Reply
#3

EDIT: Oh,sorry,explained bad,how do I add\take(remove) a specific number to\from a value in the database ?
Reply
#4

It sets it to the specified number, but you can add it if you want by adding the previous number of cookies + cookies.
Reply
#5

Sorry,I recently started learning SQLite,can you show how should I do it ?
I understood what you said,but it means I should 'get' the value and add to it the number I want,like x + 23
but how do I know what number written in the database ? (x = ?)
Reply
#6

I wrote an example as command!
pawn Код:
CMD:addcookies( playerid, params[ ] )
{
    new
        id,
        cookies
    ;
    if( sscanf( params, "ud", id, cookies ) ) return SendClientMessage( playerid, -1, "Syntax: /addcookies <ID> <Cookies>" );
    if( !IsPlayerConnected( id ) && id == INVALID_PLAYER_ID ) return SendClientMessage( playerid, -1, "Invalid player ID!" );
    new
        name[ MAX_PLAYER_NAME ]
    ;
    GetPlayerName( id, name, MAX_PLAYER_NAME );
    format( Query, sizeof( Query ), "SELECT `COOKIES` FROM `USERS` WHERE `NAME` = '%s'", DB_Escape( name ) );
    Result = db_query( Database, Query );

    if( db_num_rows( Result ) )
    {
        new
            Field[ 30 ]
        ;
        format( Query, sizeof( Query ), "UPDATE `USERS` SET COOKIES = '%d' WHERE `NAME` = '%s'", db_get_field_assoc( Result, "COOKIES", Field, 30 ) + cookies, DB_Escape( Ip ) );
        db_free_result( db_query( Database, Query ) );
    }
    return 1;
}
Almost similar for /takecookies except that instead of "db_get_field_assoc( Result, "COOKIES", Field, 30 ) + cookies", you'll have minus.
Reply
#7

Oh,thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)