Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine2 query validation and error handling
    primarykey
    data
    text
    <p>I'd like to use the <code>DBALException</code> the perform validation opposed to explicit checking of conditions.</p> <p>For example, deleting a parent record of which the child record holds a reference with 'delete restrict' will though an integrity constraint violation. This is current in MYSQL using the Doctrine2 DBAL with the mysql pdo driver.</p> <p>I want to be able to catch the DBALException (successful in doing so so far) and determine right then and there what happened.</p> <p>I am not asking for a code solution, but rather options or extensions to doctrine that handle and normalize the errors, a simple example would be:</p> <pre><code>catch(\Doctrine\DBAL\DBALException $e) { if($e-&gt;getPrevious()-&gt;getCode() == 23000) { // Integrity constraint violation /* * We know the type of problem; cannot delete parent record, * or cannot create duplicate record. * But which one is it? And which child table was complaining? */ } } </code></pre> <p>This is using the PDOException and the SQLSTATE error code to get a general idea of the problem, however it is not specific enough and although it is ODBC compliant, there is no guarantee will with work with every database.</p> <p>The reason I need this is that I cannot write validation code for every single possible reference that exists or will in the future exist for every entity in every delete procedure.</p> <p>CLOSED by self:</p> <p>Realized this is the wrong way to validate, do not use this concept outside of a testing environment.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload