title: mysql update updating all user rows in table
body: <p><strong>Problem:</strong>
  I have a mySql stored procedure which runs the following UPDATE:</p>
  
  <pre><code>IF target = 'sup' THEN
      UPDATE my_table SET deleted = 1, last_updated = lastUpdate WHERE id = ID AND user_id = accountID;
  END IF;
  </code></pre>
  
  <p>The input parameters are:</p>
  
  <pre><code>(IN ID BIGINT, IN lastUpdate DATETIME, IN target VARCHAR(3), IN accountID BIGINT)
  </code></pre>
  
  <p>When this sproc is called, mySql updates all of the rows in the table for the user_id and seems to ignore the id in the WHERE clause.</p>
  
  <p><strong>Background:</strong>
  A mobile app makes an ajax json call to a .NET webservice, which then calls the mySql sproc.</p>
  
  <p>The json call is like:</p>
  
  <pre><code>{"id":["5","6","10"],"lastUpdated":"2014-07-19 22:28:53","target":"sup","accountID":"309"}
  </code></pre>
  
  <p>At the .net webservice, it converts each id entry to Int64 and sends it to the mySql sproc:</p>
  
  <pre><code>For Each checkedID As String In id
          cmd.Parameters.AddWithValue("@ID", CType(checkedID, Int64)).Direction = ParameterDirection.Input
          cmd.Parameters.AddWithValue("@lastUpdate", dte).Direction = ParameterDirection.Input
          cmd.Parameters.AddWithValue("@target", target).Direction = ParameterDirection.Input
          cmd.Parameters.AddWithValue("@accountID", accountID).Direction = ParameterDirection.Input
          cmd.ExecuteNonQuery()
          cmd.Parameters.Clear()
      Next
  </code></pre>
  
  <p><strong>Research and fix attempts:</strong>
  Lots of search</p>
  
  <p>Using MySQL Workbench; running the SQL directly correctly updates just the targeted row:</p>
  
  <pre><code>UPDATE my_table SET deleted = 1, last_updated = '1970-01-01 10:10:10' WHERE id = "7" AND user_id = 309;
  </code></pre>
  
  <p>However, if I call the sproc from within MySQL Workbench, it still updates all of the rows for the targeted user:</p>
  
  <pre><code>CALL `my_sproc`(7, '1990-01-01 10:10:10', 'sup', 309);
  </code></pre>
  
  <p>I cannot see anything wrong with the sproc, unless I've just looked at it for too long. The mobile app has got close to 100 MySQL sprocs, and this is the only one causing an issue.</p>
  
  <p>I am stumped.</p>