mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Show a proper error message table when encountering an invalid regex statement on SQLite
This is related to #289
This commit is contained in:
parent
2c33b381c1
commit
b0ab43c39a
3 changed files with 99 additions and 13 deletions
|
@ -20,6 +20,7 @@
|
|||
|
||||
namespace App\Doctrine;
|
||||
|
||||
use App\Exceptions\InvalidRegexException;
|
||||
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
|
||||
use Doctrine\DBAL\Event\ConnectionEventArgs;
|
||||
use Doctrine\DBAL\Events;
|
||||
|
@ -43,7 +44,11 @@ class SQLiteRegexExtension implements EventSubscriberInterface
|
|||
//Ensure that the function really exists on the connection, as it is marked as experimental according to PHP documentation
|
||||
if($native_connection instanceof \PDO && method_exists($native_connection, 'sqliteCreateFunction' )) {
|
||||
$native_connection->sqliteCreateFunction('REGEXP', function ($pattern, $value) {
|
||||
return (false !== mb_ereg($pattern, $value)) ? 1 : 0;
|
||||
try {
|
||||
return (false !== mb_ereg($pattern, $value)) ? 1 : 0;
|
||||
} catch (\ErrorException $e) {
|
||||
throw InvalidRegexException::fromMBRegexError($e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue