MINOR: removed query hack

This commit is contained in:
Andreas Piening 2010-01-28 05:29:08 +00:00
parent e8726d1c4e
commit 3d1ff088ee
3 changed files with 12 additions and 64 deletions

52
README
View File

@ -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

View File

@ -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; $i<count($return);$i++) $return[$i] = trim($return[$i]);
return $return;
}
/**
@ -1044,6 +1039,7 @@ class SQLite3Database extends SS_Database {
return implode(',', $terms);
}
}
/**

View File

@ -114,6 +114,10 @@ class SQLitePDOQuery extends SQLite3Query {
$this->handle = $handle;
}
public function __destruct() {
$this->handle->closeCursor();
}
public function __destroy() {
$this->handle->closeCursor();
}