Skip to content

Commit

Permalink
Optimized the database exception to implement unique constraint error…
Browse files Browse the repository at this point in the history
… detection. (#7194)
  • Loading branch information
huangdijia authored Dec 11, 2024
1 parent 1455cc9 commit af2298f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/SQLiteConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Closure;
use Doctrine\DBAL\Driver\PDO\SQLite\Driver;
use Doctrine\DBAL\Driver\PDO\SQLite\Driver as DoctrineDriver;
use Exception;
use Hyperf\Database\Connection;
use Hyperf\Database\Query\Grammars\Grammar as HyperfQueryGrammar;
use Hyperf\Database\Query\Processors\Processor;
Expand Down Expand Up @@ -65,6 +66,16 @@ public function getSchemaBuilder(): SchemaBuilder
return new SQLiteBuilder($this);
}

/**
* Determine if the given database exception was caused by a unique constraint violation.
*
* @return bool
*/
protected function isUniqueConstraintError(Exception $exception)
{
return boolval(preg_match('#(column(s)? .* (is|are) not unique|UNIQUE constraint failed: .*)#i', $exception->getMessage()));
}

/**
* Get the default query grammar instance.
*
Expand Down

0 comments on commit af2298f

Please sign in to comment.