Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Cool on Feb 21, 2017, 04:35 PM

Title: Commit Transaction error
Post by: Cool on Feb 21, 2017, 04:35 PM
Dont know why its happening
function RegisterClan( Clan )
{
SafeSelect( sDB, "START TRANSACTION" );
        SafeSelect( sDB, format( "REPLACE INTO ClanStats (Clan) VALUES ('%s')", Clan ) );
        SafeSelect( sDB, format( "REPLACE INTO ClanUsers (Clans) VALUES ('%s')", Clan ) );
SafeSelect( sDB, "COMMIT TRANSACTION" );

}
http://imgur.com/a/qbwCT
Error line:
SafeSelect( sDB, "COMMIT TRANSACTION" ); Note: SafeSelect  is a function By SLC which give right details of error
Title: Re: Commit Transaction error
Post by: . on Feb 21, 2017, 04:41 PM
SafeSelect() was designed for "SELECT" statements that actually return something. "START TRANSACTION" does not return anything and therefore it shouldn't be used with that function. Actually it can be used but it should be renamed to something like SafeQuery()

Just to make things more readable.
Title: Re: Commit Transaction error
Post by: Cool on Feb 21, 2017, 05:19 PM
Now its not giving error but its not putting in db
Title: Re: Commit Transaction error
Post by: jWeb on Feb 21, 2017, 05:22 PM
Also, I believe you are supposed to include a ; at the end of your SQL statements. Although I'm not sure if that's the issue here.
Title: Re: Commit Transaction error
Post by: KAKAN on Feb 21, 2017, 05:55 PM
I don't understand why don't you put them into 1 string and execute it?
Also, I don't think START and COMMIT are necessary. Its useful when doing multiple queries at once, but you're doing them one by one, so no use of them at all.
Title: Re: Commit Transaction error
Post by: Cool on Feb 21, 2017, 06:01 PM
Quote from: KAKAN on Feb 21, 2017, 05:55 PMI don't understand why don't you put them into 1 string and execute it?
Also, I don't think START and COMMIT are necessary. Its useful when doing multiple queries at once, but you're doing them one by one, so no use of them at all.
But now problem is that queries failing and no error
Title: Re: Commit Transaction error
Post by: jWeb on Feb 21, 2017, 06:01 PM
Quote from: KAKAN on Feb 21, 2017, 05:55 PMAlso, I don't think START and COMMIT are necessary. Its useful when doing multiple queries at once, but you're doing them one by one, so no use of them at all.

Incorrect. Queries within a transaction will not be committed regardless of how they're executed.
Title: Re: Commit Transaction error
Post by: Cool on Feb 21, 2017, 07:45 PM
Queries working fine without START TRANSACTION  And Commit TRANSACTION but why not working with TRANSACTION
Title: Re: Commit Transaction error
Post by: KAKAN on Feb 22, 2017, 05:20 AM
sry, what do you mean by saying "not working with TRANSACTION, but works with START TRANSACTION"?
Are you trying to differentiate between START TRANSACTION
....
and TRANSACTION
....
?
That's more like finding the difference between
array.remove and just .remove.... That's what I understood :x
Title: Re: Commit Transaction error
Post by: Thijn on Feb 22, 2017, 07:34 AM
Does your table type actually support transactions, i.e. InnoDB?
Title: Re: Commit Transaction error
Post by: Cool on Feb 22, 2017, 10:03 AM
@Thijn db type = InnoDB   latin1_swedish_ci
Title: Re: Commit Transaction error
Post by: Cool on Feb 22, 2017, 11:50 AM
help!!!!!
if i dont use Start Transaction any disadvantage
Title: Re: Commit Transaction error
Post by: KAKAN on Feb 22, 2017, 12:09 PM
Quote from: happymint2 on Feb 22, 2017, 11:50 AMhelp!!!!!
if i dont use Start Transaction any disadvantage
Nope. From the time I've used SQL, I never really used Start transaction... I only saw it in sql files :x
Title: Re: Commit Transaction error
Post by: Cool on Feb 22, 2017, 01:27 PM
[Off-topic] mysql plugin not giving any errors on line its hard to understand whats wrong happening
[Edit]else if ( cmd == "addmanager" )
             {
                    // This command is for any admin
                    if ( !text ) Msg( "Syntax > !addmanager <[Tag]Owner> <[Tag]Leader> <[Tag]Leader2> <Clan-Without-Symbol>", player );
      else if ( i <= 3 ) Msg( "Syntax > !addmanager <[Tag]Owner> <[Tag]Leader> <[Tag]Leader2> <Clan-Without-Symbol>", player );
                    else
                       {
                       if ( !IsClanRegister( params[ 3 ].tolower() ) ) Msg( "Error > The clan " + params[ 3 ] + " is no register!", player );
                       else {
                                local Owner = params[ 0 ], Manager1 = params[ 1 ], Manager2 = params[ 2 ], Clan = params[ 3 ];
                              if ( !GetTag( Owner ) ) PM( "Error > The owner need clan!!", player );
                               else if ( !GetTag( Manager1 ) ) PM( "Error > The Manager 1 need clan!!", player );
                              else if ( !GetTag( Manager2 ) ) PM( "Error > The Manager 2 need clan!!", player );

                                All( player.Name + "'s added owner/managers in Clan: " + Clan );
                                All( "(Owner)-> " + Owner + " - (Managers)-> " + Manager1 + ", " + Manager2 );
                              mysql_query( sDB, format( "UPDATE ClanStats SET Leaders='%s' lower(Clan)='" + Clan.tolower() + "'", "" + Owner + ", " + Manager1 + ", " + Manager2 + "" ) );

                                PM( "Okay! Now need put !adduser <Your Player Of Clan> Example: deviL", player );
                                   local dos = SafeSelect( sDB, "SELECT Users FROM ClanUsers WHERE lower(Clans)='" + Clan.tolower() + "'" );
                                  if( ::mysql_num_rows( dos ) == 0 ){
                                   local result = mysql_fetch_assoc( dos );
                                    local Users =  Clans = result[ "Clans" ];
           // Create Managers And owner in database dont delete this "DFAX0067XLPKDW"
                                if ( Users ) mysql_query( sDB, format( "UPDATE ClanUsers SET Users='%s' WHERE lower(Clans)='" + Clan + "'", ""+Users+" " + TruncateClan( Owner ) + " " + TruncateClan( Manager1 ) + " " + TruncateClan( Manager2 ) + "" ) );
                    else mysql_query( sDB, format( "UPDATE ClanUsers SET Users='%s' WHERE lower(Clans)='" + Clan + "'", "DFAX0067XLPKDW " + TruncateClan( Owner ) + " " + TruncateClan( Manager1 ) + " " + TruncateClan( Manager2 ) + "" ) );

                            }
                       }
             }
    }
[/edit]   
this part of cmds not working and no error
  local dos = SafeSelect( sDB, "SELECT Users FROM ClanUsers WHERE lower(Clans)='" + Clan.tolower() + "'" );
                                  if( ::mysql_num_rows( dos ) == 0 ){
                                   local result = mysql_fetch_assoc( dos );
                                    local Users =  Clans = result[ "Clans" ];
           // Create Managers And owner in database dont delete this "DFAX0067XLPKDW"
                                if ( Users ) mysql_query( sDB, format( "UPDATE ClanUsers SET Users='%s' WHERE lower(Clans)='" + Clan + "'", ""+Users+" " + TruncateClan( Owner ) + " " + TruncateClan( Manager1 ) + " " + TruncateClan( Manager2 ) + "" ) );
                    else mysql_query( sDB, format( "UPDATE ClanUsers SET Users='%s' WHERE lower(Clans)='" + Clan + "'", "DFAX0067XLPKDW " + TruncateClan( Owner ) + " " + TruncateClan( Manager1 ) + " " + TruncateClan( Manager2 ) + "" ) );
Title: Re: Commit Transaction error
Post by: KAKAN on Feb 22, 2017, 04:48 PM
change that if mysql num rows to check 1 instead of 0.
so, it should be:  if( mysql_num_rows( dos)  == 1) //Do shits here...  
off: Irs really shit to type from a phone :D
Title: Re: Commit Transaction error
Post by: Cool on Feb 22, 2017, 05:18 PM
Yep Its really hard to type from phone And Thanks its solved it Btw this small mistake waste my 6 hours before posting here i tried many times to solve it :P
I am not locking this topic if i got some problem i will post here because i dont want to create more threads
Title: Re: Commit Transaction error
Post by: Cool on Feb 22, 2017, 09:13 PM
No error and nothing its returning
else if ( cmd == "clanrank" )
        {
        if ( RegisteredClans() > 5 ) Message( "** Sorry, the server need min. 5 clans registed from a table of rankings" );
            else
            {
                local Limit = 6, a = 1;
                local q = ::mysql_query( sDB, "SELECT Clan, Kills, Deaths FROM ClanStats ORDER BY Kills DESC LIMIT " + Limit );
               
                if( ::mysql_num_rows( q ) == 1 ){
                local result = ::mysql_fetch_assoc( q );
                local Clan;
                while ( a < Limit )
                {
local Clan = Name = result[ "Name" ].tostring(), Kills = Kills = result[ "Kills" ].tofloat(), Deaths = Deaths = result[ "Deaths" ].tofloat(), Ratio;
                    if ( ( Kills > 0 ) && ( Deaths > 0 ) ) Ratio = Kills / Deaths;
                    else Ratio = 0;
                    Ratio = format ( "%.2f", Ratio );
 
                    if ( a == 1 ) Message( "** 5 Clan's with top kills:" );
                    if ( a == 1 ) (Clan) ? Message( ">> 1. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 1. Position Empty" );
                    else if ( a == 2 ) (Clan) ? Message( ">> 2. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 2. Position Empty" );
                    else if ( a == 3 ) (Clan) ? Message( ">> 3. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 3. Position Empty" );
                    else if ( a == 4 ) (Clan) ? Message( ">> 4. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 4. Position Empty" );
                    else if ( a == 5 ) (Clan) ? Message( ">> 5. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 5. Position Empty" );
                    a ++;
                }
        mysql_free_result( q );
            }             
        }
        }
Title: Re: Commit Transaction error
Post by: Thijn on Feb 22, 2017, 09:47 PM
If you're going to limit by 6, you're not going to always get 1 result. You'd get max 6.

So go over your code and fix it yourself.
Title: Re: Commit Transaction error
Post by: KAKAN on Feb 23, 2017, 05:34 AM
if ( a == 1 ) Message( "** 5 Clan's with top kills:" );
                    if ( a == 1 ) (Clan) ? Message( ">> 1. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 1. Position Empty" );
                    else if ( a == 2 ) (Clan) ? Message( ">> 2. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 2. Position Empty" );
                    else if ( a == 3 ) (Clan) ? Message( ">> 3. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 3. Position Empty" );
                    else if ( a == 4 ) (Clan) ? Message( ">> 4. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 4. Position Empty" );
                    else if ( a == 5 ) (Clan) ? Message( ">> 5. " + Clan + " with " + Kills + " kills - Ratio: " + Ratio ) : Message( "** 5. Position Empty" );
dafuq did I just see?
if( a >= 1 )
Message( Clan ? format( ">> %i . %s with %i Kills. Ratio: %.2f", a, Clan, Ratio ) : "**" + a + ". Position Empty." );
Title: Re: Commit Transaction error
Post by: Cool on Feb 23, 2017, 10:11 AM
What you want say @KAKAN :p
Title: Re: Commit Transaction error
Post by: KAKAN on Feb 23, 2017, 02:47 PM
the first if statement, it should check for < 5 and not > 5.
:edit: Test this one, bugs might come, was in a kind of hurry:-
else if( cmd == "clanrank" ){
    local top_ranks_limit = 5;
    if( RegisteredClans() < top_ranks_limit ) return PrivMessage( player, "The server needs atleast 5 registered clans to show a toprank." );
    local q = mysql_query( sDB, "SELECT Clan, Kills, Deaths FROM ClanStats ORDER BY Kills DESC LIMIT " + top_ranks_limit );
    if( mysql_num_rows( q ) == 0 ) return PrivMessage( player, "Something wrong happened and we couldn't complete the action." );
    local result, i = 1;
    Message("** 5 clans with top kills.");
    while( result = mysql_fetch_assoc( q ) ){
        local Clan = result["Clan"],
            Kills = result["Kills"],
            Deaths = result["Deaths"],
            Ratio = format( "%.2f", ( Kills > 0 && Deaths > 0 ) ? Kills/Deaths : 0.00 ),
            szMsg = Clan ? format( ">> %i . %s with %i Kills. Ratio: %.2f", i, Clan, Kills, Ratio ) : "**" + i + ". Position Empty.";
        Message( szMsg );
        i++;
    }

}
Title: Re: Commit Transaction error
Post by: Cool on Feb 23, 2017, 04:14 PM
Error: Float expected for the specified format
Title: Re: Commit Transaction error
Post by: KAKAN on Feb 23, 2017, 04:31 PM
Quote from: happymint2 on Feb 23, 2017, 04:14 PMError: Float expected for the specified format
which line? I can't just go and find out the error like that, you need to give us details :) And why not try solving it yourself?
Title: Re: Commit Transaction error
Post by: Cool on Feb 23, 2017, 04:33 PM
Quote from: KAKAN on Feb 23, 2017, 04:31 PM
Quote from: happymint2 on Feb 23, 2017, 04:14 PMError: Float expected for the specified format
which line? I can't just go and find out the error like that, you need to give us details :) And why not try solving it yourself?
Tried but cant solved it :P i never post error without trying to solve :P
error line local Clan = result["Clan"],Between i tried to solve it with :P
local Clan = result["Clan"].tostring(),
            Kills = result["Kills"].tofloat(),
            Deaths = result["Deaths"].tofloat(),
Title: Re: Commit Transaction error
Post by: KAKAN on Feb 23, 2017, 04:35 PM
Quote from: happymint2 on Feb 23, 2017, 04:33 PMBetween i tried to solve it with :P
local Clan = result["Clan"].tostring(),
            Kills = result["Kills"].tofloat(),
            Deaths = result["Deaths"].tofloat(),
Still the same error?
If so, I can't do anything. Its been a long time since I last touched Squirrel. Lets wait for someone else.
Title: Re: Commit Transaction error
Post by: Cool on Feb 23, 2017, 04:38 PM
Quote from: KAKAN on Feb 23, 2017, 04:35 PM
Quote from: happymint2 on Feb 23, 2017, 04:33 PMBetween i tried to solve it with :P
local Clan = result["Clan"].tostring(),
            Kills = result["Kills"].tofloat(),
            Deaths = result["Deaths"].tofloat(),
Still the same error?
If so, I can't do anything. Its been a long time since I last touched Squirrel. Lets wait for someone else.
Error is still same :P  i will wait for someone else reply :D
Title: Re: Commit Transaction error
Post by: DizzasTeR on Feb 24, 2017, 03:44 AM
local Clan = result["Clan"]
print( type( Clan ) );

Post the result
Title: Re: Commit Transaction error
Post by: Cool on Feb 24, 2017, 08:35 AM
Quote from: Doom_Kill3R on Feb 24, 2017, 03:44 AMlocal Clan = result["Clan"]
print( type( Clan ) );

Post the result
string
Title: Re: Commit Transaction error
Post by: DizzasTeR on Feb 24, 2017, 09:47 AM
Try
else if( cmd == "clanrank" ){
    local top_ranks_limit = 5;
    if( RegisteredClans() < top_ranks_limit ) return PrivMessage( player, "The server needs atleast 5 registered clans to show a toprank." );
    local q = mysql_query( sDB, "SELECT Clan, Kills, Deaths FROM ClanStats ORDER BY Kills DESC LIMIT " + top_ranks_limit );
    if( mysql_num_rows( q ) == 0 ) return PrivMessage( player, "Something wrong happened and we couldn't complete the action." );
    local result, nrows = mysql_num_rows( q ), i = 0;
    Message("** 5 clans with top kills.");
    while( i < nrows ){
result = mysql_fetch_assoc( q )
        local Clan = result["Clan"],
            Kills = result["Kills"],
            Deaths = result["Deaths"],
            Ratio = format( "%.2f", ( Kills > 0 && Deaths > 0 ) ? Kills/Deaths : 0.00 ),
            szMsg = Clan ? format( ">> %i . %s with %i Kills. Ratio: %.2f", i, Clan, Kills, Ratio ) : "**" + i + ". Position Empty.";
        Message( szMsg );
        i++;
    }

}
Title: Re: Commit Transaction error
Post by: Cool on Feb 24, 2017, 09:57 AM
Same Error
Title: Re: Commit Transaction error
Post by: DizzasTeR on Feb 24, 2017, 10:25 AM
You're telling the wrong error information / line then.
Title: Re: Commit Transaction error
Post by: Cool on Feb 24, 2017, 10:28 AM
Quote from: Doom_Kill3R on Feb 24, 2017, 10:25 AMYou're telling the wrong error information / line then.
Nope i told you the exact error and exact line
[Edit] @Doom_Kill3R  here is proof that i am not telling you wrong information http://imgur.com/a/1PPJQ
Title: Re: Commit Transaction error
Post by: vito on Feb 24, 2017, 10:58 AM
try to add ; to end of mysql_fetch_assoc( q )  (line 188)
Title: Re: Commit Transaction error
Post by: Cool on Feb 24, 2017, 11:00 AM
Quote from: vito on Feb 24, 2017, 10:58 AMtry to add ; to end of mysql_fetch_assoc( q )  (line 188)
There is no need of it btw i tried but same error
Title: Re: Commit Transaction error
Post by: DizzasTeR on Feb 24, 2017, 11:08 AM
The error is in your format( ) fields

:edit:Ratio = ( ( Kills > 0 && Deaths > 0 ) : Kills/Deaths : 0.000 )
If above still gives error then instead of using the ternary operator, check the Kills and Deaths with if statement and set the value of Ratio accordingly.
Title: Re: Commit Transaction error
Post by: KAKAN on Feb 24, 2017, 12:04 PM
Quote from: Doom_Kill3R on Feb 24, 2017, 11:08 AMIf above still gives error then instead of using the ternary operator, check the Kills and Deaths with if statement and set the value of Ratio accordingly.
I don't think it will make a difference somehow.
Title: Re: Commit Transaction error
Post by: EK.IceFlake on Feb 24, 2017, 12:11 PM
What does this print:
print(typeof Ratio);
Title: Re: Commit Transaction error
Post by: Cool on Feb 24, 2017, 12:14 PM
Quote from: EK.IceFlake on Feb 24, 2017, 12:11 PMWhat does this print:
print(typeof Ratio);
:O Ratio in string wtf