summaryrefslogtreecommitdiff
path: root/drivers/adodb-sqlite.inc.php
diff options
context:
space:
mode:
authorDamien Regad <dregad@mantisbt.org>2025-07-21 13:30:58 +0200
committerDamien Regad <dregad@mantisbt.org>2025-08-18 18:52:58 +0200
commit2664692f850daffd91113a4b70538e0a0dc7c641 (patch)
tree1eafc8bf69f8f001f9d30c1a9bb20b56ab8a6b05 /drivers/adodb-sqlite.inc.php
parent6103ab98519fe180bcd7ea9637ed544ce3bc2177 (diff)
downloadadodb-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-sqlite.inc.php')
-rw-r--r--drivers/adodb-sqlite.inc.php14
1 files changed, 13 insertions, 1 deletions
diff --git a/drivers/adodb-sqlite.inc.php b/drivers/adodb-sqlite.inc.php
index 00638e70..e9fab6dc 100644
--- a/drivers/adodb-sqlite.inc.php
+++ b/drivers/adodb-sqlite.inc.php
@@ -164,12 +164,24 @@ class ADODB_sqlite extends ADOConnection {
function SQLDate($fmt, $col=false)
{
$fmt = $this->qstr($fmt);
- return ($col) ? "strftime($fmt,$col)" : "strftime($fmt)";
+ return ($col) ? "adodb_date($fmt,$col)" : "adodb_date($fmt)";
}
function _createFunctions()
{
+ // Register date conversion function for SQLDate() method
+ // Replaces the legacy adodb_date() functions removed in 5.23.0
+ @sqlite_create_function($this->_connectionID, '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));
+ }
+ );
}