Skip to content

Commit a800f5c

Browse files
committed
feat: add SQLite3 config synchronous
1 parent a6374de commit a800f5c

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

app/Config/Database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Database extends Config
6565
// 'failover' => [],
6666
// 'foreignKeys' => true,
6767
// 'busyTimeout' => 1000,
68+
// 'synchronous' => null,
6869
// 'dateFormat' => [
6970
// 'date' => 'Y-m-d',
7071
// 'datetime' => 'Y-m-d H:i:s',

system/Database/SQLite3/Connection.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ class Connection extends BaseConnection
5656
*/
5757
protected $busyTimeout;
5858

59+
/**
60+
* The setting of the "synchronous" flag
61+
*
62+
* @var int|null flag
63+
*
64+
* @see https://www.sqlite.org/pragma.html#pragma_synchronous
65+
*/
66+
protected $synchronous;
67+
5968
/**
6069
* @return void
6170
*/
@@ -70,6 +79,10 @@ public function initialize()
7079
if (is_int($this->busyTimeout)) {
7180
$this->connID->busyTimeout($this->busyTimeout);
7281
}
82+
83+
if (is_int($this->synchronous)) {
84+
$this->connID->exec('PRAGMA synchronous = ' . $this->synchronous);
85+
}
7386
}
7487

7588
/**

user_guide_src/source/changelogs/v4.6.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ Others
208208
- Added a new configuration ``foundRows`` for MySQLi to use ``MYSQLI_CLIENT_FOUND_ROWS``.
209209
- Added the ``BaseConnection::resetTransStatus()`` method to reset the transaction
210210
status. See :ref:`transactions-resetting-transaction-status` for details.
211+
- SQLite3 has a new Config item ``synchronous`` to adjust how strict SQLite is at flushing
212+
to disk during transactions. Modifying this can be useful if we use journal mode set to ``WAL``.
211213

212214
Model
213215
=====

user_guide_src/source/database/configuration.rst

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

0 commit comments

Comments
 (0)