Db: add option to enable foreign keys support on SQLite backend

This commit is contained in:
Benjamin Renard 2024-09-21 10:13:39 +02:00
parent 3b9bda3195
commit da317d85d0
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -54,6 +54,7 @@ class Db {
'datetime_format' => '%Y-%m-%d %H:%M:%S',
'locale_time' => null,
'auto_connect' => true,
'sqlite_foreign_keys_support' => true,
),
);
@ -87,6 +88,15 @@ class Db {
static :: $fpdo -> debug = array(static :: class, 'debug_query');
Log :: trace("DB connection established (DSN: '%s')", $dsn);
// Enable SQLite foreign keys support
if (
self :: is_sqlite()
&& App::get(static :: $config_prefix.".sqlite_foreign_keys_support")
) {
Log :: trace("Enable SQLite foreign keys support");
self :: $pdo -> exec("PRAGMA foreign_keys = ON;");
}
}
catch(Exception $e) {
Log :: error("Fail to connect to DB (DSN : '%s') : %s", $dsn, $e->getMessage());