File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -466,8 +466,14 @@ public static function insert(Model &$object) {
466466 implode (', ' , $ placeholders )
467467 );
468468
469- $ connection ->prepare ($ sql )->execute ($ params );
470-
469+ try {
470+ $ connection ->prepare ($ sql )->execute ($ params );
471+ } catch (\PDOException $ e ){
472+ if ($ e ->getCode () === DB \Exception::SQLSTATE_DUPLICATE_KEY ){
473+ throw new DuplicateKeyException ($ e ->getCode (), $ e ->getMessage ());
474+ }
475+ throw $ e ;
476+ }
471477 $ primary_key = $ object ::_getPrimaryKey ();
472478 if ($ primary_key !== null && count ($ primary_key ) === 1 ) {
473479 $ column = current ($ primary_key );
Original file line number Diff line number Diff line change 44
55use Wave ;
66
7- class Exception extends Wave \Exception {
7+ class Exception extends Wave \Exception
8+ {
9+ const SQLSTATE_DUPLICATE_KEY = 1062 ;
810}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Wave ;
4+
5+ class DuplicateKeyException extends \Wave \DB \Exception
6+ {
7+ public function __construct ($ message , $ code = null )
8+ {
9+ parent ::__construct ($ message , $ code );
10+ }
11+ }
You can’t perform that action at this time.
0 commit comments