diff options
| author | Damien Regad <dregad@mantisbt.org> | 2025-07-21 13:30:58 +0200 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2025-08-18 18:52:58 +0200 |
| commit | 2664692f850daffd91113a4b70538e0a0dc7c641 (patch) | |
| tree | 1eafc8bf69f8f001f9d30c1a9bb20b56ab8a6b05 /drivers/adodb-sqlite3.inc.php | |
| parent | 6103ab98519fe180bcd7ea9637ed544ce3bc2177 (diff) | |
| download | adodb-2664692f850daffd91113a4b70538e0a0dc7c641.tar.gz adodb-2664692f850daffd91113a4b70538e0a0dc7c641.tar.bz2 adodb-2664692f850daffd91113a4b70538e0a0dc7c641.zip | |
sqlite: Fix SQLDate() method
ADOdb date/time library was removed in #970. Follow-up PR #1002 replaced
legacy adodb_date()/adodb_date2() calls through custom functions, by
native strftime().
That introduced a regression in SQLDate() behavior, as the date formats
changed from PHP-style to strftime (e.g. `Ymd` -> `%Y%m%d`).
This commit partially reverts 4700171afa6c5f939e8d04b079331e207dea22ca
and reintroduces the createFunction() call with a closure
providing behavior compatible with the legacy adodb_date2() function.
It also removes the now-useless test script that was added as part of
PR #1002.
Diffstat (limited to 'drivers/adodb-sqlite3.inc.php')
| -rw-r--r-- | drivers/adodb-sqlite3.inc.php | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/drivers/adodb-sqlite3.inc.php b/drivers/adodb-sqlite3.inc.php index e8fe433f..be4fac39 100644 --- a/drivers/adodb-sqlite3.inc.php +++ b/drivers/adodb-sqlite3.inc.php @@ -413,19 +413,7 @@ class ADODB_sqlite3 extends ADOConnection { $fmt = str_replace($fromChars,$toChars,$fmt); $fmt = $this->qstr($fmt); - return ($col) ? "strftime($fmt,$col)" : "strftime($fmt)"; - } - - /** - * Creates any custom functions for SQLite - * - * This function is a placeholder for creating custom SQLite functions. - * Currently, it does not implement any custom functions. - * - * @return void - */ - function _createFunctions() - { + return $col ? "adodb_date($fmt,$col)" : "adodb_date($fmt)"; } /** @@ -446,7 +434,19 @@ class ADODB_sqlite3 extends ADOConnection { $argHostname = $argDatabasename; } $this->_connectionID = new SQLite3($argHostname); - $this->_createFunctions(); + + // Register date conversion function for SQLDate() method + // Replaces the legacy adodb_date() functions removed in 5.23.0 + $this->_connectionID->createFunction('adodb_date', + function (string $fmt, $date = null) : string { + if ($date === null || $date === false) { + return date($fmt); + } + + // If it's an int then assume a Unix timestamp, otherwise convert it + return date($fmt, is_int($date) ? $date : strtotime($date)); + } + ); return true; } |
