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) {
$baseClass = ClassInfo::baseDataClass($className);
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) {
$versionedQuery = new SQLQuery (
'RecordID', 'SiteTree_versions',
"`WasPublished` = 1 AND `URLSegment` = '$urlSegment'",
'`LastEdited` DESC, `WasPublished`',
"\"WasPublished\" = 1 AND \"URLSegment\" = '$urlSegment'",
'"LastEdited" DESC, "WasPublished"',
null, null, 1
);

View File

@ -128,14 +128,14 @@ class ComponentSet extends DataObjectSet {
$parentField = $this->ownerClass . '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 = '';
if($extraFields) foreach($extraFields as $k => $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 {
$parentField = $this->ownerClass . '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);
$parentField = $this->ownerClass . '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) {
$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() {
if(!empty($this->tableName)) {
$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 {
foreach($this->items as $item) {
$this->remove($item);

View File

@ -789,7 +789,7 @@ class DataObjectSet extends ViewableData implements IteratorAggregate {
$parentSet = array();
// 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...
foreach($parents as $parent) {
@ -815,7 +815,7 @@ class DataObjectSet extends ViewableData implements IteratorAggregate {
if(empty($parentStack)) {
$newParent = new DataObjectSet();
} 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
@ -839,7 +839,7 @@ class DataObjectSet extends ViewableData implements IteratorAggregate {
if(empty($requiredIDs)) {
$parentSet = new DataObjectSet();
} else {
$parentSet = DataObject::get( $groupClassName, "`$groupClassName`.`$parentField` IN( " . implode( ",", $requiredIDs ) . ")", $sortParents );
$parentSet = DataObject::get( $groupClassName, "\"$groupClassName\".\"$parentField\" IN( " . implode( ",", $requiredIDs ) . ")", $sortParents );
}
$parentSet = $parentSet->toArray();

View File

@ -335,7 +335,7 @@ abstract class Database extends Object {
$default = explode('default ', $spec);
$default = $default[1];
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++) {
$query .= "'{$holder[$i]}', ";
}
@ -384,7 +384,7 @@ abstract class Database extends Object {
if(isset($writeInfo['fields']) && $writeInfo['fields']) {
$fieldList = array();
foreach($writeInfo['fields'] as $fieldName => $fieldVal) {
$fieldList[] = "`$fieldName` = $fieldVal";
$fieldList[] = "\"$fieldName\" = $fieldVal";
}
$fieldList = implode(", ", $fieldList);
@ -394,7 +394,7 @@ abstract class Database extends Object {
switch($writeInfo['command']) {
case "update":
$sql = "update `$table` SET $fieldList where $writeInfo[where]";
$sql = "update \"$table\" SET $fieldList where $writeInfo[where]";
$this->query($sql);
// 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'])) {
$fieldList .= ", ID = $writeInfo[id]";
}
$sql = "insert into `$table` SET $fieldList";
$sql = "insert into \"$table\" SET $fieldList";
$this->query($sql, null);
}
break;
@ -412,7 +412,7 @@ abstract class Database extends Object {
$fieldList .= ", ID = $writeInfo[id]";
}
$fieldList = Database::replace_with_null($fieldList);
$sql = "insert into `$table` SET $fieldList";
$sql = "insert into \"$table\" SET $fieldList";
$this->query($sql);
break;

View File

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

View File

@ -410,11 +410,11 @@ class Hierarchy extends DataObjectDecorator {
DataObject::disable_subclass_access();
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)) {
$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();
@ -477,7 +477,7 @@ class Hierarchy extends DataObjectDecorator {
public function numChildren() {
$baseClass = ClassInfo::baseDataClass($this->owner->class);
// 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);
return $query->execute()->value();
}
@ -490,7 +490,7 @@ class Hierarchy extends DataObjectDecorator {
public function stageChildren($showAll = false) {
$extraFilter = $showAll ? '' : " AND ShowInMenus = 1";
$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) {
$extraFilter = $showAll ? '' : " AND ShowInMenus = 1";
$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 = '') {
if($p = $this->owner->__get("ParentID")) {
$className = $this->owner->class;
$filter .= $filter?" AND ":""."`$className`.ID = $p";
$filter .= $filter?" AND ":""."\"$className\".ID = $p";
return DataObject::get_one($className, $filter);
}
}
@ -552,11 +552,11 @@ class Hierarchy extends DataObjectDecorator {
if(!$afterNode || $afterNode->ParentID != $this->owner->ID) {
$children = $this->AllChildren();
} 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
/*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 );*/
if($children) {

View File

@ -117,7 +117,7 @@ class MySQLDatabase extends Database {
*/
public function getNextID($table) {
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;
}
@ -174,10 +174,10 @@ class MySQLDatabase extends Database {
public function createTable($tableName, $fields = null, $indexes = null) {
$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";
$this->query("CREATE TABLE `$tableName` (
$this->query("CREATE TABLE \"$tableName\" (
ID int(11) not null auto_increment,
$fieldSchemas
$indexSchemas
@ -196,20 +196,20 @@ class MySQLDatabase extends Database {
public function alterTable($tableName, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null) {
$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($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) {
$alterList[] .= "DROP INDEX `$k`";
$alterList[] .= "DROP INDEX \"$k\"";
$alterList[] .= "ADD ". $this->getIndexSqlDefinition($k, $v);
}
$alterations = implode(",\n", $alterList);
$this->query("ALTER TABLE `$tableName` " . $alterations);
$this->query("ALTER TABLE \"$tableName\" " . $alterations);
}
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.
*/
public function checkAndRepairTable($tableName) {
if(!$this->runTableCheckCommand("CHECK TABLE `$tableName`")) {
if(!$this->runTableCheckCommand("CHECK TABLE \"$tableName\"")) {
Database::alteration_message("Table $tableName: repaired","repaired");
return $this->runTableCheckCommand("REPAIR TABLE `$tableName` USE_FRM");
return $this->runTableCheckCommand("REPAIR TABLE \"$tableName\" USE_FRM");
} else {
return true;
}
@ -244,7 +244,7 @@ class MySQLDatabase extends Database {
}
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
*/
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) {
$fieldList = $this->fieldList($tableName);
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) {
$fields = DB::query("SHOW FULL FIELDS IN `$table`");
$fields = DB::query("SHOW FULL FIELDS IN \"$table\"");
foreach($fields as $field) {
$fieldSpec = $field['Type'];
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.
*/
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) {
@ -311,7 +311,7 @@ class MySQLDatabase extends Database {
if(!isset($indexType)) {
$indexType = "index";
}
return "$indexType `$indexName` $indexFields";
return "$indexType \"$indexName\" $indexFields";
}
/**
@ -332,8 +332,8 @@ class MySQLDatabase extends Database {
$indexType = "index";
}
$this->query("ALTER TABLE `$tableName` DROP INDEX `$indexName`");
$this->query("ALTER TABLE `$tableName` ADD $indexType `$indexName` $indexFields");
$this->query("ALTER TABLE \"$tableName\" DROP INDEX \"$indexName\"");
$this->query("ALTER TABLE \"$tableName\" ADD $indexType \"$indexName\" $indexFields");
}
/**
@ -342,7 +342,7 @@ class MySQLDatabase extends Database {
* @return array
*/
public function indexList($table) {
$indexes = DB::query("SHOW INDEXES IN `$table`");
$indexes = DB::query("SHOW INDEXES IN \"$table\"");
foreach($indexes as $index) {
$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) {
$fieldSchemas = $indexSchemas = "";
if ($fields) {
foreach($fields as $k => $v) $fieldSchemas .= "`$k` $v,\n";
foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n";
}
switch (self::getDatabaseServer()) {
@ -363,11 +363,11 @@ class PDODatabase extends Database {
*/
public function checkAndRepairTable($tableName) {
if ($parameters['type'] == "mysql") {
if (!$this->runTableCheckCommand("CHECK TABLE `$tableName`")) {
if (!$this->runTableCheckCommand("CHECK TABLE \"$tableName\"")) {
if(!Database::$supressOutput) {
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 {
return true;
}

View File

@ -484,7 +484,7 @@ class SiteTree extends DataObject {
*/
public function getParent() {
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
$idFilter = ($this->ID)
? " AND `SiteTree`.ID <> '$this->ID'" :
? " AND \"SiteTree\".ID <> '$this->ID'" :
'';
$count = 1;
@ -1364,7 +1364,7 @@ class SiteTree extends DataObject {
* Publish this page
*/
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();
// Handle activities undertaken by decorators
@ -1454,7 +1454,7 @@ class SiteTree extends DataObject {
if($this->isNew())
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
: false;
}

View File

@ -225,7 +225,7 @@ class Translatable extends DataObjectDecorator {
$langsAvailable[] = self::default_lang();
$lang = self::choose_site_lang($langsAvailable);
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) {
self::set_reading_lang($lang);
$record = $transrecord;
@ -265,7 +265,7 @@ class Translatable extends DataObjectDecorator {
static function get_original($class, $originalLangID) {
$baseClass = $class;
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
*/
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();
return ($langs) ? array_values($langs) : false;
}
@ -360,8 +360,8 @@ class Translatable extends DataObjectDecorator {
if (stripos($query->sql(),'.ID')) {
// Every reference to ID is now OriginalLangID
$query->replaceText(".ID",".OriginalLangID");
$query->where = str_replace("`ID`", "`OriginalLangID`",$query->where);
$query->select[] = "`{$baseTable}_lang`.OriginalLangID AS ID";
$query->where = str_replace("\"ID\"", "\"OriginalLangID\"",$query->where);
$query->select[] = "\"{$baseTable}_lang\".OriginalLangID AS ID";
}
if ($query->where) foreach ($query->where as $i => $wherecl) {
if (substr($wherecl,0,4) == 'ID =')
@ -371,18 +371,18 @@ class Translatable extends DataObjectDecorator {
$parts = explode(' AND ',$wherecl);
foreach ($parts as $j => $part) {
// 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)
//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 {
/* 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
* that is not a translatable field)
*/
$clauseparts = explode('.',$innerparts[1]);
$originalTable = str_replace('`','',str_replace('_lang','',$clauseparts[0]));
$parts[$j] = ($this->isInAugmentedTable($clauseparts[1], $originalTable) ? "`{$originalTable}_lang`" : "`$originalTable`")
$originalTable = str_replace('\"','',str_replace('_lang','',$clauseparts[0]));
$parts[$j] = ($this->isInAugmentedTable($clauseparts[1], $originalTable) ? "\"{$originalTable}_lang\"" : "\"$originalTable\"")
. ".{$clauseparts[1]}{$innerparts[2]}";
}
}
@ -398,19 +398,19 @@ class Translatable extends DataObjectDecorator {
}
// 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
if (!$query->delete) {
$query->from[$table] = "INNER JOIN `$table`".
" ON `{$table}_lang`.OriginalLangID = `$table`.ID";
$query->from[$table] = "INNER JOIN \"$table\"".
" ON \"{$table}_lang\".OriginalLangID = \"$table\".ID";
/* 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
*/
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 {
$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
*/
function isInAugmentedTable($clause, $table) {
$clause = str_replace('`','',$clause);
$clause = str_replace('\"','',$clause);
$table = str_replace('_lang','',$table);
if (strpos($table,'_') !== false) return false;
$field = ereg_replace('[[:blank:]]*([[:alnum:]]*).*','\\1',$clause);
@ -587,7 +587,7 @@ class Translatable extends DataObjectDecorator {
$originalRecord = self::get_one_by_lang(
$this->owner->class,
self::$default_lang,
"`$baseClass`.ID = ".$originalLangID
"\"$baseClass\".ID = ".$originalLangID
);
$this->original_values = $originalRecord->getAllFields();
$alltasks = array( 'dup' => array());

View File

@ -65,18 +65,18 @@ class Versioned extends DataObjectDecorator {
}
$query->renameTable($table, $table . '_versions');
$query->replaceText(".ID", ".RecordID");
$query->select[] = "`{$baseTable}_versions`.RecordID AS ID";
$query->select[] = "\"{$baseTable}_versions\".RecordID AS ID";
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
$this->requireArchiveTempTable($baseTable, $date);
$query->from["_Archive$baseTable"] = "INNER JOIN `_Archive$baseTable`
ON `_Archive$baseTable`.RecordID = `{$baseTable}_versions`.RecordID
AND `_Archive$baseTable`.Version = `{$baseTable}_versions`.Version";
$query->from["_Archive$baseTable"] = "INNER JOIN \"_Archive$baseTable\"
ON \"_Archive$baseTable\".RecordID = \"{$baseTable}_versions\".RecordID
AND \"_Archive$baseTable\".Version = \"{$baseTable}_versions\".Version";
// Get a specific stage
} 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()) {
$fieldList = implode(", ",array_keys($fields));
DB::query("INSERT INTO `{$table}_$stage` (ID,$fieldList)
SELECT ID,$fieldList FROM `$table`");
DB::query("INSERT INTO \"{$table}_$stage\" (ID,$fieldList)
SELECT ID,$fieldList FROM \"$table\"");
}
*/
}
@ -217,8 +217,8 @@ class Versioned extends DataObjectDecorator {
if(!DB::query("SELECT * FROM {$table}_versions")->value()) {
$fieldList = implode(", ",array_keys($fields));
DB::query("INSERT INTO `{$table}_versions` ($fieldList, RecordID, Version)
SELECT $fieldList, ID AS RecordID, 1 AS Version FROM `$table`");
DB::query("INSERT INTO \"{$table}_versions\" ($fieldList, RecordID, Version)
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);
} else {
$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;
@ -395,7 +395,7 @@ class Versioned extends DataObjectDecorator {
if(!$createNewVersion) $from->migrateVersion($from->Version);
// 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;
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
$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;
}
@ -447,14 +447,14 @@ class Versioned extends DataObjectDecorator {
$query = $this->owner->extendedSQL($filter,"");
foreach($query->from as $table => $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";
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";
$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->orderby = "`{$baseTable}_versions`.LastEdited DESC, `{$baseTable}_versions`.Version DESC";
$query->where[] = "\"{$baseTable}_versions\".RecordID = '{$this->owner->ID}'";
$query->orderby = "\"{$baseTable}_versions\".LastEdited DESC, \"{$baseTable}_versions\".Version DESC";
$records = $query->execute();
@ -630,22 +630,22 @@ class Versioned extends DataObjectDecorator {
function buildVersionSQL($filter = "", $sort = "") {
$query = $this->owner->extendedSQL($filter,$sort);
foreach($query->from as $table => $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";
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";
$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;
}
static function build_version_sql($className, $filter = "", $sort = "") {
$query = singleton($className)->extendedSQL($filter,$sort);
foreach($query->from as $table => $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";
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";
$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;
}
@ -657,7 +657,7 @@ class Versioned extends DataObjectDecorator {
Versioned::$reading_stage = null;
$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;
$record = $query->execute()->record();
$className = $record['ClassName'];
@ -677,7 +677,7 @@ class Versioned extends DataObjectDecorator {
Versioned::$reading_stage = null;
$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();
$className = $record['ClassName'];
if(!$className) {
@ -693,7 +693,7 @@ class Versioned extends DataObjectDecorator {
static function get_all_versions($class, $id, $version) {
$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();
$className = $record[ClassName];
if(!$className) {

View File

@ -102,7 +102,7 @@ class VirtualPage extends Page {
if(isset($this->changed['CopyContentFromID']) && $this->changed['CopyContentFromID']
&& $this->CopyContentFromID != 0 && $this->class == 'VirtualPage' ) {
$CopyContentFromID = $this->CopyContentFromID;
$source = DataObject::get_one("SiteTree","`SiteTree`.`ID`='$CopyContentFromID'");
$source = DataObject::get_one("SiteTree","\"SiteTree\".\"ID\"='$CopyContentFromID'");
$this->copyFrom($source);
$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);
}
$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;
} elseif(is_array($duplicateCheck) && isset($duplicateCheck['callback'])) {
$existingRecord = singleton($this->objectClass)->{$duplicateCheck['callback']}($record[$fieldName], $record);

View File

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

View File

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

View File

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

View File

@ -43,19 +43,19 @@ class Folder extends File {
$deleted = 0;
// 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) {
$childName = addslashes($childName);
// 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) {
$keptChild = array_shift($children);
foreach($children as $removedChild) {
DB::query("UPDATE `File` SET ParentID = $keptChild WHERE ParentID = $removedChild");
DB::query("DELETE FROM `File` WHERE ID = $removedChild");
DB::query("UPDATE \"File\" SET ParentID = $keptChild WHERE ParentID = $removedChild");
DB::query("DELETE FROM \"File\" WHERE ID = $removedChild");
}
} 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];
if( ($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]);
}
}
@ -117,11 +117,11 @@ class Folder extends File {
// Iterate through the unwanted children, removing them all
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++;
}
} 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);
@ -154,7 +154,7 @@ class Folder extends File {
$name = addslashes($name);
DB::query("INSERT INTO `File` SET
DB::query("INSERT INTO \"File\" SET
ClassName = '$className', ParentID = $this->ID, OwnerID = $ownerID,
Name = '$name', Filename = '$filename', Created = NOW(), LastEdited = NOW(),
Title = '$name'");
@ -433,7 +433,7 @@ class Folder extends File {
}
if($where == "") return "(ClassName = 'File' OR ClassName = 'Image')";
$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;
}

View File

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

View File

@ -219,7 +219,7 @@ class ComplexTableField extends TableListField {
&& ($filterKey = $this->getParentIdName($this->getParentClass(), $this->sourceClass()))
&& ($filterValue = $this->sourceID()) ) {
$newFilter = "`$filterKey` = '" . Convert::raw2sql($filterValue) . "'";
$newFilter = "\"$filterKey\" = '" . Convert::raw2sql($filterValue) . "'";
if($sourceFilter && is_array($sourceFilter)) {
// 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) {
return DataObject::get($this->controllerClass(), '`' . $this->joinField . "` = '$childID'");
return DataObject::get($this->controllerClass(), '"' . $this->joinField . "\" = '$childID'");
}
function ExtraData() {

View File

@ -37,7 +37,7 @@ class ManyManyComplexTableField extends HasManyComplexTableField {
$sourceField = 'Child';
$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';
}
@ -60,7 +60,7 @@ class ManyManyComplexTableField extends HasManyComplexTableField {
$query->select[] = $k;
}
$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;
}

View File

@ -182,7 +182,7 @@ HTML;
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() );
}
@ -229,7 +229,7 @@ HTML;
$joinKey = $this->primaryKeys[$className];
// 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 );
}
@ -264,7 +264,7 @@ HTML;
$tableColumns = array();
$selectFields = array();
$joins = array( "`{$this->primaryClass}`" );
$joins = array( "\"{$this->primaryClass}\"" );
foreach( $this->fields as $field ) {
if( $field{0} == '!' )
@ -274,9 +274,9 @@ HTML;
$tableColumns[$table][] = $column;
if( $column == '*' )
$selectFields[] = "`$table`.*";
$selectFields[] = "\"$table\".*";
else
$selectFields[] = "`$table`.`$column` AS '$table.$column'";
$selectFields[] = "\"$table\".\"$column\" AS '$table.$column'";
}
foreach( array_keys( $tableColumns ) as $table ) {
@ -284,7 +284,7 @@ HTML;
$primaryKey = $this->primaryKeys[$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 );

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($filterField) {
$this->filterValue = $sourceFilter;
$sourceFilter = "`$filterField` = '" . Convert::raw2sql($sourceFilter) . "'";
$sourceFilter = "\"$filterField\" = '" . Convert::raw2sql($sourceFilter) . "'";
}
parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin);

View File

@ -453,7 +453,7 @@ JS
$SNG = singleton($this->sourceClass);
foreach($this->FieldList() as $k=>$title){
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.
foreach($this->FieldList() as $k=>$title){
if(singleton($this->sourceClass)->hasDatabaseField($k))
$query->select[] = "`$k`";
$query->select[] = "\"$k\"";
}
}
return clone $query;

View File

@ -34,14 +34,14 @@ class UniqueTextField extends TextField {
// if the restrictedFields and tables have been specified,
// then get the restricted values
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;
while( $restrictedValue = $result->nextRecord() )
$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() )
$restrictedValues[$restrictedValue[$this->restrictedField]] = 1;

View File

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

View File

@ -175,14 +175,14 @@ class SearchForm extends Form {
$baseClass = reset($queryContent->from);
// 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->orderby = null;
$queryFiles = singleton('File')->extendedSQL($notMatch . $matchFile . $fileFilter, "");
$baseClass = reset($queryFiles->from);
// 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->orderby = null;

View File

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

View File

@ -168,8 +168,8 @@ class Group extends DataObject {
// Get all of groups that this group contains
$groupFamily = implode(", ", $this->collateFamilyIDs());
$filter[] = "`$table`.GroupID IN ($groupFamily)";
$join .= " INNER JOIN `$table` ON `$table`.MemberID = `Member`.ID" . Convert::raw2sql($join);
$filter[] = "\"$table\".GroupID IN ($groupFamily)";
$join .= " INNER JOIN \"$table\" ON \"$table\".MemberID = \"Member\".ID" . Convert::raw2sql($join);
$result = singleton("Member")->instance_get(
$filter,
@ -248,7 +248,7 @@ class Group extends DataObject {
* Override this so groups are ordered in the CMS
*/
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() {

View File

@ -273,7 +273,7 @@ class Member extends DataObject {
do {
$hash = substr(base_convert(md5(uniqid(mt_rand(), true)), 16, 36),
0, 30);
} while(DataObject::get_one('Member', "`AutoLoginHash` = '$hash'"));
} while(DataObject::get_one('Member', "\"AutoLoginHash\" = '$hash'"));
$this->AutoLoginHash = $hash;
$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) {
$SQL_hash = Convert::raw2sql($RAW_hash);
$member = DataObject::get_one('Member',"`AutoLoginHash`='" . $SQL_hash .
"' AND `AutoLoginExpired` > NOW()");
$member = DataObject::get_one('Member',"\"AutoLoginHash\"='" . $SQL_hash .
"' AND \"AutoLoginExpired\" > NOW()");
if($login && $member)
$member->logIn();
@ -449,7 +449,7 @@ class Member extends DataObject {
if($this->Email) {
if($this->ID) {
$idClause = "AND `Member`.ID <> $this->ID";
$idClause = "AND \"Member\".ID <> $this->ID";
} else {
$idClause = "";
}
@ -649,7 +649,7 @@ class Member extends DataObject {
if(count($collatedGroups) > 0) {
$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();
// Only include groups where allowedIPAddress() returns true
@ -721,8 +721,8 @@ class Member extends DataObject {
return Member::map();
return new SQLMap(singleton('Member')->extendedSQL(
"`GroupID` IN (" . implode( ',', $groupIDList ) .
")", "Surname, FirstName", "", "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`"));
"\"GroupID\" IN (" . implode( ',', $groupIDList ) .
")", "Surname, FirstName", "", "INNER JOIN \"Group_Members\" ON \"MemberID\"=\"Member\".\"ID\""));
}
@ -749,7 +749,7 @@ class Member extends DataObject {
$SQL_perms = "'" . implode("', '", Convert::raw2sql($perms)) . "'";
$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();
@ -765,12 +765,12 @@ class Member extends DataObject {
return Member::map(); */
$filterClause = ($groupIDList)
? "`GroupID` IN (" . implode( ',', $groupIDList ) . ")"
? "\"GroupID\" IN (" . implode( ',', $groupIDList ) . ")"
: "";
return new SQLMap(singleton('Member')->extendedSQL($filterClause,
"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
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();
if(isset($admins)) {
@ -329,7 +329,7 @@ class Permission extends DataObject {
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();
if(isset($authors)) {
foreach($authors as $author) {
@ -363,7 +363,7 @@ class Permission extends DataObject {
'Group',
$SQL_filter, // filter
null, // limit
"LEFT JOIN `Permission` ON `Group`.`ID` = `Permission`.`GroupID`"
"LEFT JOIN \"Permission\" ON \"Group\".\"ID\" = \"Permission\".\"GroupID\""
);
if(!$toplevelGroups)
return false;
@ -380,10 +380,10 @@ class Permission extends DataObject {
$members = DataObject::get(
Object::getCustomClass('Member'),
$_filter = "`Group`.ID IN (" . implode(",",$groupIDs) . ")",
$_filter = "\"Group\".ID IN (" . implode(",",$groupIDs) . ")",
$_sort = "",
$_join = "LEFT JOIN `Group_Members` ON `Member`.`ID` = `Group_Members`.`MemberID` " .
"LEFT JOIN `Group` ON `Group_Members`.`GroupID` = `Group`.`ID` "
$_join = "LEFT JOIN \"Group_Members\" ON \"Member\".\"ID\" = \"Group_Members\".\"MemberID\" " .
"LEFT JOIN \"Group\" ON \"Group_Members\".\"GroupID\" = \"Group\".\"ID\" "
);
return $members;
}

View File

@ -581,10 +581,10 @@ class Security extends Controller {
* privileges.
*/
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;
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->Members()->First()) {

View File

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

View File

@ -72,7 +72,7 @@ class DataObjectTest extends SapphireTest {
$this->assertEquals('Joe', $comments->First()->Name);
// 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('Bob', $comments->First()->Name);
$this->assertEquals('Bob', $comments->Last()->Name);