From 3d1ff088ee830d09c985c19fb8ada28851ffa1d7 Mon Sep 17 00:00:00 2001 From: Andreas Piening Date: Thu, 28 Jan 2010 05:29:08 +0000 Subject: [PATCH] MINOR: removed query hack --- README | 52 -------------------------------------- code/SQLite3Database.php | 20 ++++++--------- code/SQLitePDODatabase.php | 4 +++ 3 files changed, 12 insertions(+), 64 deletions(-) diff --git a/README b/README index 1765614..1a3d717 100644 --- a/README +++ b/README @@ -60,55 +60,3 @@ Things to note when using SQLite3 - references for sqlite are e.g. ADOBE (Photoshop Lightroom), Apple (Safari, Mail, iPod, iPhone) Mozilla (Firefox, Thunderbird), Google (Chrome) - if you are looking for a SQLite client for debugging, the SQLite plugin for firefox may be worth a try -SiteTree::doPublish() issue ---------------------------- -SiteTree::doPublish() currently uses a two different non ANSI SQL statements to update the order of SiteTree_Live to satisfy the need of MySQL and MSSQL/Postgres but doesn#t work for SQLite. -A fix would be to use an ANSI compliant form: - -proprietary multiple-table syntax ------------- -+ MySQL -- MSSQL -- Postgres -- SQLite ------------- -UPDATE - SiteTree_Live, SiteTree -SET - SiteTree_Live.Sort = SiteTree.Sort -WHERE - SiteTree_Live.ID = SiteTree.ID AND - SiteTree_Live.ParentID = 1 - -proprietary UPDATE FROM syntax ------------- -- MySQL -+ MSSQL -+ Postgres -- SQLite ------------- -UPDATE - SiteTree_Live -SET - Sort = SiteTree.Sort -FROM - SiteTree -WHERE - SiteTree_Live.ID = SiteTree.ID AND - SiteTree_Live.ParentID = 1 - -ANSI syntax ------------- -+ MySQL -? MSSQL -? Postgres -+ SQLite ------------- -UPDATE - SiteTree_Live -SET - Sort = ( - SELECT SiteTree.Sort FROM SiteTree WHERE SiteTree_Live.ID = SiteTree.ID - ) -WHERE - ParentID = 1 diff --git a/code/SQLite3Database.php b/code/SQLite3Database.php index 9c2eabc..ea031f3 100644 --- a/code/SQLite3Database.php +++ b/code/SQLite3Database.php @@ -178,15 +178,6 @@ class SQLite3Database extends SS_Database { $starttime = microtime(true); } - // @todo This is a very ugly hack to rewrite the update statement of SiteTree::doPublish() - // @see SiteTree::doPublish() There is a hack for MySQL already, maybe it's worth moving this to SiteTree or that other hack to Database... - if(preg_replace('/[\W\d]*/i','',$sql) == 'UPDATESiteTree_LiveSETSortSiteTreeSortFROMSiteTreeWHERESiteTree_LiveIDSiteTreeIDANDSiteTree_LiveParentID') { - preg_match('/\d+/i',$sql,$matches); - $sql = 'UPDATE "SiteTree_Live" - SET "Sort" = (SELECT "SiteTree"."Sort" FROM "SiteTree" WHERE "SiteTree_Live"."ID" = "SiteTree"."ID") - WHERE "ParentID" = ' . $matches[0]; - } - @$handle = $this->dbConn->query($sql); if(isset($_REQUEST['showqueries'])) { @@ -286,6 +277,8 @@ class SQLite3Database extends SS_Database { function beginSchemaUpdate() { $this->pragma('locking_mode', 'EXCLUSIVE'); $this->checkAndRepairTable(); + // if($this->TableExists('SQLiteEnums')) $this->query("DELETE FROM SQLiteEnums"); + $this->checkAndRepairTable(); parent::beginSchemaUpdate(); } @@ -486,7 +479,7 @@ class SQLite3Database extends SS_Database { $spec = $this->convertIndexSpec($indexSpec, $indexName); if(!preg_match('/".+"/', $indexName)) $indexName = "\"$indexName\""; - $this->query("CREATE INDEX $indexName ON \"$tableName\" ($spec)"); + $this->query("CREATE INDEX IF NOT EXISTS $indexName ON \"$tableName\" ($spec)"); } @@ -632,7 +625,7 @@ class SQLite3Database extends SS_Database { $tablefield = $values['table'] . '.' . $values['name']; if(empty($this->enum_map)) $this->query("CREATE TABLE IF NOT EXISTS SQLiteEnums (TableColumn TEXT PRIMARY KEY, EnumList TEXT)"); if(empty($this->enum_map[$tablefield]) || $this->enum_map[$tablefield] != implode(',', $values['enums'])) { - $this->query("REPLACE INTO SQLiteEnums (TableColumn, EnumList) VALUES (\"{$tablefield}\", \"" . implode(', ', $values['enums']) . "\")"); + $this->query("REPLACE INTO SQLiteEnums (TableColumn, EnumList) VALUES (\"{$tablefield}\", \"" . implode(',', $values['enums']) . "\")"); $this->enum_map[$tablefield] = implode(',', $values['enums']); } return "TEXT DEFAULT '{$values['default']}'"; @@ -768,7 +761,9 @@ class SQLite3Database extends SS_Database { */ public function enumValuesForField($tableName, $fieldName) { $classnameinfo = DB::query("SELECT EnumList FROM SQLiteEnums WHERE TableColumn = \"{$tableName}.{$fieldName}\"")->first(); - return explode(',', $classnameinfo['EnumList']); + $return = explode(',', $classnameinfo['EnumList']); + //for($i=0; $ihandle = $handle; } + public function __destruct() { + $this->handle->closeCursor(); + } + public function __destroy() { $this->handle->closeCursor(); }