Skip to content

Commit

Permalink
feat: add SQLite3 config synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Sep 25, 2024
1 parent a6374de commit a800f5c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Config/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Database extends Config
// 'failover' => [],
// 'foreignKeys' => true,
// 'busyTimeout' => 1000,
// 'synchronous' => null,
// 'dateFormat' => [
// 'date' => 'Y-m-d',
// 'datetime' => 'Y-m-d H:i:s',
Expand Down
13 changes: 13 additions & 0 deletions system/Database/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class Connection extends BaseConnection
*/
protected $busyTimeout;

/**
* The setting of the "synchronous" flag
*
* @var int|null flag
*
* @see https://www.sqlite.org/pragma.html#pragma_synchronous
*/
protected $synchronous;

/**
* @return void
*/
Expand All @@ -70,6 +79,10 @@ public function initialize()
if (is_int($this->busyTimeout)) {
$this->connID->busyTimeout($this->busyTimeout);
}

if (is_int($this->synchronous)) {
$this->connID->exec('PRAGMA synchronous = ' . $this->synchronous);
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ Others
- Added a new configuration ``foundRows`` for MySQLi to use ``MYSQLI_CLIENT_FOUND_ROWS``.
- Added the ``BaseConnection::resetTransStatus()`` method to reset the transaction
status. See :ref:`transactions-resetting-transaction-status` for details.
- SQLite3 has a new Config item ``synchronous`` to adjust how strict SQLite is at flushing
to disk during transactions. Modifying this can be useful if we use journal mode set to ``WAL``.

Model
=====
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/database/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ Description of Values
See `SQLite documentation <https://www.sqlite.org/pragma.html#pragma_foreign_keys>`_.
To enforce Foreign Key constraint, set this config item to true.
**busyTimeout** (``SQLite3`` only) milliseconds (int) - Sleeps for a specified amount of time when a table is locked.
**synchronous** (``SQLite3`` only) flag (int) - How strict SQLite will be at flushing to disk during transactions.
Use `null` to stay with the default setting. This can be used since v4.6.0.
**numberNative** (``MySQLi`` only) true/false (boolean) - Whether to enable MYSQLI_OPT_INT_AND_FLOAT_NATIVE.
**foundRows** (``MySQLi`` only) true/false (boolean) - Whether to enable MYSQLI_CLIENT_FOUND_ROWS.
**dateFormat** The default date/time formats as PHP's `DateTime format`_.
Expand Down

0 comments on commit a800f5c

Please sign in to comment.