From a93a0c3c9559f4203ea14b1b61bf73fe8687a0d9 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Sun, 23 Nov 2008 00:31:13 +0000 Subject: [PATCH] Updated SQL queries to be ansi compatable git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@66402 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/AssetAdmin.php | 8 ++++---- code/AssetTableField.php | 2 +- code/CMSMain.php | 16 ++++++++-------- code/CommentAdmin.php | 8 ++++---- code/CommentTableField.php | 2 +- code/Diff.php | 2 +- code/LeftAndMain.php | 6 +++--- code/MemberTableField.php | 8 ++++---- code/SecurityAdmin.php | 2 +- code/SideReport.php | 4 ++-- code/WidgetAreaEditor.php | 4 ++-- code/staticpublisher/StaticPublisher.php | 2 +- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/code/AssetAdmin.php b/code/AssetAdmin.php index 018a7836..c0fdc967 100755 --- a/code/AssetAdmin.php +++ b/code/AssetAdmin.php @@ -237,7 +237,7 @@ JS $fileNames = array(); foreach($newFiles as $newFile) { $fileIDs[] = $newFile; - $fileObj = DataObject::get_one('File', "`File`.ID=$newFile"); + $fileObj = DataObject::get_one('File', "\"File\".ID=$newFile"); $fileNames[] = $fileObj->Name; } @@ -314,7 +314,7 @@ HTML; $numFiles = 0; if($fileList != "''") { - $files = DataObject::get("File", "`File`.ID IN ($fileList)"); + $files = DataObject::get("File", "\"File\".ID IN ($fileList)"); if($files) { foreach($files as $file) { if($file instanceof Image) { @@ -350,7 +350,7 @@ HTML; $brokenPageList = ''; if($fileList != "''") { - $files = DataObject::get("File", "`File`.ID IN ($fileList)"); + $files = DataObject::get("File", "\"File\".ID IN ($fileList)"); if($files) { foreach($files as $file) { if($file instanceof Image) { @@ -376,7 +376,7 @@ HTML; $deleteList = ''; if( $folderID ) { - $remaining = DB::query("SELECT COUNT(*) FROM `File` WHERE `ParentID`=$folderID")->value(); + $remaining = DB::query("SELECT COUNT(*) FROM \"File\" WHERE \"ParentID\" = $folderID")->value(); if( !$remaining ) $deleteList .= "Element.removeClassName(\$('sitetree').getTreeNodeByIdx( '$folderID' ).getElementsByTagName('a')[0],'contents');"; diff --git a/code/AssetTableField.php b/code/AssetTableField.php index cbf383d4..76e788a6 100755 --- a/code/AssetTableField.php +++ b/code/AssetTableField.php @@ -28,7 +28,7 @@ class AssetTableField extends ComplexTableField { if($SQL_search) { $searchFilters = array(); foreach($SNG_file->searchableFields() as $fieldName => $fieldSpec) { - if(strpos($fieldName, '.') === false) $searchFilters[] = "`$fieldName` LIKE '%{$SQL_search}%'"; + if(strpos($fieldName, '.') === false) $searchFilters[] = "\"$fieldName\" LIKE '%{$SQL_search}%'"; } $this->sourceFilter = '(' . implode(' OR ', $searchFilters) . ')'; } diff --git a/code/CMSMain.php b/code/CMSMain.php index 76c78e38..5a6306a3 100644 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -360,13 +360,13 @@ JS; $treeClass = $this->stat('tree_class'); if($id && is_numeric($id)) { - $record = DataObject::get_one( $treeClass, "`$treeClass`.ID = $id"); + $record = DataObject::get_one( $treeClass, "\"$treeClass\".ID = $id"); if(!$record) { - // $record = Versioned::get_one_by_stage($treeClass, "Live", "`$treeClass`.ID = $id"); + // $record = Versioned::get_one_by_stage($treeClass, "Live", "\"$treeClass\".ID = $id"); Versioned::reading_stage('Live'); singleton($treeClass)->flushCache(); - $record = DataObject::get_one( $treeClass, "`$treeClass`.ID = $id"); + $record = DataObject::get_one( $treeClass, "\"$treeClass\".ID = $id"); if($record) { $record->DeletedFromStage = true; } else { @@ -400,7 +400,7 @@ JS; $idField->setValue($id); if($record->ID && is_numeric( $record->ID ) ) { - $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "`SiteTree`.ID = $record->ID"); + $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".ID = $record->ID"); if($liveRecord) $liveURLField->setValue($liveRecord->AbsoluteLink()); } @@ -662,7 +662,7 @@ JS; if($groupIDs) { $groupList = implode(", ", $groupIDs); $members = DataObject::get("Member","","", - "INNER JOIN `Group_Members` ON `Group_Members`.MemberID = `Member`.ID AND `Group_Members`.GroupID IN ($groupList)"); + "INNER JOIN \"Group_Members\" ON \"Group_Members\".MemberID = \"Member\".ID AND \"Group_Members\".GroupID IN ($groupList)"); } if($members) { @@ -753,7 +753,7 @@ HTML; $pageID = $this->urlParams['ID']; $page = $this->getRecord($pageID); if($page) { - $versions = $page->allVersions($_REQUEST['unpublished'] ? "" : "`SiteTree`.WasPublished = 1"); + $versions = $page->allVersions($_REQUEST['unpublished'] ? "" : "\"SiteTree\".WasPublished = 1"); return array( 'Versions' => $versions, ); @@ -797,7 +797,7 @@ HTML; $JS_title = Convert::raw2js($page->TreeTitle()); $JS_stageURL = $page->DeletedFromStage ? '' : Convert::raw2js($page->AbsoluteLink()); - $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "`SiteTree`.ID = $page->ID"); + $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".ID = $page->ID"); $JS_liveURL = $liveRecord ? Convert::raw2js($liveRecord->AbsoluteLink()) : ''; FormResponse::add($this->getActionUpdateJS($page)); @@ -1075,7 +1075,7 @@ HTML; // check to see if the record exists on the live site, if it doesn't remove the tree node // $_REQUEST['showqueries'] = 1 ; - $liveRecord = Versioned::get_one_by_stage( $this->stat('tree_class'), 'Live', "`{$this->stat('tree_class')}`.`ID`={$id}"); + $liveRecord = Versioned::get_one_by_stage( $this->stat('tree_class'), 'Live', "\"{$this->stat('tree_class')}\".\"ID\"={$id}"); if($liveRecord) { $title = Convert::raw2js($record->TreeTitle()); diff --git a/code/CommentAdmin.php b/code/CommentAdmin.php index 1242b28a..4c915507 100644 --- a/code/CommentAdmin.php +++ b/code/CommentAdmin.php @@ -125,7 +125,7 @@ class CommentAdmin extends LeftAndMain { if($_REQUEST['Comments']) { foreach($_REQUEST['Comments'] as $commentid) { - $comment = DataObject::get_one('PageComment', "`PageComment`.ID = $commentid"); + $comment = DataObject::get_one('PageComment', "\"PageComment\".ID = $commentid"); if($comment) { $comment->delete(); $numComments++; @@ -169,7 +169,7 @@ JS; if($_REQUEST['Comments']) { foreach($_REQUEST['Comments'] as $commentid) { - $comment = DataObject::get_one('PageComment', "`PageComment`.ID = $commentid"); + $comment = DataObject::get_one('PageComment', "\"PageComment\".ID = $commentid"); if($comment) { $comment->IsSpam = true; $comment->NeedsModeration = false; @@ -208,7 +208,7 @@ JS; if($_REQUEST['Comments']) { foreach($_REQUEST['Comments'] as $commentid) { - $comment = DataObject::get_one('PageComment', "`PageComment`.ID = $commentid"); + $comment = DataObject::get_one('PageComment', "\"PageComment\".ID = $commentid"); if($comment) { $comment->IsSpam = false; $comment->NeedsModeration = false; @@ -248,7 +248,7 @@ JS; if($_REQUEST['Comments']) { foreach($_REQUEST['Comments'] as $commentid) { - $comment = DataObject::get_one('PageComment', "`PageComment`.ID = $commentid"); + $comment = DataObject::get_one('PageComment', "\"PageComment\".ID = $commentid"); if($comment) { $comment->IsSpam = false; $comment->NeedsModeration = false; diff --git a/code/CommentTableField.php b/code/CommentTableField.php index 19859a35..66eeac3b 100644 --- a/code/CommentTableField.php +++ b/code/CommentTableField.php @@ -19,7 +19,7 @@ class CommentTableField extends ComplexTableField { // search $search = isset($_REQUEST['CommentSearch']) ? Convert::raw2sql($_REQUEST['CommentSearch']) : null; if(!empty($_REQUEST['CommentSearch'])) { - $this->sourceFilter[] = "( `Name` LIKE '%$search%' OR `Comment` LIKE '%$search%')"; + $this->sourceFilter[] = "( \"Name\" LIKE '%$search%' OR \"Comment\" LIKE '%$search%')"; } Requirements::javascript(CMS_DIR . '/javascript/CommentTableField.js'); diff --git a/code/Diff.php b/code/Diff.php index 2f0131c9..ad8696eb 100755 --- a/code/Diff.php +++ b/code/Diff.php @@ -408,7 +408,7 @@ class _DiffEngine * We do something when a run of changed lines include a * line at one end and has an excluded, identical line at the other. * We are free to choose which identical line is included. - * `compareseq' usually chooses the one at the beginning, + * 'compareseq' usually chooses the one at the beginning, * but usually it is cleaner to consider the following identical line * to be the "change". * diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 2273d23d..75adc15e 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -433,7 +433,7 @@ JS; $SQL_id = Convert::raw2sql($_REQUEST['ID']); if(substr($SQL_id,0,3) != 'new') { - $record = DataObject::get_one($className, "`$className`.ID = {$SQL_id}"); + $record = DataObject::get_one($className, "\"$className\".ID = {$SQL_id}"); if($record && !$record->canEdit()) return Security::permissionFailure($this); } else { if(!singleton($this->stat('tree_class'))->canCreate()) return Security::permissionFailure($this); @@ -678,7 +678,7 @@ JS; if(is_array($_REQUEST['ID'])) { if($_REQUEST['MovedNodeID']==0){ //Sorting root - $movedNode = DataObject::get($className, "`ParentID`=0"); + $movedNode = DataObject::get($className, "\"ParentID\"=0"); }else{ $movedNode = DataObject::get_by_id($className, $_REQUEST['MovedNodeID']); } @@ -694,7 +694,7 @@ JS; // Nodes that weren't "actually moved" shouldn't be registered as having been edited; do a direct SQL update instead } else if(is_numeric($id)) { ++$counter; - DB::query("UPDATE `$className` SET `Sort` = $counter WHERE `ID` = '$id'"); + DB::query("UPDATE \"$className\" SET \"Sort\" = $counter WHERE \"ID\" = '$id'"); } } // Virtual pages require selected to be null if the page is the same. diff --git a/code/MemberTableField.php b/code/MemberTableField.php index b4a0e8bc..580b22ea 100755 --- a/code/MemberTableField.php +++ b/code/MemberTableField.php @@ -104,7 +104,7 @@ class MemberTableField extends ComplexTableField { // construct the filter and sort if(isset($_REQUEST['MemberOrderByField'])) { - $this->sourceSort = '`' . Convert::raw2sql($_REQUEST['MemberOrderByField']) . '`' . Convert::raw2sql( $_REQUEST['MemberOrderByOrder'] ); + $this->sourceSort = '"' . Convert::raw2sql($_REQUEST['MemberOrderByField']) . '"' . Convert::raw2sql( $_REQUEST['MemberOrderByOrder'] ); } $SNG_member = singleton('Member'); @@ -114,7 +114,7 @@ class MemberTableField extends ComplexTableField { if(!empty($_REQUEST['MemberSearch'])) { $searchFilters = array(); foreach($SNG_member->searchableFields() as $fieldName => $fieldSpec) { - if(strpos($fieldName,'.') === false) $searchFilters[] = "`$fieldName` LIKE '%{$SQL_search}%'"; + if(strpos($fieldName,'.') === false) $searchFilters[] = "\"$fieldName\" LIKE '%{$SQL_search}%'"; } $this->sourceFilter[] = '(' . implode(' OR ', $searchFilters) . ')'; } @@ -122,10 +122,10 @@ class MemberTableField extends ComplexTableField { // filter by groups // TODO Not implemented yet if(isset($_REQUEST['ctf'][$this->Name()]['GroupID']) && is_numeric($_REQUEST['ctf'][$this->Name()]['GroupID'])) { - $this->sourceFilter[] = "`GroupID`='{$_REQUEST['ctf'][$this->Name()]['GroupID']}'"; + $this->sourceFilter[] = "\"GroupID\"='{$_REQUEST['ctf'][$this->Name()]['GroupID']}'"; } - $this->sourceJoin = " INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`"; + $this->sourceJoin = " INNER JOIN \"Group_Members\" ON \"MemberID\"=\"Member\".\"ID\""; $this->setFieldListCsv( $csvFieldList ); } diff --git a/code/SecurityAdmin.php b/code/SecurityAdmin.php index d2a1c25b..1503155a 100644 --- a/code/SecurityAdmin.php +++ b/code/SecurityAdmin.php @@ -153,7 +153,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { if($id == 'new') $id = null; if($id) { - $record = DataObject::get_one($className, "`$className`.ID = $id"); + $record = DataObject::get_one($className, "\"$className\".ID = $id"); } else { $record = new $className(); } diff --git a/code/SideReport.php b/code/SideReport.php index b9689632..0fb5dcc6 100755 --- a/code/SideReport.php +++ b/code/SideReport.php @@ -87,7 +87,7 @@ class SideReport_RecentlyEdited extends SideReport { return _t('SideReport.LAST2WEEKS',"Pages edited in the last 2 weeks"); } function records() { - return DataObject::get("SiteTree", "`SiteTree`.LastEdited > NOW() - INTERVAL 14 DAY", "`SiteTree`.`LastEdited` DESC"); + return DataObject::get("SiteTree", "\"SiteTree\".LastEdited > NOW() - INTERVAL 14 DAY", "\"SiteTree\".\"LastEdited\" DESC"); } function fieldsToShow() { return array( @@ -101,7 +101,7 @@ class SideReport_ToDo extends SideReport { return _t('SideReport.TODO',"To do"); } function records() { - return DataObject::get("SiteTree", "`SiteTree`.ToDo IS NOT NULL AND `SiteTree`.ToDo <> ''", "`SiteTree`.`LastEdited` DESC"); + return DataObject::get("SiteTree", "\"SiteTree\".ToDo IS NOT NULL AND \"SiteTree\".ToDo <> ''", "\"SiteTree\".\"LastEdited\" DESC"); } function fieldsToShow() { return array( diff --git a/code/WidgetAreaEditor.php b/code/WidgetAreaEditor.php index af28ce79..60e07111 100644 --- a/code/WidgetAreaEditor.php +++ b/code/WidgetAreaEditor.php @@ -67,8 +67,8 @@ class WidgetAreaEditor extends FormField { foreach(array_keys( $_REQUEST['Widget'] ) as $newWidgetID ) { $newWidgetData = $_REQUEST['Widget'][$newWidgetID]; - // `ParentID`=0 is for the new page - $widget = DataObject::get_one( 'Widget', "(`ParentID`='{$record->$name()->ID}' OR `ParentID`=0) AND `Widget`.`ID`='$newWidgetID'" ); + // \"ParentID\"=0 is for the new page + $widget = DataObject::get_one( 'Widget', "(\"ParentID\"='{$record->$name()->ID}' OR \"ParentID\"=0) AND \"Widget\".\"ID\"='$newWidgetID'" ); // check if we are updating an existing widget if($widget && isset($missingWidgets[$widget->ID])) diff --git a/code/staticpublisher/StaticPublisher.php b/code/staticpublisher/StaticPublisher.php index c170fe61..274ef54b 100644 --- a/code/staticpublisher/StaticPublisher.php +++ b/code/staticpublisher/StaticPublisher.php @@ -26,7 +26,7 @@ abstract class StaticPublisher extends DataObjectDecorator { if($this->owner->hasMethod('pagesAffectedByChanges')) { $urls = $this->owner->pagesAffectedByChanges($original); } else { - // $pages = array(Versioned::get_one_by_stage('SiteTree', 'Live', "`SiteTree`.ID = {$this->owner->ID}")); + // $pages = array(Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".ID = {$this->owner->ID}")); $pages = Versioned::get_by_stage('SiteTree', 'Live', '', '', 10); foreach($pages as $page) { $urls[] = $page->Link();