SA-MP Forums Archive
db_free_result Crashes PAWN. - 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: db_free_result Crashes PAWN. (/showthread.php?tid=249761)



db_free_result Crashes PAWN. - Zh3r0 - 20.04.2011

Whenever i add the db_free_result function in this code, my pawn gives me a [Don't Send] error, and get's frustrating as i don't want memory leaks.


pawn Код:
new
                pQue[ 256 ];

            format( pQue, sizeof (pQue), "SELECT * FROM `Muted` WHERE `IP` = '%s'", GetPlayerIPEx( params[ 0 ] ) );
            new DBResult:RESULT = db_query( UsefullDatabase, pQue );
           
            P_DATA[ params[ 0 ] ][ Muted ] = 1;
            P_DATA[ params[ 0 ] ][ MutedTime ] = 0;

            new pQue2[ 256 ];
            if ( db_num_rows( RESULT ) )
                format( pQue2, sizeof (pQue2),"UPDATE `Muted` SET `IP` = '%s', `Muted` = '1', `Time` = '0', `RealName` = '%s'",GetPlayerIPEx( params[ 0 ] ), Name( params[ 0 ] ) );
            else
                format( pQue2, sizeof (pQue2), "INSERT INTO `Muted` ( `IP`, `Muted`, `Time`, `RealName` ) VALUES ('%s', '1', '0', '%s')", GetPlayerIPEx( params[ 0 ] ), Name( params[ 0 ] ) );
               

            db_query( UsefullDatabase, pQue2 );
            db_free_result( RESULT );
Any ideea that could cause this? I'm new into SQL and i still learn about it.

PS: That's from inside my /mute command.


Re: db_free_result Crashes PAWN. - Zh3r0 - 20.04.2011

Ok, so i made some changes, i moved up the Muted and MutedTime variables, and moved down the FormatMSG, and other textes.

pawn Код:
P_DATA[ params[ 0 ] ][ Muted ] = 1;
            P_DATA[ params[ 0 ] ][ MutedTime ] = 0;
           

            #if SAVE_MUTE == true
            new
           
                pQue[ 256 ];
           
            format( pQue, sizeof (pQue), "SELECT * FROM `Muted` WHERE `IP` = '%s'", GetPlayerIPEx( params[ 0 ] ) );
            new DBResult:RESULT = db_query( UsefullDatabase, pQue );
           
            new pQue2[ 256 ];
            if ( db_num_rows( RESULT ) )
                format( pQue2, sizeof (pQue2),"UPDATE `Muted` SET `IP` = '%s', `Muted` = '1', `Time` = '0', `RealName` = '%s'",GetPlayerIPEx( params[ 0 ] ), Name( params[ 0 ] ) );
            else
                format( pQue2, sizeof (pQue2), "INSERT INTO `Muted` ( `IP`, `Muted`, `Time`, `RealName` ) VALUES ('%s', '1', '0', '%s')", GetPlayerIPEx( params[ 0 ] ), Name( params[ 0 ] ) );
               

            db_query( UsefullDatabase, pQue2 ) && db_free_result( RESULT );
           
            #endif
           
            SendAdminCMD( playerid, "Admin "ORAN"%s[%i]"GREY" muted player "ORAN"%s[%i]", Name( playerid ), playerid, Name( params[ 0 ] ), params[ 0 ], params[ 1 ] );
            FormatMSG( playerid, Color:GREY, "You muted "ORAN"%s[%i]", Name( params[ 0 ] ), params[ 0 ] );
            SendClientMessage( params[ 0 ], Color:GREY, "You have been muted!");
Now works just fine...

Glad this is over but i still want to know the issue :O


Re: db_free_result Crashes PAWN. - Zh3r0 - 20.04.2011

Quote:
Originally Posted by ******
Посмотреть сообщение
What's with the "&&"? This isn't JavaScript... Plus that will only free your result if the first query happens - if it fails you have a memory leak.
That "&&" was just for fun, removed it btw.

This is strange, wherever in my script i try to use SQL functions, it starts to crash ... any more ideas ?


Re: db_free_result Crashes PAWN. - Finn - 20.04.2011

You don't have a ";" at the end of the query, I am not sure if it matters, but still. :P


Re: db_free_result Crashes PAWN. - Wyu - 20.04.2011

You may try INSERT OR REPLACE INTO

http://www.sqlite.org/lang_conflict.html

pawn Код:
"INSERT OR REPLACE INTO `Muted` ( `IP`, `Muted`, `Time`, `RealName` ) VALUES ('%s', '1', '0', '%s')", ....



Re: db_free_result Crashes PAWN. - Zh3r0 - 20.04.2011

Quote:
Originally Posted by Wyu
Посмотреть сообщение
You may try INSERT OR REPLACE INTO

http://www.sqlite.org/lang_conflict.html

pawn Код:
"INSERT OR REPLACE INTO `Muted` ( `IP`, `Muted`, `Time`, `RealName` ) VALUES ('%s', '1', '0', '%s')", ....
That's to replace the check if the IP and all those exist in the table?

Just to make sure before i replace my code.