From 251ab9534b7434c53d6ff935333598626bb4c6ed Mon Sep 17 00:00:00 2001 From: grimpirate Date: Wed, 16 Oct 2024 02:02:01 -0400 Subject: [PATCH] now() throws error when using SQLite3 Use config instead of settings Use CURRENT_TIMESTAMP Strict parameter type Lint fix Lint fix Removed unneeded functions/variables --- system/Session/Handlers/DatabaseHandler.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system/Session/Handlers/DatabaseHandler.php b/system/Session/Handlers/DatabaseHandler.php index 2d1d2fbbe97e..ae6be78b9b59 100644 --- a/system/Session/Handlers/DatabaseHandler.php +++ b/system/Session/Handlers/DatabaseHandler.php @@ -196,7 +196,7 @@ public function write($id, $data): bool 'data' => $this->prepareData($data), ]; - if (! $this->db->table($this->table)->set('timestamp', 'now()', false)->insert($insertData)) { + if (! $this->db->table($this->table)->set('timestamp', 'CURRENT_TIMESTAMP', false)->insert($insertData)) { return $this->fail(); } @@ -218,7 +218,7 @@ public function write($id, $data): bool $updateData['data'] = $this->prepareData($data); } - if (! $builder->set('timestamp', 'now()', false)->update($updateData)) { + if (! $builder->set('timestamp', 'CURRENT_TIMESTAMP', false)->update($updateData)) { return $this->fail(); } @@ -282,12 +282,12 @@ public function destroy($id): bool #[ReturnTypeWillChange] public function gc($max_lifetime) { - $separator = ' '; - $interval = implode($separator, ['', "{$max_lifetime} second", '']); - return $this->db->table($this->table)->where( 'timestamp <', - "now() - INTERVAL {$interval}", + match (config(Database::class)->{$this->DBGroup}['DBDriver']) { + 'SQLite3' => "datetime('now', '-{$max_lifetime} second')", + default => "now() - INTERVAL {$max_lifetime} second", + }, false )->delete() ? 1 : $this->fail(); }