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=267422)
SQLite Problem -
Rock_Ro - 08.07.2011
pawn Код:
public OnPlayerConnect( playerid )
{
new Query2[ 256 ];
new DBResult:RRezult;
format( Query2, sizeof( Query2 ), "SELECT 'Reputation' FROM `REPUTATION` WHERE `Name` = '%s'", CName( playerid ) );
RRezult = db_query( Database, Query2 );
if( db_num_rows( RRezult ) )
{
new Field[ 30 ];
new Reputation;
db_get_field_assoc( RRezult, #Reputation, Field, 30 );
Reputation = strval( Field );
RK_REP[ playerid ][ RK_REPUTATION ] = Reputation;
}
db_free_result( RRezult );
}
public OnPlayerDisconnect( playerid )
{
format( Query, sizeof( Query ), "UPDATE `REPUTATION` (`Name`, `Reputation`) VALUES('%s', '%d')", CName( playerid ), RK_REP[ playerid ][ RK_REPUTATION ] );
db_free_result( db_query( Database, Query ) );
}
It save's "Reputation" but it doesen't load on connect, what the problem could be ?
Re: SQLite Problem -
Lorenc_ - 08.07.2011
instead of #Reputation try "Reputation"
If that wont work, supposedly, it could be the OnPlayerDisconnect query
Re: SQLite Problem -
Rock_Ro - 08.07.2011
pawn Код:
C:\Documents and Settings\--\Desktop\--.pwn(54) : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
1 Error.
Doesen't work that way...
Re: SQLite Problem -
Lorenc_ - 08.07.2011
pawn Код:
public OnPlayerDisconnect( playerid )
{
format( Query, sizeof( Query ), "UPDATE `REPUTATION` SET Reputation = '%d' WHERE Name = '%s') ", RK_REP[ playerid ][ RK_REPUTATION ], GetName(playerid) );
db_free_result( db_query( Database, Query ) );
}
Try this.
That should work, it has to have the ' " ' character besides them like this:
pawn Код:
db_get_field_assoc(Result, "GANGID", Field, 30);
Re: SQLite Problem -
[NoV]LaZ - 08.07.2011
Код:
UPDATE `Reputation` SET `Reputation` = '%d' WHERE `Name` = '%s';
I don't know on what basis you want to update the database. Also, why do you need to update the player's name ?
Re: SQLite Problem -
Bakr - 08.07.2011
There is something wrong with your db_get_field_assoc function. It's returning an invalid tag because you must have something conflicting with "Reputation". Do you have a definition with Reputation?
Re: SQLite Problem -
Rock_Ro - 08.07.2011
@Bakr
No...
@Lorenc_
Doesen't Work...
It won't load and it won't update...
Re: SQLite Problem -
Lorenc_ - 08.07.2011
Have you even inserted the player data into the database?
Ahhh!!
change 'Reputation' to `Reputation`
Re: SQLite Problem -
Rock_Ro - 08.07.2011
pawn Код:
public OnFilterScriptInit( )
{
Database = db_open( "RepPlayers.db" );
db_free_result( db_query( Database, "CREATE TABLE IF NOT EXISTS `REP` (`Name`, `Reputation`)" ) );
}
public OnFilterScriptExit( )
{
db_close( Database );
}
public OnPlayerConnect( playerid )
{
new Query2[ 256 ];
new DBResult:RRezult;
format( Query2, sizeof( Query2 ), "SELECT 'Reputation' FROM `REP` WHERE `Name` = '%s'", CName( playerid ) );
RRezult = db_query( Database, Query2 );
if( db_num_rows( RRezult ) )
{
new Field[ 30 ];
new Reputation;
db_get_field_assoc( RRezult, "Reputation", Field, 30);
Reputation = strval( Field );
RK_REP[ playerid ][ RK_REPUTATION ] = Reputation;
}
db_free_result( RRezult );
}
public OnPlayerDisconnect( playerid )
{
format( Query, sizeof( Query ), "UPDATE 'Reputation' FROM `REP` (`Name`, `Reputation`) VALUES('%s', '%d')", CName( playerid ), RK_REP[ playerid ][ RK_REPUTATION ] );
db_free_result( db_query( Database, Query ) );
}
The part of the code witch contains SQLite
Re: SQLite Problem -
[NoV]LaZ - 08.07.2011
Код:
SELECT `Reputation` FROM `REP` WHERE `Name` = '%s'
pawn Код:
new field[30];
db_get_field_assoc(RREzult, "Reputation", field, sizeof (field));
RK_REP[playerid][RK_REPUTATION] = strval(field);
Your UPDATE syntax is not correct, check the posts above.