Commit Transaction error

Started by Cool, Feb 21, 2017, 04:35 PM

Previous topic - Next topic

Cool

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

.

#1
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.
.

Cool

Now its not giving error but its not putting in db

jWeb

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.

KAKAN

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.
oh no

Cool

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

jWeb

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.

Cool

Queries working fine without START TRANSACTION  And Commit TRANSACTION but why not working with TRANSACTION

KAKAN

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
oh no

Thijn

Does your table type actually support transactions, i.e. InnoDB?

Cool

@Thijn db type = InnoDB   latin1_swedish_ci

Cool

help!!!!!
if i dont use Start Transaction any disadvantage

KAKAN

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
oh no

Cool

#13
[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 ) + "" ) );

KAKAN

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
oh no