db_free_result Crashes PAWN.
#1

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.
Reply
#2

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
Reply
#3

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 ?
Reply
#4

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

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')", ....
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)