zend-db
zend-db copied to clipboard
Sqlite : Enabling Foreign Key Support
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');
}