<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="condition-handling-restrictions">
      </a>
      15.6.8 Restrictions on Condition Handling
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045175210880">
  </a>
  <a class="indexterm" name="idm46045175209392">
  </a>
  <p>
   <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
    <code class="literal">
     SIGNAL
    </code>
   </a>
   ,
   <a class="link" href="resignal.html" title="15.6.7.4 RESIGNAL Statement">
    <code class="literal">
     RESIGNAL
    </code>
   </a>
   , and
   <a class="link" href="get-diagnostics.html" title="15.6.7.3 GET DIAGNOSTICS Statement">
    <code class="literal">
     GET DIAGNOSTICS
    </code>
   </a>
   are not permissible
      as prepared statements. For example, this statement is invalid:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa88890062"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">PREPARE</span> stmt1 <span class="token keyword">FROM</span> <span class="token string">'SIGNAL SQLSTATE "02000"'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   <code class="literal">
    SQLSTATE
   </code>
   values in class
   <code class="literal">
    '04'
   </code>
   are not treated specially. They are
      handled the same as other exceptions.
  </p>
  <p>
   In standard SQL, the first condition relates to the
   <code class="literal">
    SQLSTATE
   </code>
   value returned for the previous SQL
      statement. In MySQL, this is not guaranteed, so to get the main
      error, you cannot do this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa78715522"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">GET</span> <span class="token keyword">DIAGNOSTICS</span> <span class="token keyword">CONDITION</span> <span class="token number">1</span> <span class="token variable">@errno</span> <span class="token operator">=</span> <span class="token keyword">MYSQL_ERRNO</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   Instead, do this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa3382697"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">GET</span> <span class="token keyword">DIAGNOSTICS</span> <span class="token variable">@cno</span> <span class="token operator">=</span> <span class="token keyword">NUMBER</span><span class="token punctuation">;</span>
<span class="token keyword">GET</span> <span class="token keyword">DIAGNOSTICS</span> <span class="token keyword">CONDITION</span> <span class="token variable">@cno</span> <span class="token variable">@errno</span> <span class="token operator">=</span> <span class="token keyword">MYSQL_ERRNO</span><span class="token punctuation">;</span></code></pre>
  </div>
 </div>
 <br/>
</div>
