From 2f6c1207583faf8ab7ae01a8ffcfd123be43cd9d Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 27 Jun 2024 16:57:34 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- src/db/Capacitor.php | 4 ++-- src/db/CapacitorStorage.php | 10 ++++++---- src/db/sqlite/Sqlite.php | 11 +++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/db/Capacitor.php b/src/db/Capacitor.php index 6341741..a5c2c7f 100644 --- a/src/db/Capacitor.php +++ b/src/db/Capacitor.php @@ -150,9 +150,9 @@ class Capacitor implements ITransactor { return $this->storage->_all($this->channel, $filter); } - function each($filter, $func=null, ?array $args=null): int { + function each($filter, $func=null, ?array $args=null, ?int &$updated=null): int { $this->beginTransaction(); - return $this->storage->_each($this->channel, $filter, $func, $args); + return $this->storage->_each($this->channel, $filter, $func, $args, $updated); } function delete($filter, $func=null, ?array $args=null): int { diff --git a/src/db/CapacitorStorage.php b/src/db/CapacitorStorage.php index 41786d6..2d28308 100644 --- a/src/db/CapacitorStorage.php +++ b/src/db/CapacitorStorage.php @@ -438,9 +438,10 @@ EOT; * si la fonction retourne un tableau, il est utilisé pour mettre à jour la * ligne * + * @param int $updated reçoit le nombre de lignes mises à jour * @return int le nombre de lignes parcourues */ - function _each(CapacitorChannel $channel, $filter, $func, ?array $args): int { + function _each(CapacitorChannel $channel, $filter, $func, ?array $args, ?int &$updated=null): int { $this->_create($channel); if ($func === null) $func = "->onEach"; func::ensure_func($func, $channel, $args); @@ -449,6 +450,7 @@ EOT; $tableName = $channel->getTableName(); $manageTransactions = $channel->isManageTransactions(); $count = 0; + $updated = 0; if ($manageTransactions) { $commited = false; $db->beginTransaction(); @@ -463,7 +465,7 @@ EOT; if (!array_key_exists("modified_", $updates)) { $updates["modified_"] = date("Y-m-d H:i:s"); } - $db->exec([ + $updated += $db->exec([ "update", "table" => $tableName, "values" => $this->serialize($channel, $updates), @@ -490,8 +492,8 @@ EOT; } } - function each(?string $channel, $filter, $func=null, ?array $args=null): int { - return $this->_each($this->getChannel($channel), $filter, $func, $args); + function each(?string $channel, $filter, $func=null, ?array $args=null, ?int &$updated=null): int { + return $this->_each($this->getChannel($channel), $filter, $func, $args, $updated); } /** diff --git a/src/db/sqlite/Sqlite.php b/src/db/sqlite/Sqlite.php index dc8266f..63bd943 100644 --- a/src/db/sqlite/Sqlite.php +++ b/src/db/sqlite/Sqlite.php @@ -39,6 +39,16 @@ class Sqlite implements IDatabase { $sqlite->db->enableExceptions(true); } + /** + * @var int temps maximum à attendre que la base soit accessible si elle est + * verrouillée + */ + const BUSY_TIMEOUT = 30 * 1000; + + static function config_busyTimeout(self $sqlite): void { + $sqlite->db->busyTimeout(static::BUSY_TIMEOUT); + } + static function config_enableWalIfAllowed(self $sqlite): void { if ($sqlite->isWalAllowed()) { $sqlite->db->exec("PRAGMA journal_mode=WAL"); @@ -49,6 +59,7 @@ class Sqlite implements IDatabase { const CONFIG = [ [self::class, "config_enableExceptions"], + [self::class, "config_busyTimeout"], [self::class, "config_enableWalIfAllowed"], ];