From 4e551cf9c528f3aa7116c8f2414aa410b8084814 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 25 Jan 2009 12:10:10 +0000 Subject: [PATCH] move shimmie-specific sqlite things out of adodb and into shimmie's database engine --- core/database.class.php | 27 +++++++++++++++++++++----- lib/adodb/drivers/adodb-sqlite.inc.php | 20 ------------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index b7a36733..3b7b3ed1 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -90,15 +90,32 @@ class PostgreSQL extends DBEngine { return "CREATE TABLE $name ($data)"; } } + +// shimmie functions for export to sqlite +function _unix_timestamp($date) { return strtotime($date); } +function _now() { return date("Y-m-d h:i:s"); } +function _floor($a) { return floor($a); } +function _log1($a) { return log($a); } +function _log2($a, $b) { return log($a, $b); } +function _isnull($a) { return is_null($a); } +function _md5($a) { return md5($a); } +function _concat($a, $b) { return $a . $b; } +function _lower($a) { return strtolower($a); } + class SQLite extends DBEngine { var $name = "sqlite"; public function init($db) { - // TODO: add functions: - // now() - // unix_timestamp() - // lower() - // log(base, number) + ini_set('sqlite.assoc_case', 0); + @sqlite_create_function($db->_connectionID, 'UNIX_TIMESTAMP', '_unix_timestamp', 1); + @sqlite_create_function($db->_connectionID, 'now', '_now', 0); + @sqlite_create_function($db->_connectionID, 'floor', '_floor', 1); + @sqlite_create_function($db->_connectionID, 'log', '_log1', 1); + @sqlite_create_function($db->_connectionID, 'log', '_log2', 2); + @sqlite_create_function($db->_connectionID, 'isnull', '_isnull', 1); + @sqlite_create_function($db->_connectionID, 'md5', '_md5', 1); + @sqlite_create_function($db->_connectionID, 'concat', '_concat', 2); + @sqlite_create_function($db->_connectionID, 'lower', '_lower', 1); } public function create_table_sql($name, $data) { diff --git a/lib/adodb/drivers/adodb-sqlite.inc.php b/lib/adodb/drivers/adodb-sqlite.inc.php index 64fbf496..f756c3cd 100644 --- a/lib/adodb/drivers/adodb-sqlite.inc.php +++ b/lib/adodb/drivers/adodb-sqlite.inc.php @@ -152,15 +152,6 @@ class ADODB_sqlite extends ADOConnection { { @sqlite_create_function($this->_connectionID, 'adodb_date', 'adodb_date', 1); @sqlite_create_function($this->_connectionID, 'adodb_date2', 'adodb_date2', 2); - - // XXX: shimmie customisation, as suggested by naikoto on the forums - @sqlite_create_function($this->_connectionID, 'UNIX_TIMESTAMP', 'UNIX_TIMESTAMP', 1); - @sqlite_create_function($this->_connectionID, 'now', 'now', 0); - @sqlite_create_function($this->_connectionID, 'floor', 'mfloor', 1); - @sqlite_create_function($this->_connectionID, 'log', 'mlog', 1); - @sqlite_create_function($this->_connectionID, 'isnull', 'fisnull', 1); - @sqlite_create_function($this->_connectionID, 'md5', 'fmd5', 1); - @sqlite_create_function($this->_connectionID, 'concat', 'fconcat', 2); } @@ -402,16 +393,5 @@ class ADORecordset_sqlite extends ADORecordSet { function _close() { } - } - -// shimmie functions -ini_set ( 'sqlite.assoc_case' , 0 ); -function UNIX_TIMESTAMP($date) { return strtotime($date); } -function now() { return date("Y-m-d h:i:s"); } -function mfloor($a) { return floor($a); } -function mlog($a) { return log($a); } -function fisnull($a) { return is_null($a); } -function fmd5($a) { return md5($a); } -function fconcat($a, $b) { return $a . $b; } ?>