Skip to content

Commit

Permalink
Merge pull request #6050 from kenjis/fix-sqlite-foreign_keys
Browse files Browse the repository at this point in the history
fix: add config for SQLite3 Foreign Keys
  • Loading branch information
kenjis authored May 30, 2022
2 parents c605069 + 214f2d9 commit 4cf4f0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 14 additions & 0 deletions system/Database/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ class Connection extends BaseConnection
*/
public $escapeChar = '`';

/**
* @var bool Enable Foreign Key constraint or not
*/
protected $foreignKeys = false;

public function initialize()
{
parent::initialize();

if ($this->foreignKeys) {
$this->enableForeignKeyChecks();
}
}

/**
* Connect to the database.
*
Expand Down
10 changes: 7 additions & 3 deletions user_guide_src/source/database/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ default group's configuration settings. The values should be name following this
Explanation of Values:
**********************

============== ===========================================================================================================
=============== ===========================================================================================================
Name Config Description
============== ===========================================================================================================
=============== ===========================================================================================================
**dsn** The DSN connect string (an all-in-one configuration sequence).
**hostname** The hostname of your database server. Often this is 'localhost'.
**username** The username used to connect to the database.
Expand Down Expand Up @@ -140,8 +140,12 @@ Explanation of Values:
**port** The database port number. To use this value you have to add a line to the database config array.

.. literalinclude:: configuration/009.php
**foreignKeys** true/false (boolean) - Whether or not to enable Foreign Key constraint (``SQLite3`` only).

============== ===========================================================================================================
.. important:: SQLite3 Foreign Key constraint is disabled by default.
See `SQLite documentation <https://www.sqlite.org/pragma.html#pragma_foreign_keys>`_.
To enforce Foreign Key constraint, set this config item to true.
=============== ===========================================================================================================

.. note:: Depending on what database platform you are using (MySQL, PostgreSQL,
etc.) not all values will be needed. For example, when using SQLite you
Expand Down

0 comments on commit 4cf4f0f

Please sign in to comment.