title: Conditionally commit transactions on MySQL without stored procedure
body: <p>I found <a href="http://dev.mysql.com/doc/refman/5.5/en/flow-control-constructs.html" rel="nofollow">their document</a> said that the IF ELSE END IF is only supported in stored procedure. </p>
  
  <pre><code>MySQL supports the IF, CASE, ITERATE, LEAVE LOOP, WHILE, and REPEAT constructs for flow control within **stored programs**.
  </code></pre>
  
  <p>We tried and seem that it is not supported in running batch statements via cli.</p>
  
  <p>To optimize the performance and reduce round trip, reading the ROW_COUNT() by an application is not considered. The best if mysql can take it in the speed of light.</p>
  
  <p>How do I make it work without using any additional stored procedure?  We tried to use WHERE ROW_COUNT() on every UPDATE to suspend the chain of updates if any one goes wrong; but it wont stop the transaction begin replicated even if nothing should be modified.</p>
  
  <p>EDIT:</p>
  
  <p>In short, how do I do </p>
  
  <pre><code>START TRANSACTION
  UPDATE `table_a` SET a=1 WHERE id=1 AND addition=2;
  UPDATE `table_b` SET a=1 WHERE id=1 AND another_rule=3;
  IF UPDATE_COUNT() = 1 
  THEN 
    COMMIT
  ELSE
    ROLLBACK
  END IF
  </code></pre>
  
  <p>In a crond schedule, without using stored procedure.</p>