title: MySQL Atomic UPDATE in InnoDB vs MyISAM
body: <p>Is this "compare and swap" statement always atomic regardless of engine (e.g. InnoDB or MyISAM)? :</p>
  
  <pre><code>UPDATE tbl_name SET locked=1 WHERE id=ID AND locked &lt;&gt; 1;
  </code></pre>
  
  <p>I ask this because I intend to use this statement to do pseudo row-level locking that is compatible with both transactional and non-transactional database tables.</p>
  
  <p>This is the method that is <a href="http://dev.mysql.com/doc/refman/5.6/en/ansi-diff-transactions.html" rel="nofollow">recommended for MyISAM</a>, but I am uncertain as to whether this works for InnoDB since the documentation suggests using transactions instead.</p>