Updated SQL queries to be ansi compatable

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@66401 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-11-23 00:31:06 +00:00
parent 12e62c6329
commit a3d3fb65a9
35 changed files with 163 additions and 163 deletions

View File

@ -453,7 +453,7 @@ class RestfulServer extends Controller {
protected function getObjectQuery($className, $id, $params) { protected function getObjectQuery($className, $id, $params) {
$baseClass = ClassInfo::baseDataClass($className); $baseClass = ClassInfo::baseDataClass($className);
return singleton($className)->buildSQL( return singleton($className)->buildSQL(
"`$baseClass`.ID = {$id}" "\"$baseClass\".ID = {$id}"
); );
} }

View File

@ -83,8 +83,8 @@ class ModelAsController extends Controller implements NestedController {
protected function findOldPage($urlSegment) { protected function findOldPage($urlSegment) {
$versionedQuery = new SQLQuery ( $versionedQuery = new SQLQuery (
'RecordID', 'SiteTree_versions', 'RecordID', 'SiteTree_versions',
"`WasPublished` = 1 AND `URLSegment` = '$urlSegment'", "\"WasPublished\" = 1 AND \"URLSegment\" = '$urlSegment'",
'`LastEdited` DESC, `WasPublished`', '"LastEdited" DESC, "WasPublished"',
null, null, 1 null, null, 1
); );

View File

@ -128,14 +128,14 @@ class ComponentSet extends DataObjectSet {
$parentField = $this->ownerClass . 'ID'; $parentField = $this->ownerClass . 'ID';
$childField = ($this->childClass == $this->ownerClass) ? "ChildID" : ($this->childClass . 'ID'); $childField = ($this->childClass == $this->ownerClass) ? "ChildID" : ($this->childClass . 'ID');
DB::query( "DELETE FROM `$this->tableName` WHERE $parentField = {$this->ownerObj->ID} AND $childField = {$item->ID}" ); DB::query( "DELETE FROM \"$this->tableName\" WHERE $parentField = {$this->ownerObj->ID} AND $childField = {$item->ID}" );
$extraSQL = ''; $extraSQL = '';
if($extraFields) foreach($extraFields as $k => $v) { if($extraFields) foreach($extraFields as $k => $v) {
$extraSQL .= ", $k = '" . addslashes($v) . "'"; $extraSQL .= ", $k = '" . addslashes($v) . "'";
} }
DB::query("INSERT INTO `$this->tableName` SET $parentField = {$this->ownerObj->ID}, $childField = {$item->ID} $extraSQL"); DB::query("INSERT INTO \"$this->tableName\" SET $parentField = {$this->ownerObj->ID}, $childField = {$item->ID} $extraSQL");
} }
} }
@ -206,7 +206,7 @@ class ComponentSet extends DataObjectSet {
} else { } else {
$parentField = $this->ownerClass . 'ID'; $parentField = $this->ownerClass . 'ID';
$childField = ($this->childClass == $this->ownerClass) ? "ChildID" : ($this->childClass . 'ID'); $childField = ($this->childClass == $this->ownerClass) ? "ChildID" : ($this->childClass . 'ID');
DB::query("DELETE FROM `$this->tableName` WHERE $parentField = {$this->ownerObj->ID} AND $childField = {$item->ID}"); DB::query("DELETE FROM \"$this->tableName\" WHERE $parentField = {$this->ownerObj->ID} AND $childField = {$item->ID}");
} }
} }
@ -232,7 +232,7 @@ class ComponentSet extends DataObjectSet {
$itemCSV = implode(", ", $itemList); $itemCSV = implode(", ", $itemList);
$parentField = $this->ownerClass . 'ID'; $parentField = $this->ownerClass . 'ID';
$childField = ($this->childClass == $this->ownerClass) ? "ChildID" : ($this->childClass . 'ID'); $childField = ($this->childClass == $this->ownerClass) ? "ChildID" : ($this->childClass . 'ID');
DB::query("DELETE FROM `$this->tableName` WHERE $parentField = {$this->ownerObj->ID} AND $childField IN ($itemCSV)"); DB::query("DELETE FROM \"$this->tableName\" WHERE $parentField = {$this->ownerObj->ID} AND $childField IN ($itemCSV)");
} }
} }
@ -243,7 +243,7 @@ class ComponentSet extends DataObjectSet {
*/ */
function removeByFilter($filter) { function removeByFilter($filter) {
$parentField = $this->ownerClass . 'ID'; $parentField = $this->ownerClass . 'ID';
DB::query("DELETE FROM `$this->tableName` WHERE $parentField = {$this->ownerObj->ID} AND $filter"); DB::query("DELETE FROM \"$this->tableName\" WHERE $parentField = {$this->ownerObj->ID} AND $filter");
} }
/** /**
@ -252,7 +252,7 @@ class ComponentSet extends DataObjectSet {
function removeAll() { function removeAll() {
if(!empty($this->tableName)) { if(!empty($this->tableName)) {
$parentField = $this->ownerClass . 'ID'; $parentField = $this->ownerClass . 'ID';
DB::query("DELETE FROM `$this->tableName` WHERE $parentField = {$this->ownerObj->ID}"); DB::query("DELETE FROM \"$this->tableName\" WHERE $parentField = {$this->ownerObj->ID}");
} else { } else {
foreach($this->items as $item) { foreach($this->items as $item) {
$this->remove($item); $this->remove($item);

View File

@ -789,7 +789,7 @@ class DataObjectSet extends ViewableData implements IteratorAggregate {
$parentSet = array(); $parentSet = array();
// get direct parents // get direct parents
$parents = DataObject::get( 'SiteTree', "`SiteTree`.`$parentField` IN( " . implode( ",", array_keys( $groupedSet ) ) . ")", $sortParents ); $parents = DataObject::get( 'SiteTree', "\"SiteTree\".\"$parentField\" IN( " . implode( ",", array_keys( $groupedSet ) ) . ")", $sortParents );
// for each of these parents... // for each of these parents...
foreach($parents as $parent) { foreach($parents as $parent) {
@ -815,7 +815,7 @@ class DataObjectSet extends ViewableData implements IteratorAggregate {
if(empty($parentStack)) { if(empty($parentStack)) {
$newParent = new DataObjectSet(); $newParent = new DataObjectSet();
} else { } else {
$newParent = DataObject::get_one( $groupClassName, "`SiteTree`.`$parentField` IN( " . implode( ",", $parentStack ) . ")" ); $newParent = DataObject::get_one( $groupClassName, "\"SiteTree\".\"$parentField\" IN( " . implode( ",", $parentStack ) . ")" );
} }
// change each of the descendant's association from the old parent to // change each of the descendant's association from the old parent to
@ -839,7 +839,7 @@ class DataObjectSet extends ViewableData implements IteratorAggregate {
if(empty($requiredIDs)) { if(empty($requiredIDs)) {
$parentSet = new DataObjectSet(); $parentSet = new DataObjectSet();
} else { } else {
$parentSet = DataObject::get( $groupClassName, "`$groupClassName`.`$parentField` IN( " . implode( ",", $requiredIDs ) . ")", $sortParents ); $parentSet = DataObject::get( $groupClassName, "\"$groupClassName\".\"$parentField\" IN( " . implode( ",", $requiredIDs ) . ")", $sortParents );
} }
$parentSet = $parentSet->toArray(); $parentSet = $parentSet->toArray();

View File

@ -335,7 +335,7 @@ abstract class Database extends Object {
$default = explode('default ', $spec); $default = explode('default ', $spec);
$default = $default[1]; $default = $default[1];
if($default == "'SiteTree'") $default = "'Page'"; if($default == "'SiteTree'") $default = "'Page'";
$query = "UPDATE `$table` SET $field=$default WHERE $field IN ("; $query = "UPDATE \"$table\" SET $field=$default WHERE $field IN (";
for($i=0;$i+1<count($holder);$i++) { for($i=0;$i+1<count($holder);$i++) {
$query .= "'{$holder[$i]}', "; $query .= "'{$holder[$i]}', ";
} }
@ -384,7 +384,7 @@ abstract class Database extends Object {
if(isset($writeInfo['fields']) && $writeInfo['fields']) { if(isset($writeInfo['fields']) && $writeInfo['fields']) {
$fieldList = array(); $fieldList = array();
foreach($writeInfo['fields'] as $fieldName => $fieldVal) { foreach($writeInfo['fields'] as $fieldName => $fieldVal) {
$fieldList[] = "`$fieldName` = $fieldVal"; $fieldList[] = "\"$fieldName\" = $fieldVal";
} }
$fieldList = implode(", ", $fieldList); $fieldList = implode(", ", $fieldList);
@ -394,7 +394,7 @@ abstract class Database extends Object {
switch($writeInfo['command']) { switch($writeInfo['command']) {
case "update": case "update":
$sql = "update `$table` SET $fieldList where $writeInfo[where]"; $sql = "update \"$table\" SET $fieldList where $writeInfo[where]";
$this->query($sql); $this->query($sql);
// If numAffectedRecord = 0, then we want to run instert instead // If numAffectedRecord = 0, then we want to run instert instead
@ -402,7 +402,7 @@ abstract class Database extends Object {
if(!isset($writeInfo['fields']['ID']) && isset($writeInfo['id'])) { if(!isset($writeInfo['fields']['ID']) && isset($writeInfo['id'])) {
$fieldList .= ", ID = $writeInfo[id]"; $fieldList .= ", ID = $writeInfo[id]";
} }
$sql = "insert into `$table` SET $fieldList"; $sql = "insert into \"$table\" SET $fieldList";
$this->query($sql, null); $this->query($sql, null);
} }
break; break;
@ -412,7 +412,7 @@ abstract class Database extends Object {
$fieldList .= ", ID = $writeInfo[id]"; $fieldList .= ", ID = $writeInfo[id]";
} }
$fieldList = Database::replace_with_null($fieldList); $fieldList = Database::replace_with_null($fieldList);
$sql = "insert into `$table` SET $fieldList"; $sql = "insert into \"$table\" SET $fieldList";
$this->query($sql); $this->query($sql);
break; break;

View File

@ -203,7 +203,7 @@ class DatabaseAdmin extends Controller {
function clearAllData() { function clearAllData() {
$tables = DB::query("SHOW TABLES")->column(); $tables = DB::query("SHOW TABLES")->column();
foreach($tables as $table) { foreach($tables as $table) {
DB::query("TRUNCATE `$table`"); DB::query("TRUNCATE \"$table\"");
} }
} }
@ -239,12 +239,12 @@ class DatabaseAdmin extends Controller {
} }
if($subclasses) { if($subclasses) {
$records = DB::query("SELECT * FROM `$baseClass`"); $records = DB::query("SELECT * FROM \"$baseClass\"");
foreach($subclasses as $subclass) { foreach($subclasses as $subclass) {
$recordExists[$subclass] = $recordExists[$subclass] =
DB::query("SELECT ID FROM `$subclass")->keyedColumn(); DB::query("SELECT ID FROM \"$subclass")->keyedColumn();
} }
foreach($records as $record) { foreach($records as $record) {
@ -253,7 +253,7 @@ class DatabaseAdmin extends Controller {
if(($record['ClassName'] != $subclass) && if(($record['ClassName'] != $subclass) &&
(!is_subclass_of($record['ClassName'], $subclass)) && (!is_subclass_of($record['ClassName'], $subclass)) &&
($recordExists[$subclass][$id])) { ($recordExists[$subclass][$id])) {
$sql = "DELETE FROM `$subclass` WHERE ID = $record[ID]"; $sql = "DELETE FROM \"$subclass\" WHERE ID = $record[ID]";
echo "<li>$sql"; echo "<li>$sql";
DB::query($sql); DB::query($sql);
} }

View File

@ -410,11 +410,11 @@ class Hierarchy extends DataObjectDecorator {
DataObject::disable_subclass_access(); DataObject::disable_subclass_access();
if(isset($idxStageChildren)) { if(isset($idxStageChildren)) {
$foundInLive = Versioned::get_by_stage( $baseClass, 'Live', "`{$baseClass}`.`ID` IN (" . implode(",", array_keys($idxStageChildren)) . ")", "" ); $foundInLive = Versioned::get_by_stage( $baseClass, 'Live', "\"{$baseClass}\".\"ID\" IN (" . implode(",", array_keys($idxStageChildren)) . ")", "" );
} }
if(isset($idxLiveChildren)) { if(isset($idxLiveChildren)) {
$foundInStage = Versioned::get_by_stage( $baseClass, 'Stage', "`{$baseClass}`.`ID` IN (" . implode(",", array_keys($idxLiveChildren)) . ")", "" ); $foundInStage = Versioned::get_by_stage( $baseClass, 'Stage', "\"{$baseClass}\".\"ID\" IN (" . implode(",", array_keys($idxLiveChildren)) . ")", "" );
} }
DataObject::enable_subclass_access(); DataObject::enable_subclass_access();
@ -477,7 +477,7 @@ class Hierarchy extends DataObjectDecorator {
public function numChildren() { public function numChildren() {
$baseClass = ClassInfo::baseDataClass($this->owner->class); $baseClass = ClassInfo::baseDataClass($this->owner->class);
// We build the query in an extension-friendly way. // We build the query in an extension-friendly way.
$query = new SQLQuery("COUNT(*)","`$baseClass`","ParentID = " . (int)$this->owner->ID); $query = new SQLQuery("COUNT(*)","\"$baseClass\"","ParentID = " . (int)$this->owner->ID);
$this->owner->extend('augmentSQL', $query); $this->owner->extend('augmentSQL', $query);
return $query->execute()->value(); return $query->execute()->value();
} }
@ -490,7 +490,7 @@ class Hierarchy extends DataObjectDecorator {
public function stageChildren($showAll = false) { public function stageChildren($showAll = false) {
$extraFilter = $showAll ? '' : " AND ShowInMenus = 1"; $extraFilter = $showAll ? '' : " AND ShowInMenus = 1";
$baseClass = ClassInfo::baseDataClass($this->owner->class); $baseClass = ClassInfo::baseDataClass($this->owner->class);
return DataObject::get($baseClass, "`{$baseClass}`.`ParentID` = " . (int)$this->owner->ID . " AND `{$baseClass}`.ID != " . (int)$this->owner->ID . $extraFilter, ""); return DataObject::get($baseClass, "\"{$baseClass}\".\"ParentID\" = " . (int)$this->owner->ID . " AND \"{$baseClass}\".ID != " . (int)$this->owner->ID . $extraFilter, "");
} }
/** /**
@ -501,7 +501,7 @@ class Hierarchy extends DataObjectDecorator {
public function liveChildren($showAll = false) { public function liveChildren($showAll = false) {
$extraFilter = $showAll ? '' : " AND ShowInMenus = 1"; $extraFilter = $showAll ? '' : " AND ShowInMenus = 1";
$baseClass = ClassInfo::baseDataClass($this->owner->class); $baseClass = ClassInfo::baseDataClass($this->owner->class);
return Versioned::get_by_stage($baseClass, "Live", "`{$baseClass}`.`ParentID` = " . (int)$this->owner->ID . " AND `{$baseClass}`.ID != " . (int)$this->owner->ID. $extraFilter, ""); return Versioned::get_by_stage($baseClass, "Live", "\"{$baseClass}\".\"ParentID\" = " . (int)$this->owner->ID . " AND \"{$baseClass}\".ID != " . (int)$this->owner->ID. $extraFilter, "");
} }
/** /**
@ -511,7 +511,7 @@ class Hierarchy extends DataObjectDecorator {
public function getParent($filter = '') { public function getParent($filter = '') {
if($p = $this->owner->__get("ParentID")) { if($p = $this->owner->__get("ParentID")) {
$className = $this->owner->class; $className = $this->owner->class;
$filter .= $filter?" AND ":""."`$className`.ID = $p"; $filter .= $filter?" AND ":""."\"$className\".ID = $p";
return DataObject::get_one($className, $filter); return DataObject::get_one($className, $filter);
} }
} }
@ -552,11 +552,11 @@ class Hierarchy extends DataObjectDecorator {
if(!$afterNode || $afterNode->ParentID != $this->owner->ID) { if(!$afterNode || $afterNode->ParentID != $this->owner->ID) {
$children = $this->AllChildren(); $children = $this->AllChildren();
} else { } else {
$children = DataObject::get(ClassInfo::baseDataClass($this->owner->class), "`$baseClass`.`ParentID`={$this->owner->ID}" . ( ( $afterNode ) ? " AND `Sort` > " . sprintf( '%d', $afterNode->Sort ) : "" ), '`Sort` ASC'); $children = DataObject::get(ClassInfo::baseDataClass($this->owner->class), "\"$baseClass\".\"ParentID\"={$this->owner->ID}" . ( ( $afterNode ) ? " AND \"Sort\" > " . sprintf( '%d', $afterNode->Sort ) : "" ), '\"Sort\" ASC');
} }
// Try all the siblings of this node after the given node // Try all the siblings of this node after the given node
/*if( $siblings = DataObject::get( ClassInfo::baseDataClass($this->owner->class), "`ParentID`={$this->owner->ParentID}" . ( $afterNode ) ? "`Sort` > {$afterNode->Sort}" : "" , '`Sort` ASC' ) ) /*if( $siblings = DataObject::get( ClassInfo::baseDataClass($this->owner->class), "\"ParentID\"={$this->owner->ParentID}" . ( $afterNode ) ? "\"Sort\" > {$afterNode->Sort}" : "" , '\"Sort\" ASC' ) )
$searchNodes->merge( $siblings );*/ $searchNodes->merge( $siblings );*/
if($children) { if($children) {

View File

@ -117,7 +117,7 @@ class MySQLDatabase extends Database {
*/ */
public function getNextID($table) { public function getNextID($table) {
user_error('getNextID is OBSOLETE (and will no longer work properly)', E_USER_WARNING); user_error('getNextID is OBSOLETE (and will no longer work properly)', E_USER_WARNING);
$result = $this->query("SELECT MAX(ID)+1 FROM `$table`")->value(); $result = $this->query("SELECT MAX(ID)+1 FROM \"$table\"")->value();
return $result ? $result : 1; return $result ? $result : 1;
} }
@ -174,10 +174,10 @@ class MySQLDatabase extends Database {
public function createTable($tableName, $fields = null, $indexes = null) { public function createTable($tableName, $fields = null, $indexes = null) {
$fieldSchemas = $indexSchemas = ""; $fieldSchemas = $indexSchemas = "";
if($fields) foreach($fields as $k => $v) $fieldSchemas .= "`$k` $v,\n"; if($fields) foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n";
if($indexes) foreach($indexes as $k => $v) $fieldSchemas .= $this->getIndexSqlDefinition($k, $v) . ",\n"; if($indexes) foreach($indexes as $k => $v) $fieldSchemas .= $this->getIndexSqlDefinition($k, $v) . ",\n";
$this->query("CREATE TABLE `$tableName` ( $this->query("CREATE TABLE \"$tableName\" (
ID int(11) not null auto_increment, ID int(11) not null auto_increment,
$fieldSchemas $fieldSchemas
$indexSchemas $indexSchemas
@ -196,20 +196,20 @@ class MySQLDatabase extends Database {
public function alterTable($tableName, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null) { public function alterTable($tableName, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null) {
$fieldSchemas = $indexSchemas = ""; $fieldSchemas = $indexSchemas = "";
if($newFields) foreach($newFields as $k => $v) $alterList[] .= "ADD `$k` $v"; if($newFields) foreach($newFields as $k => $v) $alterList[] .= "ADD \"$k\" $v";
if($newIndexes) foreach($newIndexes as $k => $v) $alterList[] .= "ADD " . $this->getIndexSqlDefinition($k, $v); if($newIndexes) foreach($newIndexes as $k => $v) $alterList[] .= "ADD " . $this->getIndexSqlDefinition($k, $v);
if($alteredFields) foreach($alteredFields as $k => $v) $alterList[] .= "CHANGE `$k` `$k` $v"; if($alteredFields) foreach($alteredFields as $k => $v) $alterList[] .= "CHANGE \"$k\" \"$k\" $v";
if($alteredIndexes) foreach($alteredIndexes as $k => $v) { if($alteredIndexes) foreach($alteredIndexes as $k => $v) {
$alterList[] .= "DROP INDEX `$k`"; $alterList[] .= "DROP INDEX \"$k\"";
$alterList[] .= "ADD ". $this->getIndexSqlDefinition($k, $v); $alterList[] .= "ADD ". $this->getIndexSqlDefinition($k, $v);
} }
$alterations = implode(",\n", $alterList); $alterations = implode(",\n", $alterList);
$this->query("ALTER TABLE `$tableName` " . $alterations); $this->query("ALTER TABLE \"$tableName\" " . $alterations);
} }
public function renameTable($oldTableName, $newTableName) { public function renameTable($oldTableName, $newTableName) {
$this->query("ALTER TABLE `$oldTableName` RENAME `$newTableName`"); $this->query("ALTER TABLE \"$oldTableName\" RENAME \"$newTableName\"");
} }
@ -220,9 +220,9 @@ class MySQLDatabase extends Database {
* @return boolean Return true if the table has integrity after the method is complete. * @return boolean Return true if the table has integrity after the method is complete.
*/ */
public function checkAndRepairTable($tableName) { public function checkAndRepairTable($tableName) {
if(!$this->runTableCheckCommand("CHECK TABLE `$tableName`")) { if(!$this->runTableCheckCommand("CHECK TABLE \"$tableName\"")) {
Database::alteration_message("Table $tableName: repaired","repaired"); Database::alteration_message("Table $tableName: repaired","repaired");
return $this->runTableCheckCommand("REPAIR TABLE `$tableName` USE_FRM"); return $this->runTableCheckCommand("REPAIR TABLE \"$tableName\" USE_FRM");
} else { } else {
return true; return true;
} }
@ -244,7 +244,7 @@ class MySQLDatabase extends Database {
} }
public function createField($tableName, $fieldName, $fieldSpec) { public function createField($tableName, $fieldName, $fieldSpec) {
$this->query("ALTER TABLE `$tableName` ADD `$fieldName` $fieldSpec"); $this->query("ALTER TABLE \"$tableName\" ADD \"$fieldName\" $fieldSpec");
} }
/** /**
@ -254,7 +254,7 @@ class MySQLDatabase extends Database {
* @param string $fieldSpec The new field specification * @param string $fieldSpec The new field specification
*/ */
public function alterField($tableName, $fieldName, $fieldSpec) { public function alterField($tableName, $fieldName, $fieldSpec) {
$this->query("ALTER TABLE `$tableName` CHANGE `$fieldName` `$fieldName` $fieldSpec"); $this->query("ALTER TABLE \"$tableName\" CHANGE \"$fieldName\" \"$fieldName\" $fieldSpec");
} }
/** /**
@ -267,12 +267,12 @@ class MySQLDatabase extends Database {
public function renameField($tableName, $oldName, $newName) { public function renameField($tableName, $oldName, $newName) {
$fieldList = $this->fieldList($tableName); $fieldList = $this->fieldList($tableName);
if(array_key_exists($oldName, $fieldList)) { if(array_key_exists($oldName, $fieldList)) {
$this->query("ALTER TABLE `$tableName` CHANGE `$oldName` `$newName` " . $fieldList[$oldName]); $this->query("ALTER TABLE \"$tableName\" CHANGE \"$oldName\" \"$newName\" " . $fieldList[$oldName]);
} }
} }
public function fieldList($table) { public function fieldList($table) {
$fields = DB::query("SHOW FULL FIELDS IN `$table`"); $fields = DB::query("SHOW FULL FIELDS IN \"$table\"");
foreach($fields as $field) { foreach($fields as $field) {
$fieldSpec = $field['Type']; $fieldSpec = $field['Type'];
if(!$field['Null'] || $field['Null'] == 'NO') { if(!$field['Null'] || $field['Null'] == 'NO') {
@ -301,7 +301,7 @@ class MySQLDatabase extends Database {
* @param string $indexSpec The specification of the index, see Database::requireIndex() for more details. * @param string $indexSpec The specification of the index, see Database::requireIndex() for more details.
*/ */
public function createIndex($tableName, $indexName, $indexSpec) { public function createIndex($tableName, $indexName, $indexSpec) {
$this->query("ALTER TABLE `$tableName` ADD " . $this->getIndexSqlDefinition($indexName, $indexSpec)); $this->query("ALTER TABLE \"$tableName\" ADD " . $this->getIndexSqlDefinition($indexName, $indexSpec));
} }
protected function getIndexSqlDefinition($indexName, $indexSpec) { protected function getIndexSqlDefinition($indexName, $indexSpec) {
@ -311,7 +311,7 @@ class MySQLDatabase extends Database {
if(!isset($indexType)) { if(!isset($indexType)) {
$indexType = "index"; $indexType = "index";
} }
return "$indexType `$indexName` $indexFields"; return "$indexType \"$indexName\" $indexFields";
} }
/** /**
@ -332,8 +332,8 @@ class MySQLDatabase extends Database {
$indexType = "index"; $indexType = "index";
} }
$this->query("ALTER TABLE `$tableName` DROP INDEX `$indexName`"); $this->query("ALTER TABLE \"$tableName\" DROP INDEX \"$indexName\"");
$this->query("ALTER TABLE `$tableName` ADD $indexType `$indexName` $indexFields"); $this->query("ALTER TABLE \"$tableName\" ADD $indexType \"$indexName\" $indexFields");
} }
/** /**
@ -342,7 +342,7 @@ class MySQLDatabase extends Database {
* @return array * @return array
*/ */
public function indexList($table) { public function indexList($table) {
$indexes = DB::query("SHOW INDEXES IN `$table`"); $indexes = DB::query("SHOW INDEXES IN \"$table\"");
foreach($indexes as $index) { foreach($indexes as $index) {
$groupedIndexes[$index['Key_name']]['fields'][$index['Seq_in_index']] = $index['Column_name']; $groupedIndexes[$index['Key_name']]['fields'][$index['Seq_in_index']] = $index['Column_name'];

View File

@ -282,7 +282,7 @@ class PDODatabase extends Database {
public function createTable($tableName, $fields = null, $indexes = null) { public function createTable($tableName, $fields = null, $indexes = null) {
$fieldSchemas = $indexSchemas = ""; $fieldSchemas = $indexSchemas = "";
if ($fields) { if ($fields) {
foreach($fields as $k => $v) $fieldSchemas .= "`$k` $v,\n"; foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n";
} }
switch (self::getDatabaseServer()) { switch (self::getDatabaseServer()) {
@ -363,11 +363,11 @@ class PDODatabase extends Database {
*/ */
public function checkAndRepairTable($tableName) { public function checkAndRepairTable($tableName) {
if ($parameters['type'] == "mysql") { if ($parameters['type'] == "mysql") {
if (!$this->runTableCheckCommand("CHECK TABLE `$tableName`")) { if (!$this->runTableCheckCommand("CHECK TABLE \"$tableName\"")) {
if(!Database::$supressOutput) { if(!Database::$supressOutput) {
echo "<li style=\"color: orange\">Table $tableName: repaired</li>"; echo "<li style=\"color: orange\">Table $tableName: repaired</li>";
} }
return $this->runTableCheckCommand("REPAIR TABLE `$tableName` USE_FRM"); return $this->runTableCheckCommand("REPAIR TABLE \"$tableName\" USE_FRM");
} else { } else {
return true; return true;
} }

View File

@ -484,7 +484,7 @@ class SiteTree extends DataObject {
*/ */
public function getParent() { public function getParent() {
if ($this->getField("ParentID")) { if ($this->getField("ParentID")) {
return DataObject::get_one("SiteTree", "`SiteTree`.ID = " . $this->getField("ParentID")); return DataObject::get_one("SiteTree", "\"SiteTree\".ID = " . $this->getField("ParentID"));
} }
} }
@ -961,7 +961,7 @@ class SiteTree extends DataObject {
// Ensure URLSegment is unique // Ensure URLSegment is unique
$idFilter = ($this->ID) $idFilter = ($this->ID)
? " AND `SiteTree`.ID <> '$this->ID'" : ? " AND \"SiteTree\".ID <> '$this->ID'" :
''; '';
$count = 1; $count = 1;
@ -1364,7 +1364,7 @@ class SiteTree extends DataObject {
* Publish this page * Publish this page
*/ */
function doPublish() { function doPublish() {
$original = Versioned::get_one_by_stage("SiteTree", "Live", "`SiteTree`.`ID` = $this->ID"); $original = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $this->ID");
if(!$original) $original = new SiteTree(); if(!$original) $original = new SiteTree();
// Handle activities undertaken by decorators // Handle activities undertaken by decorators
@ -1454,7 +1454,7 @@ class SiteTree extends DataObject {
if($this->isNew()) if($this->isNew())
return false; return false;
return (DB::query("SELECT ID FROM `SiteTree_Live` WHERE ID = $this->ID")->value()) return (DB::query("SELECT ID FROM \"SiteTree_Live\" WHERE ID = $this->ID")->value())
? true ? true
: false; : false;
} }

View File

@ -225,7 +225,7 @@ class Translatable extends DataObjectDecorator {
$langsAvailable[] = self::default_lang(); $langsAvailable[] = self::default_lang();
$lang = self::choose_site_lang($langsAvailable); $lang = self::choose_site_lang($langsAvailable);
if (isset($lang)) { if (isset($lang)) {
$transrecord = self::get_one_by_lang($callerClass, $lang, "`$callerClass`.ID = $record->ID"); $transrecord = self::get_one_by_lang($callerClass, $lang, "\"$callerClass\".ID = $record->ID");
if ($transrecord) { if ($transrecord) {
self::set_reading_lang($lang); self::set_reading_lang($lang);
$record = $transrecord; $record = $transrecord;
@ -265,7 +265,7 @@ class Translatable extends DataObjectDecorator {
static function get_original($class, $originalLangID) { static function get_original($class, $originalLangID) {
$baseClass = $class; $baseClass = $class;
while( ($p = get_parent_class($baseClass)) != "DataObject") $baseClass = $p; while( ($p = get_parent_class($baseClass)) != "DataObject") $baseClass = $p;
return self::get_one_by_lang($class,self::default_lang(),"`$baseClass`.ID = $originalLangID"); return self::get_one_by_lang($class,self::default_lang(),"\"$baseClass\".ID = $originalLangID");
} }
/** /**
@ -276,7 +276,7 @@ class Translatable extends DataObjectDecorator {
* @return array List of languages * @return array List of languages
*/ */
static function get_langs_by_id($class, $id) { static function get_langs_by_id($class, $id) {
$query = new SQLQuery('Lang',"{$class}_lang","(`{$class}_lang`.OriginalLangID =$id)"); $query = new SQLQuery('Lang',"{$class}_lang","(\"{$class}_lang\".OriginalLangID =$id)");
$langs = $query->execute()->column(); $langs = $query->execute()->column();
return ($langs) ? array_values($langs) : false; return ($langs) ? array_values($langs) : false;
} }
@ -360,8 +360,8 @@ class Translatable extends DataObjectDecorator {
if (stripos($query->sql(),'.ID')) { if (stripos($query->sql(),'.ID')) {
// Every reference to ID is now OriginalLangID // Every reference to ID is now OriginalLangID
$query->replaceText(".ID",".OriginalLangID"); $query->replaceText(".ID",".OriginalLangID");
$query->where = str_replace("`ID`", "`OriginalLangID`",$query->where); $query->where = str_replace("\"ID\"", "\"OriginalLangID\"",$query->where);
$query->select[] = "`{$baseTable}_lang`.OriginalLangID AS ID"; $query->select[] = "\"{$baseTable}_lang\".OriginalLangID AS ID";
} }
if ($query->where) foreach ($query->where as $i => $wherecl) { if ($query->where) foreach ($query->where as $i => $wherecl) {
if (substr($wherecl,0,4) == 'ID =') if (substr($wherecl,0,4) == 'ID =')
@ -371,18 +371,18 @@ class Translatable extends DataObjectDecorator {
$parts = explode(' AND ',$wherecl); $parts = explode(' AND ',$wherecl);
foreach ($parts as $j => $part) { foreach ($parts as $j => $part) {
// Divide this clause between the left ($innerparts[1]) and right($innerparts[2]) part of the condition // Divide this clause between the left ($innerparts[1]) and right($innerparts[2]) part of the condition
ereg('(`?[[:alnum:]_-]*`?\.?`?[[:alnum:]_-]*`?)(.*)', $part, $innerparts); ereg('(\"?[[:alnum:]_-]*\"?\.?\"?[[:alnum:]_-]*\"?)(.*)', $part, $innerparts);
if (strpos($innerparts[1],'.') === false) if (strpos($innerparts[1],'.') === false)
//it may be ambiguous, so sometimes we will need to add the table //it may be ambiguous, so sometimes we will need to add the table
$parts[$j] = ($this->isInAugmentedTable($innerparts[1], $table) ? "`{$table}_lang`." : "")."$part"; $parts[$j] = ($this->isInAugmentedTable($innerparts[1], $table) ? "\"{$table}_lang\"." : "")."$part";
else { else {
/* if the table has been specified we have to determine if the original (without _lang) name has to be used /* if the table has been specified we have to determine if the original (without _lang) name has to be used
* because we don't have the queried field in the augmented table (which usually means * because we don't have the queried field in the augmented table (which usually means
* that is not a translatable field) * that is not a translatable field)
*/ */
$clauseparts = explode('.',$innerparts[1]); $clauseparts = explode('.',$innerparts[1]);
$originalTable = str_replace('`','',str_replace('_lang','',$clauseparts[0])); $originalTable = str_replace('\"','',str_replace('_lang','',$clauseparts[0]));
$parts[$j] = ($this->isInAugmentedTable($clauseparts[1], $originalTable) ? "`{$originalTable}_lang`" : "`$originalTable`") $parts[$j] = ($this->isInAugmentedTable($clauseparts[1], $originalTable) ? "\"{$originalTable}_lang\"" : "\"$originalTable\"")
. ".{$clauseparts[1]}{$innerparts[2]}"; . ".{$clauseparts[1]}{$innerparts[2]}";
} }
} }
@ -398,19 +398,19 @@ class Translatable extends DataObjectDecorator {
} }
// unless we are bypassing this query, add the language filter // unless we are bypassing this query, add the language filter
if (!self::$bypass) $query->where[] = "`{$table}_lang`.Lang = '$lang'"; if (!self::$bypass) $query->where[] = "\"{$table}_lang\".Lang = '$lang'";
// unless this is a deletion, the query is applied to the joined table // unless this is a deletion, the query is applied to the joined table
if (!$query->delete) { if (!$query->delete) {
$query->from[$table] = "INNER JOIN `$table`". $query->from[$table] = "INNER JOIN \"$table\"".
" ON `{$table}_lang`.OriginalLangID = `$table`.ID"; " ON \"{$table}_lang\".OriginalLangID = \"$table\".ID";
/* if we are selecting fields (not doing counts for example) we need to select everything from /* if we are selecting fields (not doing counts for example) we need to select everything from
* the original table (was renamed to _lang) since some fields that we require may be there * the original table (was renamed to _lang) since some fields that we require may be there
*/ */
if ($query->select[0][0] == '`') $query->select = array_merge(array("`$table`.*"),$query->select); if ($query->select[0][0] == '\"') $query->select = array_merge(array("\"$table\".*"),$query->select);
} else unset($query->from[$table]); } else unset($query->from[$table]);
} else { } else {
$query->from[$table] = str_replace("`{$table}`.OriginalLangID","`{$table}`.ID",$query->from[$table]); $query->from[$table] = str_replace("\"{$table}\".OriginalLangID","\"{$table}\".ID",$query->from[$table]);
} }
} }
} }
@ -424,7 +424,7 @@ class Translatable extends DataObjectDecorator {
* @return boolean True if the clause can be applied to the augmented table * @return boolean True if the clause can be applied to the augmented table
*/ */
function isInAugmentedTable($clause, $table) { function isInAugmentedTable($clause, $table) {
$clause = str_replace('`','',$clause); $clause = str_replace('\"','',$clause);
$table = str_replace('_lang','',$table); $table = str_replace('_lang','',$table);
if (strpos($table,'_') !== false) return false; if (strpos($table,'_') !== false) return false;
$field = ereg_replace('[[:blank:]]*([[:alnum:]]*).*','\\1',$clause); $field = ereg_replace('[[:blank:]]*([[:alnum:]]*).*','\\1',$clause);
@ -587,7 +587,7 @@ class Translatable extends DataObjectDecorator {
$originalRecord = self::get_one_by_lang( $originalRecord = self::get_one_by_lang(
$this->owner->class, $this->owner->class,
self::$default_lang, self::$default_lang,
"`$baseClass`.ID = ".$originalLangID "\"$baseClass\".ID = ".$originalLangID
); );
$this->original_values = $originalRecord->getAllFields(); $this->original_values = $originalRecord->getAllFields();
$alltasks = array( 'dup' => array()); $alltasks = array( 'dup' => array());

View File

@ -65,18 +65,18 @@ class Versioned extends DataObjectDecorator {
} }
$query->renameTable($table, $table . '_versions'); $query->renameTable($table, $table . '_versions');
$query->replaceText(".ID", ".RecordID"); $query->replaceText(".ID", ".RecordID");
$query->select[] = "`{$baseTable}_versions`.RecordID AS ID"; $query->select[] = "\"{$baseTable}_versions\".RecordID AS ID";
if($table != $baseTable) { if($table != $baseTable) {
$query->from[$table] .= " AND `{$table}_versions`.Version = `{$baseTable}_versions`.Version"; $query->from[$table] .= " AND \"{$table}_versions\".Version = \"{$baseTable}_versions\".Version";
} }
} }
// Link to the version archived on that date // Link to the version archived on that date
$this->requireArchiveTempTable($baseTable, $date); $this->requireArchiveTempTable($baseTable, $date);
$query->from["_Archive$baseTable"] = "INNER JOIN `_Archive$baseTable` $query->from["_Archive$baseTable"] = "INNER JOIN \"_Archive$baseTable\"
ON `_Archive$baseTable`.RecordID = `{$baseTable}_versions`.RecordID ON \"_Archive$baseTable\".RecordID = \"{$baseTable}_versions\".RecordID
AND `_Archive$baseTable`.Version = `{$baseTable}_versions`.Version"; AND \"_Archive$baseTable\".Version = \"{$baseTable}_versions\".Version";
// Get a specific stage // Get a specific stage
} else if(Versioned::$reading_stage && Versioned::$reading_stage != $this->defaultStage } else if(Versioned::$reading_stage && Versioned::$reading_stage != $this->defaultStage
@ -176,8 +176,8 @@ class Versioned extends DataObjectDecorator {
/* /*
if(!DB::query("SELECT * FROM {$table}_$stage")->value()) { if(!DB::query("SELECT * FROM {$table}_$stage")->value()) {
$fieldList = implode(", ",array_keys($fields)); $fieldList = implode(", ",array_keys($fields));
DB::query("INSERT INTO `{$table}_$stage` (ID,$fieldList) DB::query("INSERT INTO \"{$table}_$stage\" (ID,$fieldList)
SELECT ID,$fieldList FROM `$table`"); SELECT ID,$fieldList FROM \"$table\"");
} }
*/ */
} }
@ -217,8 +217,8 @@ class Versioned extends DataObjectDecorator {
if(!DB::query("SELECT * FROM {$table}_versions")->value()) { if(!DB::query("SELECT * FROM {$table}_versions")->value()) {
$fieldList = implode(", ",array_keys($fields)); $fieldList = implode(", ",array_keys($fields));
DB::query("INSERT INTO `{$table}_versions` ($fieldList, RecordID, Version) DB::query("INSERT INTO \"{$table}_versions\" ($fieldList, RecordID, Version)
SELECT $fieldList, ID AS RecordID, 1 AS Version FROM `$table`"); SELECT $fieldList, ID AS RecordID, 1 AS Version FROM \"$table\"");
} }
*/ */
@ -386,7 +386,7 @@ class Versioned extends DataObjectDecorator {
$from = Versioned::get_version($this->owner->class, $this->owner->ID, $fromStage); $from = Versioned::get_version($this->owner->class, $this->owner->ID, $fromStage);
} else { } else {
$this->owner->flushCache(); $this->owner->flushCache();
$from = Versioned::get_one_by_stage($this->owner->class, $fromStage, "`{$baseClass}`.`ID` = {$this->owner->ID}"); $from = Versioned::get_one_by_stage($this->owner->class, $fromStage, "\"{$baseClass}\".\"ID\" = {$this->owner->ID}");
} }
$publisherID = isset(Member::currentUser()->ID) ? Member::currentUser()->ID : 0; $publisherID = isset(Member::currentUser()->ID) ? Member::currentUser()->ID : 0;
@ -395,7 +395,7 @@ class Versioned extends DataObjectDecorator {
if(!$createNewVersion) $from->migrateVersion($from->Version); if(!$createNewVersion) $from->migrateVersion($from->Version);
// Mark this version as having been published at some stage // Mark this version as having been published at some stage
DB::query("UPDATE `{$extTable}_versions` SET WasPublished = 1, PublisherID = $publisherID WHERE RecordID = $from->ID AND Version = $from->Version"); DB::query("UPDATE \"{$extTable}_versions\" SET WasPublished = 1, PublisherID = $publisherID WHERE RecordID = $from->ID AND Version = $from->Version");
$oldStage = Versioned::$reading_stage; $oldStage = Versioned::$reading_stage;
Versioned::$reading_stage = $toStage; Versioned::$reading_stage = $toStage;
@ -431,7 +431,7 @@ class Versioned extends DataObjectDecorator {
} }
// We test for equality - if one of the versions doesn't exist, this will be false // We test for equality - if one of the versions doesn't exist, this will be false
$stagesAreEqual = DB::query("SELECT if(`$table1`.Version=`$table2`.Version,1,0) FROM `$table1` INNER JOIN `$table2` ON `$table1`.ID = `$table2`.ID AND `$table1`.ID = {$this->owner->ID}")->value(); $stagesAreEqual = DB::query("SELECT if(\"$table1\".Version=\"$table2\".Version,1,0) FROM \"$table1\" INNER JOIN \"$table2\" ON \"$table1\".ID = \"$table2\".ID AND \"$table1\".ID = {$this->owner->ID}")->value();
return !$stagesAreEqual; return !$stagesAreEqual;
} }
@ -447,14 +447,14 @@ class Versioned extends DataObjectDecorator {
$query = $this->owner->extendedSQL($filter,""); $query = $this->owner->extendedSQL($filter,"");
foreach($query->from as $table => $join) { foreach($query->from as $table => $join) {
if($join[0] == '`') $baseTable = str_replace('`','',$join); if($join[0] == '\"') $baseTable = str_replace('\"','',$join);
else if (substr($join,0,5) != 'INNER') $query->from[$table] = "LEFT JOIN `$table` ON `$table`.RecordID = `{$baseTable}_versions`.RecordID AND `$table`.Version = `{$baseTable}_versions`.Version"; else if (substr($join,0,5) != 'INNER') $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".RecordID = \"{$baseTable}_versions\".RecordID AND \"$table\".Version = \"{$baseTable}_versions\".Version";
$query->renameTable($table, $table . '_versions'); $query->renameTable($table, $table . '_versions');
} }
$query->select[] = "`{$baseTable}_versions`.AuthorID, `{$baseTable}_versions`.Version, `{$baseTable}_versions`.RecordID"; $query->select[] = "\"{$baseTable}_versions\".AuthorID, \"{$baseTable}_versions\".Version, \"{$baseTable}_versions\".RecordID";
$query->where[] = "`{$baseTable}_versions`.RecordID = '{$this->owner->ID}'"; $query->where[] = "\"{$baseTable}_versions\".RecordID = '{$this->owner->ID}'";
$query->orderby = "`{$baseTable}_versions`.LastEdited DESC, `{$baseTable}_versions`.Version DESC"; $query->orderby = "\"{$baseTable}_versions\".LastEdited DESC, \"{$baseTable}_versions\".Version DESC";
$records = $query->execute(); $records = $query->execute();
@ -630,22 +630,22 @@ class Versioned extends DataObjectDecorator {
function buildVersionSQL($filter = "", $sort = "") { function buildVersionSQL($filter = "", $sort = "") {
$query = $this->owner->extendedSQL($filter,$sort); $query = $this->owner->extendedSQL($filter,$sort);
foreach($query->from as $table => $join) { foreach($query->from as $table => $join) {
if($join[0] == '`') $baseTable = str_replace('`','',$join); if($join[0] == '\"') $baseTable = str_replace('\"','',$join);
else $query->from[$table] = "LEFT JOIN `$table` ON `$table`.RecordID = `{$baseTable}_versions`.RecordID AND `$table`.Version = `{$baseTable}_versions`.Version"; else $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".RecordID = \"{$baseTable}_versions\".RecordID AND \"$table\".Version = \"{$baseTable}_versions\".Version";
$query->renameTable($table, $table . '_versions'); $query->renameTable($table, $table . '_versions');
} }
$query->select[] = "`{$baseTable}_versions`.AuthorID, `{$baseTable}_versions`.Version, `{$baseTable}_versions`.RecordID AS ID"; $query->select[] = "\"{$baseTable}_versions\".AuthorID, \"{$baseTable}_versions\".Version, \"{$baseTable}_versions\".RecordID AS ID";
return $query; return $query;
} }
static function build_version_sql($className, $filter = "", $sort = "") { static function build_version_sql($className, $filter = "", $sort = "") {
$query = singleton($className)->extendedSQL($filter,$sort); $query = singleton($className)->extendedSQL($filter,$sort);
foreach($query->from as $table => $join) { foreach($query->from as $table => $join) {
if($join[0] == '`') $baseTable = str_replace('`','',$join); if($join[0] == '\"') $baseTable = str_replace('"','',$join);
else $query->from[$table] = "LEFT JOIN `$table` ON `$table`.RecordID = `{$baseTable}_versions`.RecordID AND `$table`.Version = `{$baseTable}_versions`.Version"; else $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".RecordID = \"{$baseTable}_versions\".RecordID AND \"$table\".Version = \"{$baseTable}_versions\".Version";
$query->renameTable($table, $table . '_versions'); $query->renameTable($table, $table . '_versions');
} }
$query->select[] = "`{$baseTable}_versions`.AuthorID, `{$baseTable}_versions`.Version, `{$baseTable}_versions`.RecordID AS ID"; $query->select[] = "\"{$baseTable}_versions\".AuthorID, \"{$baseTable}_versions\".Version, \"{$baseTable}_versions\".RecordID AS ID";
return $query; return $query;
} }
@ -657,7 +657,7 @@ class Versioned extends DataObjectDecorator {
Versioned::$reading_stage = null; Versioned::$reading_stage = null;
$baseTable = ClassInfo::baseDataClass($class); $baseTable = ClassInfo::baseDataClass($class);
$query = singleton($class)->buildVersionSQL("`{$baseTable}`.RecordID = $id", "`{$baseTable}`.Version DESC"); $query = singleton($class)->buildVersionSQL("\"{$baseTable}\".RecordID = $id", "\"{$baseTable}\".Version DESC");
$query->limit = 1; $query->limit = 1;
$record = $query->execute()->record(); $record = $query->execute()->record();
$className = $record['ClassName']; $className = $record['ClassName'];
@ -677,7 +677,7 @@ class Versioned extends DataObjectDecorator {
Versioned::$reading_stage = null; Versioned::$reading_stage = null;
$baseTable = ClassInfo::baseDataClass($class); $baseTable = ClassInfo::baseDataClass($class);
$query = singleton($class)->buildVersionSQL("`{$baseTable}`.RecordID = $id AND `{$baseTable}`.Version = $version"); $query = singleton($class)->buildVersionSQL("\"{$baseTable}\".RecordID = $id AND \"{$baseTable}\".Version = $version");
$record = $query->execute()->record(); $record = $query->execute()->record();
$className = $record['ClassName']; $className = $record['ClassName'];
if(!$className) { if(!$className) {
@ -693,7 +693,7 @@ class Versioned extends DataObjectDecorator {
static function get_all_versions($class, $id, $version) { static function get_all_versions($class, $id, $version) {
$baseTable = ClassInfo::baseDataClass($class); $baseTable = ClassInfo::baseDataClass($class);
$query = singleton($class)->buildVersionSQL("`{$baseTable}`.RecordID = $id AND `{$baseTable}`.Version = $version"); $query = singleton($class)->buildVersionSQL("\"{$baseTable}\".RecordID = $id AND \"{$baseTable}\".Version = $version");
$record = $query->execute()->record(); $record = $query->execute()->record();
$className = $record[ClassName]; $className = $record[ClassName];
if(!$className) { if(!$className) {

View File

@ -102,7 +102,7 @@ class VirtualPage extends Page {
if(isset($this->changed['CopyContentFromID']) && $this->changed['CopyContentFromID'] if(isset($this->changed['CopyContentFromID']) && $this->changed['CopyContentFromID']
&& $this->CopyContentFromID != 0 && $this->class == 'VirtualPage' ) { && $this->CopyContentFromID != 0 && $this->class == 'VirtualPage' ) {
$CopyContentFromID = $this->CopyContentFromID; $CopyContentFromID = $this->CopyContentFromID;
$source = DataObject::get_one("SiteTree","`SiteTree`.`ID`='$CopyContentFromID'"); $source = DataObject::get_one("SiteTree","\"SiteTree\".\"ID\"='$CopyContentFromID'");
$this->copyFrom($source); $this->copyFrom($source);
$this->URLSegment = $source->URLSegment . '-' . $this->ID; $this->URLSegment = $source->URLSegment . '-' . $this->ID;
} }

View File

@ -149,7 +149,7 @@ class CsvBulkLoader extends BulkLoader {
//user_error("CsvBulkLoader:processRecord: Couldn't find duplicate identifier '{$fieldName}' in columns", E_USER_ERROR); //user_error("CsvBulkLoader:processRecord: Couldn't find duplicate identifier '{$fieldName}' in columns", E_USER_ERROR);
} }
$SQL_fieldValue = $record[$fieldName]; $SQL_fieldValue = $record[$fieldName];
$existingRecord = DataObject::get_one($this->objectClass, "`$SQL_fieldName` = '{$SQL_fieldValue}'"); $existingRecord = DataObject::get_one($this->objectClass, "\"$SQL_fieldName\" = '{$SQL_fieldValue}'");
if($existingRecord) return $existingRecord; if($existingRecord) return $existingRecord;
} elseif(is_array($duplicateCheck) && isset($duplicateCheck['callback'])) { } elseif(is_array($duplicateCheck) && isset($duplicateCheck['callback'])) {
$existingRecord = singleton($this->objectClass)->{$duplicateCheck['callback']}($record[$fieldName], $record); $existingRecord = singleton($this->objectClass)->{$duplicateCheck['callback']}($record[$fieldName], $record);

View File

@ -519,7 +519,7 @@ class Email_BounceHandler extends Controller {
if(!$duplicateBounce) { if(!$duplicateBounce) {
$record = new Email_BounceRecord(); $record = new Email_BounceRecord();
$member = DataObject::get_one( 'Member', "`Email`='$SQL_email'" ); $member = DataObject::get_one( 'Member', "\"Email\"='$SQL_email'" );
if( $member ) { if( $member ) {
$record->MemberID = $member->ID; $record->MemberID = $member->ID;

View File

@ -13,7 +13,7 @@ class QueuedEmailDispatchTask extends DailyTask {
echo "SENDING QUEUED EMAILS\n"; echo "SENDING QUEUED EMAILS\n";
$queued = DataObject::get('QueuedEmail', "`Send` < NOW()"); $queued = DataObject::get('QueuedEmail', "\"Send\" < NOW()");
if( !$queued ) if( !$queued )
return; return;

View File

@ -560,10 +560,10 @@ class File extends DataObject {
// In short, we select everything except File.Content // In short, we select everything except File.Content
$dataobject_select = array(); $dataobject_select = array();
foreach($query->select as $item) { foreach($query->select as $item) {
if($item == "`File`.*") { if($item == "\"File\".*") {
$fileColumns = DB::query("SHOW FIELDS IN `File`")->column(); $fileColumns = DB::query("SHOW FIELDS IN \"File\"")->column();
$columnsToAdd = array_diff($fileColumns, $excludeDbColumns); $columnsToAdd = array_diff($fileColumns, $excludeDbColumns);
foreach($columnsToAdd as $otherItem) $dataobject_select[] = '`File`.' . $otherItem; foreach($columnsToAdd as $otherItem) $dataobject_select[] = '"File".' . $otherItem;
} else { } else {
$dataobject_select[] = $item; $dataobject_select[] = $item;
} }

View File

@ -43,19 +43,19 @@ class Folder extends File {
$deleted = 0; $deleted = 0;
// First, merge any children that are duplicates // First, merge any children that are duplicates
$duplicateChildrenNames = DB::query("SELECT Name FROM `File` WHERE ParentID = $parentID GROUP BY Name HAVING count(*) > 1")->column(); $duplicateChildrenNames = DB::query("SELECT Name FROM \"File\" WHERE ParentID = $parentID GROUP BY Name HAVING count(*) > 1")->column();
if($duplicateChildrenNames) foreach($duplicateChildrenNames as $childName) { if($duplicateChildrenNames) foreach($duplicateChildrenNames as $childName) {
$childName = addslashes($childName); $childName = addslashes($childName);
// Note, we do this in the database rather than object-model; otherwise we get all sorts of problems about deleting files // Note, we do this in the database rather than object-model; otherwise we get all sorts of problems about deleting files
$children = DB::query("SELECT ID FROM `File` WHERE Name = '$childName' AND ParentID = $parentID")->column(); $children = DB::query("SELECT ID FROM \"File\" WHERE Name = '$childName' AND ParentID = $parentID")->column();
if($children) { if($children) {
$keptChild = array_shift($children); $keptChild = array_shift($children);
foreach($children as $removedChild) { foreach($children as $removedChild) {
DB::query("UPDATE `File` SET ParentID = $keptChild WHERE ParentID = $removedChild"); DB::query("UPDATE \"File\" SET ParentID = $keptChild WHERE ParentID = $removedChild");
DB::query("DELETE FROM `File` WHERE ID = $removedChild"); DB::query("DELETE FROM \"File\" WHERE ID = $removedChild");
} }
} else { } else {
user_error("Inconsistent database issue: SELECT ID FROM `File` WHERE Name = '$childName' AND ParentID = $parentID should have returned data", E_USER_WARNING); user_error("Inconsistent database issue: SELECT ID FROM \"File\" WHERE Name = '$childName' AND ParentID = $parentID should have returned data", E_USER_WARNING);
} }
} }
@ -93,7 +93,7 @@ class Folder extends File {
$child = $hasDbChild[$actualChild]; $child = $hasDbChild[$actualChild];
if( ($child->class != 'Folder' && is_dir($baseDir . $actualChild)) if( ($child->class != 'Folder' && is_dir($baseDir . $actualChild))
|| ($child->class == 'Folder' && !is_dir($baseDir . $actualChild)) ) { || ($child->class == 'Folder' && !is_dir($baseDir . $actualChild)) ) {
DB::query("DELETE FROM `File` WHERE ID = $child->ID"); DB::query("DELETE FROM \"File\" WHERE ID = $child->ID");
unset($hasDbChild[$actualChild]); unset($hasDbChild[$actualChild]);
} }
} }
@ -117,11 +117,11 @@ class Folder extends File {
// Iterate through the unwanted children, removing them all // Iterate through the unwanted children, removing them all
if(isset($unwantedDbChildren)) foreach($unwantedDbChildren as $unwantedDbChild) { if(isset($unwantedDbChildren)) foreach($unwantedDbChildren as $unwantedDbChild) {
DB::query("DELETE FROM `File` WHERE ID = $unwantedDbChild->ID"); DB::query("DELETE FROM \"File\" WHERE ID = $unwantedDbChild->ID");
$deleted++; $deleted++;
} }
} else { } else {
DB::query("DELETE FROM `File` WHERE ID = $this->ID"); DB::query("DELETE FROM \"File\" WHERE ID = $this->ID");
} }
return array('added' => $added, 'deleted' => $deleted); return array('added' => $added, 'deleted' => $deleted);
@ -154,7 +154,7 @@ class Folder extends File {
$name = addslashes($name); $name = addslashes($name);
DB::query("INSERT INTO `File` SET DB::query("INSERT INTO \"File\" SET
ClassName = '$className', ParentID = $this->ID, OwnerID = $ownerID, ClassName = '$className', ParentID = $this->ID, OwnerID = $ownerID,
Name = '$name', Filename = '$filename', Created = NOW(), LastEdited = NOW(), Name = '$name', Filename = '$filename', Created = NOW(), LastEdited = NOW(),
Title = '$name'"); Title = '$name'");
@ -433,7 +433,7 @@ class Folder extends File {
} }
if($where == "") return "(ClassName = 'File' OR ClassName = 'Image')"; if($where == "") return "(ClassName = 'File' OR ClassName = 'Image')";
$where = substr($where,0,strlen($where)-1); $where = substr($where,0,strlen($where)-1);
$where = "`File`.ID NOT IN (" . $where . ") AND (ClassName = 'File' OR ClassName = 'Image')"; $where = "\"File\".ID NOT IN (" . $where . ") AND (ClassName = 'File' OR ClassName = 'Image')";
return $where; return $where;
} }

View File

@ -107,7 +107,7 @@ JS;
function validate( $validator ) { function validate( $validator ) {
$result = DB::query(sprintf( $result = DB::query(sprintf(
"SELECT COUNT(*) FROM `%s` WHERE `%s` = '%s'", "SELECT COUNT(*) FROM \"%s\" WHERE \"%s\" = '%s'",
$this->restrictedTable, $this->restrictedTable,
$this->restrictedField, $this->restrictedField,
Convert::raw2sql($this->value) Convert::raw2sql($this->value)

View File

@ -219,7 +219,7 @@ class ComplexTableField extends TableListField {
&& ($filterKey = $this->getParentIdName($this->getParentClass(), $this->sourceClass())) && ($filterKey = $this->getParentIdName($this->getParentClass(), $this->sourceClass()))
&& ($filterValue = $this->sourceID()) ) { && ($filterValue = $this->sourceID()) ) {
$newFilter = "`$filterKey` = '" . Convert::raw2sql($filterValue) . "'"; $newFilter = "\"$filterKey\" = '" . Convert::raw2sql($filterValue) . "'";
if($sourceFilter && is_array($sourceFilter)) { if($sourceFilter && is_array($sourceFilter)) {
// Note that the brackets below are taken into account when building this // Note that the brackets below are taken into account when building this

View File

@ -36,7 +36,7 @@ class HasOneComplexTableField extends HasManyComplexTableField {
} }
function isChildSet($childID) { function isChildSet($childID) {
return DataObject::get($this->controllerClass(), '`' . $this->joinField . "` = '$childID'"); return DataObject::get($this->controllerClass(), '"' . $this->joinField . "\" = '$childID'");
} }
function ExtraData() { function ExtraData() {

View File

@ -37,7 +37,7 @@ class ManyManyComplexTableField extends HasManyComplexTableField {
$sourceField = 'Child'; $sourceField = 'Child';
$parentID = $this->controller->ID; $parentID = $this->controller->ID;
$this->sourceJoin .= " LEFT JOIN `$manyManyTable` ON (`$source`.`ID` = `{$sourceField}ID` AND `{$this->manyManyParentClass}ID` = '$parentID')"; $this->sourceJoin .= " LEFT JOIN \"$manyManyTable\" ON (\"$source\".\"ID\" = \"{$sourceField}ID\" AND \"{$this->manyManyParentClass}ID\" = '$parentID')";
$this->joinField = 'Checked'; $this->joinField = 'Checked';
} }
@ -60,7 +60,7 @@ class ManyManyComplexTableField extends HasManyComplexTableField {
$query->select[] = $k; $query->select[] = $k;
} }
$parent = $this->controllerClass(); $parent = $this->controllerClass();
$query->select[] = "IF(`{$this->manyManyParentClass}ID` IS NULL, '0', '1') AS Checked"; $query->select[] = "IF(\"{$this->manyManyParentClass}ID\" IS NULL, '0', '1') AS Checked";
} }
return clone $query; return clone $query;
} }

View File

@ -182,7 +182,7 @@ HTML;
protected function getColumnsInTable( $table ) { protected function getColumnsInTable( $table ) {
$result = DB::query( "SELECT * FROM `$table` LIMIT 1" ); $result = DB::query( "SELECT * FROM \"$table\" LIMIT 1" );
return array_keys( $result->next() ); return array_keys( $result->next() );
} }
@ -229,7 +229,7 @@ HTML;
$joinKey = $this->primaryKeys[$className]; $joinKey = $this->primaryKeys[$className];
// get the all the extra fields. // get the all the extra fields.
$recordObj = DataObject::get_one( $className, "`$className`.`$joinKey`='$primaryKeyValue'" ); $recordObj = DataObject::get_one( $className, "\"$className\".\"$joinKey\"='$primaryKeyValue'" );
$completeRecord = $completeRecord + $this->joinFields( $recordObj, $fields ); $completeRecord = $completeRecord + $this->joinFields( $recordObj, $fields );
} }
@ -264,7 +264,7 @@ HTML;
$tableColumns = array(); $tableColumns = array();
$selectFields = array(); $selectFields = array();
$joins = array( "`{$this->primaryClass}`" ); $joins = array( "\"{$this->primaryClass}\"" );
foreach( $this->fields as $field ) { foreach( $this->fields as $field ) {
if( $field{0} == '!' ) if( $field{0} == '!' )
@ -274,9 +274,9 @@ HTML;
$tableColumns[$table][] = $column; $tableColumns[$table][] = $column;
if( $column == '*' ) if( $column == '*' )
$selectFields[] = "`$table`.*"; $selectFields[] = "\"$table\".*";
else else
$selectFields[] = "`$table`.`$column` AS '$table.$column'"; $selectFields[] = "\"$table\".\"$column\" AS '$table.$column'";
} }
foreach( array_keys( $tableColumns ) as $table ) { foreach( array_keys( $tableColumns ) as $table ) {
@ -284,7 +284,7 @@ HTML;
$primaryKey = $this->primaryKeys[$this->primaryClass]; $primaryKey = $this->primaryKeys[$this->primaryClass];
if( $table != $this->primaryClass ) if( $table != $this->primaryClass )
$joins[] = "LEFT JOIN `$table` ON `$table`.`$tableKey`=`{$this->primaryClass}`.`$primaryKey`"; $joins[] = "LEFT JOIN \"$table\" ON \"$table\".\"$tableKey\"=\"{$this->primaryClass}\".\"$primaryKey\"";
} }
$query = new SQLQuery( $selectFields, $joins ); $query = new SQLQuery( $selectFields, $joins );

View File

@ -110,7 +110,7 @@ class TableField extends TableListField {
// If we specify filterField, then an implicit source filter of "filterField = sourceFilter" is used. // If we specify filterField, then an implicit source filter of "filterField = sourceFilter" is used.
if($filterField) { if($filterField) {
$this->filterValue = $sourceFilter; $this->filterValue = $sourceFilter;
$sourceFilter = "`$filterField` = '" . Convert::raw2sql($sourceFilter) . "'"; $sourceFilter = "\"$filterField\" = '" . Convert::raw2sql($sourceFilter) . "'";
} }
parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin); parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);

View File

@ -453,7 +453,7 @@ JS
$SNG = singleton($this->sourceClass); $SNG = singleton($this->sourceClass);
foreach($this->FieldList() as $k=>$title){ foreach($this->FieldList() as $k=>$title){
if(!$SNG->hasField($k) && !$SNG->hasMethod('get' . $k) && !$SNG->hasMethod($k) && !strpos($k, ".")) if(!$SNG->hasField($k) && !$SNG->hasMethod('get' . $k) && !$SNG->hasMethod($k) && !strpos($k, "."))
$query->select[] = "`$k`"; $query->select[] = "\"$k\"";
} }
} }
@ -487,7 +487,7 @@ JS
// Add more selected fields if they are from joined table. // Add more selected fields if they are from joined table.
foreach($this->FieldList() as $k=>$title){ foreach($this->FieldList() as $k=>$title){
if(singleton($this->sourceClass)->hasDatabaseField($k)) if(singleton($this->sourceClass)->hasDatabaseField($k))
$query->select[] = "`$k`"; $query->select[] = "\"$k\"";
} }
} }
return clone $query; return clone $query;

View File

@ -34,14 +34,14 @@ class UniqueTextField extends TextField {
// if the restrictedFields and tables have been specified, // if the restrictedFields and tables have been specified,
// then get the restricted values // then get the restricted values
if( !empty( $this->restrictedField ) && !empty( $this->restrictedTable ) ) { if( !empty( $this->restrictedField ) && !empty( $this->restrictedTable ) ) {
$result = DB::query("SELECT `{$this->restrictedField}` FROM `{$this->restrictedTable}`"); $result = DB::query("SELECT \"{$this->restrictedField}\" FROM \"{$this->restrictedTable}\"");
$count = 1; $count = 1;
while( $restrictedValue = $result->nextRecord() ) while( $restrictedValue = $result->nextRecord() )
$restrictedValues[$restrictedValue[$this->restrictedField]] = 1; $restrictedValues[$restrictedValue[$this->restrictedField]] = 1;
$result = DB::query("SELECT `{$this->restrictedField}` FROM `{$this->restrictedTable}_Live`"); $result = DB::query("SELECT \"{$this->restrictedField}\" FROM \"{$this->restrictedTable}_Live\"");
while( $restrictedValue = $result->nextRecord() ) while( $restrictedValue = $result->nextRecord() )
$restrictedValues[$restrictedValue[$this->restrictedField]] = 1; $restrictedValues[$restrictedValue[$this->restrictedField]] = 1;

View File

@ -85,10 +85,10 @@ class SearchContext extends Object {
*/ */
protected function applyBaseTableFields() { protected function applyBaseTableFields() {
$classes = ClassInfo::dataClassesFor($this->modelClass); $classes = ClassInfo::dataClassesFor($this->modelClass);
$fields = array("`".ClassInfo::baseDataClass($this->modelClass).'`.*'); $fields = array("\"".ClassInfo::baseDataClass($this->modelClass).'".*');
if($this->modelClass != $classes[0]) $fields[] = '`'.$classes[0].'`.*'; if($this->modelClass != $classes[0]) $fields[] = '"'.$classes[0].'".*';
//$fields = array_keys($model->db()); //$fields = array_keys($model->db());
$fields[] = '`'.$classes[0].'`.ClassName AS RecordClassName'; $fields[] = '"'.$classes[0].'".ClassName AS RecordClassName';
return $fields; return $fields;
} }

View File

@ -175,14 +175,14 @@ class SearchForm extends Form {
$baseClass = reset($queryContent->from); $baseClass = reset($queryContent->from);
// There's no need to do all that joining // There's no need to do all that joining
$queryContent->from = array(str_replace('`','',$baseClass) => $baseClass); $queryContent->from = array(str_replace(array('`','"'),'',$baseClass) => $baseClass);
$queryContent->select = array("ClassName","$baseClass.ID","ParentID","Title","URLSegment","Content","LastEdited","Created","_utf8'' AS Filename", "_utf8'' AS Name", "$relevanceContent AS Relevance", "CanViewType"); $queryContent->select = array("ClassName","$baseClass.ID","ParentID","Title","URLSegment","Content","LastEdited","Created","_utf8'' AS Filename", "_utf8'' AS Name", "$relevanceContent AS Relevance", "CanViewType");
$queryContent->orderby = null; $queryContent->orderby = null;
$queryFiles = singleton('File')->extendedSQL($notMatch . $matchFile . $fileFilter, ""); $queryFiles = singleton('File')->extendedSQL($notMatch . $matchFile . $fileFilter, "");
$baseClass = reset($queryFiles->from); $baseClass = reset($queryFiles->from);
// There's no need to do all that joining // There's no need to do all that joining
$queryFiles->from = array(str_replace('`','',$baseClass) => $baseClass); $queryFiles->from = array(str_replace(array('`','"'),'',$baseClass) => $baseClass);
$queryFiles->select = array("ClassName","$baseClass.ID","_utf8'' AS ParentID","Title","_utf8'' AS URLSegment","Content","LastEdited","Created","Filename","Name","$relevanceFile AS Relevance","NULL AS CanViewType"); $queryFiles->select = array("ClassName","$baseClass.ID","_utf8'' AS ParentID","Title","_utf8'' AS URLSegment","Content","LastEdited","Created","Filename","Name","$relevanceFile AS Relevance","NULL AS CanViewType");
$queryFiles->orderby = null; $queryFiles->orderby = null;

View File

@ -123,22 +123,22 @@ abstract class SearchFilter extends Object {
if ($component = $model->has_one($rel)) { if ($component = $model->has_one($rel)) {
if(!$query->isJoinedTo($component)) { if(!$query->isJoinedTo($component)) {
$foreignKey = $model->getReverseAssociation($component); $foreignKey = $model->getReverseAssociation($component);
$query->leftJoin($component, "`$component`.`ID` = `{$this->model}`.`{$foreignKey}ID`"); $query->leftJoin($component, "\"$component\".\"ID\" = \"{$this->model}\".\"{$foreignKey}ID\"");
} }
$this->model = $component; $this->model = $component;
} elseif ($component = $model->has_many($rel)) { } elseif ($component = $model->has_many($rel)) {
if(!$query->isJoinedTo($component)) { if(!$query->isJoinedTo($component)) {
$ancestry = $model->getClassAncestry(); $ancestry = $model->getClassAncestry();
$foreignKey = $model->getComponentJoinField($rel); $foreignKey = $model->getComponentJoinField($rel);
$query->leftJoin($component, "`$component`.`{$foreignKey}` = `{$ancestry[0]}`.`ID`"); $query->leftJoin($component, "\"$component\".\"{$foreignKey}\" = \"{$ancestry[0]}\".\"ID\"");
} }
$this->model = $component; $this->model = $component;
} elseif ($component = $model->many_many($rel)) { } elseif ($component = $model->many_many($rel)) {
list($parentClass, $componentClass, $parentField, $componentField, $relationTable) = $component; list($parentClass, $componentClass, $parentField, $componentField, $relationTable) = $component;
$parentBaseClass = ClassInfo::baseDataClass($parentClass); $parentBaseClass = ClassInfo::baseDataClass($parentClass);
$componentBaseClass = ClassInfo::baseDataClass($componentClass); $componentBaseClass = ClassInfo::baseDataClass($componentClass);
$query->innerJoin($relationTable, "`$relationTable`.`$parentField` = `$parentBaseClass`.`ID`"); $query->innerJoin($relationTable, "\"$relationTable\".\"$parentField\" = \"$parentBaseClass\".\"ID\"");
$query->leftJoin($componentClass, "`$relationTable`.`$componentField` = `$componentClass`.`ID`"); $query->leftJoin($componentClass, "\"$relationTable\".\"$componentField\" = \"$componentClass\".\"ID\"");
$this->model = $componentClass; $this->model = $componentClass;
} }
} }

View File

@ -168,8 +168,8 @@ class Group extends DataObject {
// Get all of groups that this group contains // Get all of groups that this group contains
$groupFamily = implode(", ", $this->collateFamilyIDs()); $groupFamily = implode(", ", $this->collateFamilyIDs());
$filter[] = "`$table`.GroupID IN ($groupFamily)"; $filter[] = "\"$table\".GroupID IN ($groupFamily)";
$join .= " INNER JOIN `$table` ON `$table`.MemberID = `Member`.ID" . Convert::raw2sql($join); $join .= " INNER JOIN \"$table\" ON \"$table\".MemberID = \"Member\".ID" . Convert::raw2sql($join);
$result = singleton("Member")->instance_get( $result = singleton("Member")->instance_get(
$filter, $filter,
@ -248,7 +248,7 @@ class Group extends DataObject {
* Override this so groups are ordered in the CMS * Override this so groups are ordered in the CMS
*/ */
public function stageChildren() { public function stageChildren() {
return DataObject::get('Group', "`Group`.`ParentID` = " . (int)$this->ID . " AND `Group`.ID != " . (int)$this->ID, "Sort"); return DataObject::get('Group', "\"Group\".\"ParentID\" = " . (int)$this->ID . " AND \"Group\".ID != " . (int)$this->ID, "Sort");
} }
public function TreeTitle() { public function TreeTitle() {

View File

@ -273,7 +273,7 @@ class Member extends DataObject {
do { do {
$hash = substr(base_convert(md5(uniqid(mt_rand(), true)), 16, 36), $hash = substr(base_convert(md5(uniqid(mt_rand(), true)), 16, 36),
0, 30); 0, 30);
} while(DataObject::get_one('Member', "`AutoLoginHash` = '$hash'")); } while(DataObject::get_one('Member', "\"AutoLoginHash\" = '$hash'"));
$this->AutoLoginHash = $hash; $this->AutoLoginHash = $hash;
$this->AutoLoginExpired = date('Y-m-d', time() + (86400 * $lifetime)); $this->AutoLoginExpired = date('Y-m-d', time() + (86400 * $lifetime));
@ -289,8 +289,8 @@ class Member extends DataObject {
static function member_from_autologinhash($RAW_hash, $login = false) { static function member_from_autologinhash($RAW_hash, $login = false) {
$SQL_hash = Convert::raw2sql($RAW_hash); $SQL_hash = Convert::raw2sql($RAW_hash);
$member = DataObject::get_one('Member',"`AutoLoginHash`='" . $SQL_hash . $member = DataObject::get_one('Member',"\"AutoLoginHash\"='" . $SQL_hash .
"' AND `AutoLoginExpired` > NOW()"); "' AND \"AutoLoginExpired\" > NOW()");
if($login && $member) if($login && $member)
$member->logIn(); $member->logIn();
@ -449,7 +449,7 @@ class Member extends DataObject {
if($this->Email) { if($this->Email) {
if($this->ID) { if($this->ID) {
$idClause = "AND `Member`.ID <> $this->ID"; $idClause = "AND \"Member\".ID <> $this->ID";
} else { } else {
$idClause = ""; $idClause = "";
} }
@ -649,7 +649,7 @@ class Member extends DataObject {
if(count($collatedGroups) > 0) { if(count($collatedGroups) > 0) {
$collatedGroups = implode(", ", array_unique($collatedGroups)); $collatedGroups = implode(", ", array_unique($collatedGroups));
$unfilteredGroups = singleton('Group')->instance_get("`ID` IN ($collatedGroups)", "ID", "", "", "Member_GroupSet"); $unfilteredGroups = singleton('Group')->instance_get("\"ID\" IN ($collatedGroups)", "ID", "", "", "Member_GroupSet");
$result = new ComponentSet(); $result = new ComponentSet();
// Only include groups where allowedIPAddress() returns true // Only include groups where allowedIPAddress() returns true
@ -721,8 +721,8 @@ class Member extends DataObject {
return Member::map(); return Member::map();
return new SQLMap(singleton('Member')->extendedSQL( return new SQLMap(singleton('Member')->extendedSQL(
"`GroupID` IN (" . implode( ',', $groupIDList ) . "\"GroupID\" IN (" . implode( ',', $groupIDList ) .
")", "Surname, FirstName", "", "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`")); ")", "Surname, FirstName", "", "INNER JOIN \"Group_Members\" ON \"MemberID\"=\"Member\".\"ID\""));
} }
@ -749,7 +749,7 @@ class Member extends DataObject {
$SQL_perms = "'" . implode("', '", Convert::raw2sql($perms)) . "'"; $SQL_perms = "'" . implode("', '", Convert::raw2sql($perms)) . "'";
$groups = DataObject::get('Group', "", "", $groups = DataObject::get('Group', "", "",
"INNER JOIN `Permission` ON `Permission`.GroupID = `Group`.ID AND `Permission`.Code IN ($SQL_perms)"); "INNER JOIN \"Permission\" ON \"Permission\".GroupID = \"Group\".ID AND \"Permission\".Code IN ($SQL_perms)");
} }
$groupIDList = array(); $groupIDList = array();
@ -765,12 +765,12 @@ class Member extends DataObject {
return Member::map(); */ return Member::map(); */
$filterClause = ($groupIDList) $filterClause = ($groupIDList)
? "`GroupID` IN (" . implode( ',', $groupIDList ) . ")" ? "\"GroupID\" IN (" . implode( ',', $groupIDList ) . ")"
: ""; : "";
return new SQLMap(singleton('Member')->extendedSQL($filterClause, return new SQLMap(singleton('Member')->extendedSQL($filterClause,
"Surname, FirstName", "", "Surname, FirstName", "",
"INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID` INNER JOIN `Group` ON `Group`.`ID`=`GroupID`")); "INNER JOIN \"Group_Members\" ON \"MemberID\"=\"Member\".\"ID\" INNER JOIN \"Group\" ON \"Group\".\"ID\"=\"GroupID\""));
} }

View File

@ -321,7 +321,7 @@ class Permission extends DataObject {
// Add default content if blank // Add default content if blank
if(!DB::query("SELECT ID FROM Permission")->value() && array_key_exists('CanCMSAdmin', DB::fieldList('Group'))) { if(!DB::query("SELECT ID FROM Permission")->value() && array_key_exists('CanCMSAdmin', DB::fieldList('Group'))) {
$admins = DB::query("SELECT ID FROM `Group` WHERE CanCMSAdmin = 1") $admins = DB::query("SELECT ID FROM \"Group\" WHERE CanCMSAdmin = 1")
->column(); ->column();
if(isset($admins)) { if(isset($admins)) {
@ -329,7 +329,7 @@ class Permission extends DataObject {
Permission::grant($admin, "ADMIN"); Permission::grant($admin, "ADMIN");
} }
$authors = DB::query("SELECT ID FROM `Group` WHERE CanCMS = 1") $authors = DB::query("SELECT ID FROM \"Group\" WHERE CanCMS = 1")
->column(); ->column();
if(isset($authors)) { if(isset($authors)) {
foreach($authors as $author) { foreach($authors as $author) {
@ -363,7 +363,7 @@ class Permission extends DataObject {
'Group', 'Group',
$SQL_filter, // filter $SQL_filter, // filter
null, // limit null, // limit
"LEFT JOIN `Permission` ON `Group`.`ID` = `Permission`.`GroupID`" "LEFT JOIN \"Permission\" ON \"Group\".\"ID\" = \"Permission\".\"GroupID\""
); );
if(!$toplevelGroups) if(!$toplevelGroups)
return false; return false;
@ -380,10 +380,10 @@ class Permission extends DataObject {
$members = DataObject::get( $members = DataObject::get(
Object::getCustomClass('Member'), Object::getCustomClass('Member'),
$_filter = "`Group`.ID IN (" . implode(",",$groupIDs) . ")", $_filter = "\"Group\".ID IN (" . implode(",",$groupIDs) . ")",
$_sort = "", $_sort = "",
$_join = "LEFT JOIN `Group_Members` ON `Member`.`ID` = `Group_Members`.`MemberID` " . $_join = "LEFT JOIN \"Group_Members\" ON \"Member\".\"ID\" = \"Group_Members\".\"MemberID\" " .
"LEFT JOIN `Group` ON `Group_Members`.`GroupID` = `Group`.`ID` " "LEFT JOIN \"Group\" ON \"Group_Members\".\"GroupID\" = \"Group\".\"ID\" "
); );
return $members; return $members;
} }

View File

@ -581,10 +581,10 @@ class Security extends Controller {
* privileges. * privileges.
*/ */
static function findAnAdministrator($username = 'admin', $password = 'password') { static function findAnAdministrator($username = 'admin', $password = 'password') {
$permission = DataObject::get_one("Permission", "`Code` = 'ADMIN'", true, "ID"); $permission = DataObject::get_one("Permission", "\"Code\" = 'ADMIN'", true, "ID");
$adminGroup = null; $adminGroup = null;
if($permission) $adminGroup = DataObject::get_one("Group", "`Group`.`ID` = '{$permission->GroupID}'", true, "`Group`.`ID`"); if($permission) $adminGroup = DataObject::get_one("Group", "\"Group\".\"ID\" = '{$permission->GroupID}'", true, "\"Group\".\"ID\"");
if($adminGroup) { if($adminGroup) {
if($adminGroup->Members()->First()) { if($adminGroup->Members()->First()) {

View File

@ -21,8 +21,8 @@ class UpgradeSiteTreePermissionSchemaTask extends BuildTask {
function run($request) { function run($request) {
// transfer values for changed column name // transfer values for changed column name
foreach(array('SiteTree','SiteTree_Live','SiteTree_versions') as $table) { foreach(array('SiteTree','SiteTree_Live','SiteTree_versions') as $table) {
DB::query("UPDATE `{$table}` SET CanViewType = Viewers;"); DB::query("UPDATE \"{$table}\" SET CanViewType = Viewers;");
DB::query("UPDATE `{$table}` SET CanEditType = Editors;"); DB::query("UPDATE \"{$table}\" SET CanEditType = Editors;");
} }
//Debug::message('Moved SiteTree->Viewers to SiteTree->CanViewType'); //Debug::message('Moved SiteTree->Viewers to SiteTree->CanViewType');
//Debug::message('Moved SiteTree->Editors to SiteTree->CanEditType'); //Debug::message('Moved SiteTree->Editors to SiteTree->CanEditType');

View File

@ -72,7 +72,7 @@ class DataObjectTest extends SapphireTest {
$this->assertEquals('Joe', $comments->First()->Name); $this->assertEquals('Joe', $comments->First()->Name);
// Test join // Test join
$comments = DataObject::get('PageComment', "`SiteTree`.Title='First Page'", '', 'INNER JOIN SiteTree ON PageComment.ParentID = SiteTree.ID'); $comments = DataObject::get('PageComment', "\"SiteTree\".Title='First Page'", '', 'INNER JOIN SiteTree ON PageComment.ParentID = SiteTree.ID');
$this->assertEquals(2, $comments->Count()); $this->assertEquals(2, $comments->Count());
$this->assertEquals('Bob', $comments->First()->Name); $this->assertEquals('Bob', $comments->First()->Name);
$this->assertEquals('Bob', $comments->Last()->Name); $this->assertEquals('Bob', $comments->Last()->Name);