zendframework/zend-db

Sqlite : Enabling Foreign Key Support

Opened this issue · 1 comments

From Sqlite documentation :

Foreign key constraints are disabled by default (for backwards compatibility), so must be enabled separately for each database connection. (Note, however, that future releases of SQLite might change so that foreign key constraints enabled by default. Careful developers will not make any assumptions about whether or not foreign keys are enabled by default but will instead enable or disable them as necessary.)

Using it, it's a pain to make it ' for each database connection ' !
So is it possible to activate it by default or adding an option for executing ' pragmas ' directive on connection ??

For the moment i've patched localy the file :
zend-db/src/Adapter/Driver/Pdo/Connection.php
From line 255 :

if (isset($charset) && $pdoDriver == 'pgsql') {
   $this->resource->exec('SET NAMES ' . $this->resource->quote($charset));
}
//---------------------------------------------------------------------------------------------------------
//   Sqlite : Enabling Foreign Key Support 
else if ($pdoDriver == 'sqlite' ) {
    $this->resource->exec('PRAGMA foreign_keys = on');
}

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#144.