Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,14 @@
*/
'sqlite.journal_mode' => 'DELETE',

/**
* Number of milliseconds a SQLite3 connection will wait for a lock held by
* another connection to clear before giving up with a "database is locked"
* error. See https://www.sqlite.org/pragma.html#pragma_busy_timeout for
* more details.
*/
'sqlite.busy_timeout' => 30000,

/**
* During setup, if requirements are met (see below), this setting is set to true
* to enable MySQL to handle 4-byte characters instead of 3-byte characters.
Expand Down
4 changes: 3 additions & 1 deletion lib/private/DB/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ public function getConnection(string $type, array $additionalConnectionParams):

case 'sqlite3':
$journalMode = $connectionParams['sqlite.journal_mode'];
$busyTimeout = $connectionParams['sqlite.busy_timeout'];
$connectionParams['platform'] = new OCSqlitePlatform();
$eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode));
$eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode, $busyTimeout));
break;
}
$configuration = new Configuration();
Expand Down Expand Up @@ -206,6 +207,7 @@ public function createConnectionParams(string $configPrefix = '', array $additio

$connectionParams['tablePrefix'] = $this->config->getValue('dbtableprefix', self::DEFAULT_DBTABLEPREFIX);
$connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL');
$connectionParams['sqlite.busy_timeout'] = $this->config->getValue('sqlite.busy_timeout', 30000);

//additional driver options, eg. for mysql ssl
$driverOptions = $this->config->getValue($configPrefix . 'dbdriveroptions', $this->config->getValue('dbdriveroptions', null));
Expand Down
2 changes: 2 additions & 0 deletions lib/private/DB/SQLiteSessionInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SQLiteSessionInit implements EventSubscriber {
public function __construct(
private readonly bool $caseSensitiveLike,
private readonly string $journalMode,
private readonly int $busyTimeout,
) {
}

Expand All @@ -27,6 +28,7 @@ public function postConnect(ConnectionEventArgs $args): void {
$args->getConnection()->executeStatement('PRAGMA case_sensitive_like = ' . $sensitive);
$args->getConnection()->executeStatement('PRAGMA journal_mode = ' . $this->journalMode);
$args->getConnection()->executeStatement('PRAGMA foreign_keys = true');
$args->getConnection()->executeStatement('PRAGMA busy_timeout = ' . $this->busyTimeout);
/** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */
$connection = $args->getConnection()->getWrappedConnection();
$pdo = $connection->getWrappedConnection();
Expand Down
31 changes: 31 additions & 0 deletions tests/lib/DB/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,35 @@ public function testPgsqlSslConnection(): void {
$this->assertEquals('client.key', $params['sslkey']);
$this->assertEquals('client.crl', $params['sslcrl']);
}

public function testSqliteBusyTimeoutDefault(): void {
/** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject $config */
$config = $this->createMock(SystemConfig::class);
$config->method('getValue')
->willReturnCallback(fn ($key, $default) => match ($key) {
'dbtype' => 'sqlite3',
default => $default,
});
$factory = new ConnectionFactory($config);

$params = $factory->createConnectionParams();

$this->assertSame(30000, $params['sqlite.busy_timeout']);
}

public function testSqliteBusyTimeoutConfigured(): void {
/** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject $config */
$config = $this->createMock(SystemConfig::class);
$config->method('getValue')
->willReturnCallback(fn ($key, $default) => match ($key) {
'dbtype' => 'sqlite3',
'sqlite.busy_timeout' => 5000,
default => $default,
});
$factory = new ConnectionFactory($config);

$params = $factory->createConnectionParams();

$this->assertSame(5000, $params['sqlite.busy_timeout']);
}
}
Loading