modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-27 16:57:34 +04:00
parent f3af19406b
commit 2f6c120758
3 changed files with 19 additions and 6 deletions

View File

@ -150,9 +150,9 @@ class Capacitor implements ITransactor {
return $this->storage->_all($this->channel, $filter); 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(); $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 { function delete($filter, $func=null, ?array $args=null): int {

View File

@ -438,9 +438,10 @@ EOT;
* si la fonction retourne un tableau, il est utilisé pour mettre à jour la * si la fonction retourne un tableau, il est utilisé pour mettre à jour la
* ligne * ligne
* *
* @param int $updated reçoit le nombre de lignes mises à jour
* @return int le nombre de lignes parcourues * @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); $this->_create($channel);
if ($func === null) $func = "->onEach"; if ($func === null) $func = "->onEach";
func::ensure_func($func, $channel, $args); func::ensure_func($func, $channel, $args);
@ -449,6 +450,7 @@ EOT;
$tableName = $channel->getTableName(); $tableName = $channel->getTableName();
$manageTransactions = $channel->isManageTransactions(); $manageTransactions = $channel->isManageTransactions();
$count = 0; $count = 0;
$updated = 0;
if ($manageTransactions) { if ($manageTransactions) {
$commited = false; $commited = false;
$db->beginTransaction(); $db->beginTransaction();
@ -463,7 +465,7 @@ EOT;
if (!array_key_exists("modified_", $updates)) { if (!array_key_exists("modified_", $updates)) {
$updates["modified_"] = date("Y-m-d H:i:s"); $updates["modified_"] = date("Y-m-d H:i:s");
} }
$db->exec([ $updated += $db->exec([
"update", "update",
"table" => $tableName, "table" => $tableName,
"values" => $this->serialize($channel, $updates), "values" => $this->serialize($channel, $updates),
@ -490,8 +492,8 @@ EOT;
} }
} }
function each(?string $channel, $filter, $func=null, ?array $args=null): int { function each(?string $channel, $filter, $func=null, ?array $args=null, ?int &$updated=null): int {
return $this->_each($this->getChannel($channel), $filter, $func, $args); return $this->_each($this->getChannel($channel), $filter, $func, $args, $updated);
} }
/** /**

View File

@ -39,6 +39,16 @@ class Sqlite implements IDatabase {
$sqlite->db->enableExceptions(true); $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 { static function config_enableWalIfAllowed(self $sqlite): void {
if ($sqlite->isWalAllowed()) { if ($sqlite->isWalAllowed()) {
$sqlite->db->exec("PRAGMA journal_mode=WAL"); $sqlite->db->exec("PRAGMA journal_mode=WAL");
@ -49,6 +59,7 @@ class Sqlite implements IDatabase {
const CONFIG = [ const CONFIG = [
[self::class, "config_enableExceptions"], [self::class, "config_enableExceptions"],
[self::class, "config_busyTimeout"],
[self::class, "config_enableWalIfAllowed"], [self::class, "config_enableWalIfAllowed"],
]; ];