title: Missing "Lock wait timeout exceeded" handling in magento's pdo_mysql adapter?
body: <p>If i compare the two Magento adapter classes <strong>Varien_Db_Adapter_Mysqli</strong> and <strong>Varien_Db_Adapter_Pdo_Mysql</strong> i can find some differences in the query exception handling of method <strong>raw_query</strong>.</p>
  
  <pre><code>&lt;?php
  
  class Varien_Db_Adapter_Mysqli extends Zend_Db_Adapter_Mysqli
  {
  
  //....
  
  /**
   * Run RAW Query
   *
   * @param string $sql
   * @return Zend_Db_Statement_Interface
   */
  public function raw_query($sql)
  {
      $timeoutMessage = 'SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded;      try restarting transaction';
      $tries = 0;
      do {
          $retry = false;
          try {
              $this-&gt;clear_result();
              $result = $this-&gt;getConnection()-&gt;query($sql);
              $this-&gt;clear_result();
          } catch (Exception $e) {
              if ($tries &lt; 10 &amp;&amp; $e-&gt;getMessage() == $timeoutMessage) {
                  $retry = true;
                  $tries++;
              } else {
                  throw $e;
              }
          }
      } while ($retry);
  
      return $result;
  }
  
  //....
  
  }
  </code></pre>
  
  <p>If i compare this with equal method in Varien_Db_Adapter_Pdo_Mysql i find another error handling. It checks not for timeouts, but for lost connections.</p>
  
  <pre><code>&lt;?php
  
  class Varien_Db_Adapter_Pdo_Mysql  extends Zend_Db_Adapter_Pdo_Mysql implements Varien_Db_Adapter_Interface
  {
  
  //....
  
  
  /**
   * Run RAW Query
   *
   * @param string $sql
   * @return Zend_Db_Statement_Interface
   * @throws PDOException
   */
  public function raw_query($sql)
  {
      $lostConnectionMessage = 'SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query';
      $tries = 0;
      do {
          $retry = false;
          try {
              $result = $this-&gt;query($sql);
          } catch (Exception $e) {
              // Convert to PDOException to maintain backwards compatibility with usage of MySQL adapter
              if ($e instanceof Zend_Db_Statement_Exception) {
                  $e = $e-&gt;getPrevious();
                  if (!($e instanceof PDOException)) {
                      $e = new PDOException($e-&gt;getMessage(), $e-&gt;getCode());
                  }
              }
              // Check to reconnect
              if ($tries &lt; 10 &amp;&amp; $e-&gt;getMessage() == $lostConnectionMessage) {
                  $retry = true;
                  $tries++;
              } else {
                  throw $e;
              }
          }
      } while ($retry);
  
      return $result;
  }
  
  //....
  
  }
  </code></pre>
  
  <p>Is that correct? Would it not be better to check both failure cases?</p>
  
  <p>Example:</p>
  
  <pre><code>/**
   * Run RAW Query
   *
   * @param string $sql
   * @return Zend_Db_Statement_Interface
   * @throws PDOException
   */
  public function raw_query($sql)
  {
      $lostConnectionMessages = array(
          'SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query',
          'SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction',
      );
      $tries = 0;
      do {
          $retry = false;
          try {
              $result = $this-&gt;query($sql);
          } catch (Exception $e) {
              // Convert to PDOException to maintain backwards compatibility with usage of MySQL adapter
              if ($e instanceof Zend_Db_Statement_Exception) {
                  $e = $e-&gt;getPrevious();
                  if (!($e instanceof PDOException)) {
                      $e = new PDOException($e-&gt;getMessage(), $e-&gt;getCode());
                  }
              }
              // Check to reconnect
              if ($tries &lt; 10 &amp;&amp; in_array($e-&gt;getMessage(), $lostConnectionMessages)) {
                  $retry = true;
                  $tries++;
              } else {
                  throw $e;
              }
          }
      } while ($retry);
  
      return $result;
  }
  </code></pre>