Skip to content

Commit b9a2b68

Browse files
committed
feat: add SQLite3 Config busyTimeout
1 parent e2c4a3b commit b9a2b68

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

app/Config/Database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Database extends Config
6767
'failover' => [],
6868
'port' => 3306,
6969
'foreignKeys' => true,
70+
'busyTimeout' => 1000,
7071
];
7172

7273
public function __construct()

system/Database/SQLite3/Connection.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,26 @@ class Connection extends BaseConnection
4545
*/
4646
protected $foreignKeys = false;
4747

48+
/**
49+
* The milliseconds to sleep
50+
*
51+
* @var int|null milliseconds
52+
*
53+
* @see https://www.php.net/manual/en/sqlite3.busytimeout
54+
*/
55+
protected $busyTimeout;
56+
4857
public function initialize()
4958
{
5059
parent::initialize();
5160

5261
if ($this->foreignKeys) {
5362
$this->enableForeignKeyChecks();
5463
}
64+
65+
if (is_int($this->busyTimeout)) {
66+
$this->simpleQuery('PRAGMA busy_timeout=' . $this->busyTimeout);
67+
}
5568
}
5669

5770
/**

user_guide_src/source/database/configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Explanation of Values:
150150
.. important:: SQLite3 Foreign Key constraint is disabled by default.
151151
See `SQLite documentation <https://www.sqlite.org/pragma.html#pragma_foreign_keys>`_.
152152
To enforce Foreign Key constraint, set this config item to true.
153+
**busyTimeout** milliseconds (int) - Sleeps for a specified amount of time when a table is locked (``SQLite3`` only).
153154
=============== ===========================================================================================================
154155

155156
.. note:: Depending on what database platform you are using (MySQL, PostgreSQL,

0 commit comments

Comments
 (0)