Updating queries to be more DB agnostic

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@66507 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-11-24 09:31:14 +00:00
parent 09e3145921
commit 96c5be8252
34 changed files with 157 additions and 144 deletions

View File

@ -83,8 +83,10 @@ class Controller extends RequestHandler {
// Directly access the session variable just in case the Group or Member tables don't yet exist
if(Session::get('loggedInAs') && Security::database_is_ready()) {
$member = Member::currentUser();
Cookie::set("PastMember", true);
DB::query("UPDATE \"Member\" SET \"LastVisited\" = NOW() WHERE \"ID\" = $member->ID", null);
if($member) {
Cookie::set("PastMember", true);
DB::query("UPDATE \"Member\" SET \"LastVisited\" = NOW() WHERE \"ID\" = $member->ID", null);
}
}
// This is used to test that subordinate controllers are actually calling parent::init() - a common bug

View File

@ -429,7 +429,7 @@ abstract class Database extends Object {
case "insert":
if(!isset($writeInfo['fields']['ID']) && isset($writeInfo['id'])) {
$columnList[] = "\"$ID\"";
$columnList[] = "\"ID\"";
$valueList[] = (int)$writeInfo['id'];
}
$columnList = implode(", ", $columnList);

View File

@ -199,6 +199,7 @@ class DatabaseAdmin extends Controller {
/**
* Clear all data out of the database
* @todo Move this code into Database class, for DB abstraction
*/
function clearAllData() {
$tables = DB::query("SHOW TABLES")->column();
@ -244,7 +245,7 @@ class DatabaseAdmin extends Controller {
foreach($subclasses as $subclass) {
$recordExists[$subclass] =
DB::query("SELECT ID FROM \"$subclass")->keyedColumn();
DB::query("SELECT \"ID\" FROM \"$subclass\"")->keyedColumn();
}
foreach($records as $record) {

View File

@ -124,7 +124,7 @@ class GhostPage_ComponentSet extends ComponentSet {
function remove($item) {
$id = is_object($item) ? $item->ID : $item;
$ghosts = DataObject::get("GhostPage","ParentID = $id AND LinkedPageID = {$this->ownerObj->ID}");
$ghosts = DataObject::get("GhostPage","\"ParentID\" = $id AND \"LinkedPageID\" = {$this->ownerObj->ID}");
if($ghosts) {
foreach($ghosts as $ghost) {
$ghost->delete();

View File

@ -590,7 +590,6 @@ class MySQLDatabase extends Database {
if(isset($limit['start']) && is_numeric($limit['start']) && isset($limit['limit']) && is_numeric($limit['limit'])) {
// @todo MySQL specific LIMIT syntax
//$combinedLimit = (int)$limit['start'] . ',' . (int)$limit['limit'];
$combinedLimit = "$limit[limit] OFFSET $limit[start]";
} elseif(isset($limit['limit']) && is_numeric($limit['limit'])) {
$combinedLimit = (int)$limit['limit'];

View File

@ -291,9 +291,9 @@ class SiteTree extends DataObject {
* @return DataObjectSet Comments on this page.
*/
public function Comments() {
$spamfilter = isset($_GET['showspam']) ? '' : 'AND IsSpam=0';
$unmoderatedfilter = Permission::check('ADMIN') ? '' : 'AND NeedsModeration = 0';
$comments = DataObject::get("PageComment", "ParentID = '" . Convert::raw2sql($this->ID) . "' $spamfilter $unmoderatedfilter", "Created DESC");
$spamfilter = isset($_GET['showspam']) ? '' : 'AND NOT "IsSpam"';
$unmoderatedfilter = Permission::check('ADMIN') ? '' : 'AND NOT "NeedsModeration"';
$comments = DataObject::get("PageComment", "\"ParentID\" = '" . Convert::raw2sql($this->ID) . "' $spamfilter $unmoderatedfilter", "\"Created\" DESC");
return $comments ? $comments : new DataObjectSet();
}
@ -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"));
}
}
@ -937,8 +937,7 @@ class SiteTree extends DataObject {
protected function onBeforeWrite() {
if(!$this->Sort && $this->ParentID) {
$this->Sort = DB::query(
"SELECT MAX(Sort) + 1 FROM SiteTree WHERE ParentID = $this->ParentID")->value();
$this->Sort = DB::query("SELECT MAX(\"Sort\") + 1 FROM \"SiteTree\" WHERE \"ParentID\" = $this->ParentID")->value();
}
// Auto-set URLSegment
@ -1378,10 +1377,11 @@ class SiteTree extends DataObject {
GoogleSitemap::ping();
// Fix the sort order for this page's siblings
DB::query("UPDATE SiteTree_Live
INNER JOIN SiteTree ON SiteTree_Live.ID = SiteTree.ID
SET SiteTree_Live.Sort = SiteTree.Sort
WHERE SiteTree_Live.ParentID = " . sprintf('%d', $this->ParentID));
DB::query("UPDATE \"SiteTree_Live\"
SET \"Sort\" = \"SiteTree\".\"Sort\"
FROM \"SiteTree\"
WHERE \"SiteTree_Live\".\"ID\" = \"SiteTree\".\"ID\"
AND \"SiteTree_Live\".\"ParentID\" = " . sprintf('%d', $this->ParentID) );
// Handle activities undertaken by decorators
$this->extend('onAfterPublish', $original);
@ -1466,7 +1466,7 @@ class SiteTree extends DataObject {
function MultipleParents() {
$parents = new GhostPage_ComponentSet($this->Parent);
$parents->setOwner($this);
$ghostPages = DataObject::get("GhostPage", "LinkedPageID = '$this->ID'");
$ghostPages = DataObject::get("GhostPage", "\"LinkedPageID\" = '$this->ID'");
if($ghostPages) {
foreach($ghostPages as $ghostPage) {

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;
@ -524,13 +524,13 @@ class Translatable extends DataObjectDecorator {
// populate lang field
$manipulation["{$table}_lang"]['fields']['Lang'] = "'$lang'" ;
// get a valid id, pre-inserting
DB::query("INSERT INTO {$table}_lang SET Created = NOW(), Lang = '$lang'");
DB::query("INSERT INTO \"{$table}_lang\" (\"Created\", \"Lang\") VALUES (NOW(), '$lang')");
$manipulation["{$table}_lang"]['id'] = $manipulation["{$table}_lang"]['fields']['ID'] = DB::getGeneratedID("{$table}_lang");
$manipulation["{$table}_lang"]['command'] = 'update';
// we don't have to insert anything in $table if we are inserting in $table_lang
unset($manipulation[$table]);
// now dataobjects may create a record before the real write in the base table, so we have to delete it - 20/08/2007
if (is_numeric($fakeID)) DB::query("DELETE FROM $table WHERE ID=$fakeID");
if (is_numeric($fakeID)) DB::query("DELETE FROM \"$table\" WHERE \"ID\"=$fakeID");
}
else {
if (!isset($manipulation[$table]['fields']['OriginalLangID'])) {
@ -545,7 +545,7 @@ class Translatable extends DataObjectDecorator {
} else {
$manipulation["{$table}_lang"]['where'] = "(Lang = '$lang') AND (OriginalLangID = $id)";
}
$realID = DB::query("SELECT ID FROM {$table}_lang WHERE (OriginalLangID = $id) AND (Lang = '$lang') LIMIT 1")->value();
$realID = DB::query("SELECT \"ID\" FROM \"{$table}_lang\" WHERE (\"OriginalLangID\" = $id) AND (\"Lang\" = '$lang') LIMIT 1")->value();
$manipulation["{$table}_lang"]['id'] = $realID;
$manipulation["{$table}_lang"]['RecordID'] = $manipulation["{$table}_lang"]['fields']['OriginalLangID'];
// we could be updating non-translatable fields at the same time, so these will remain

View File

@ -99,19 +99,20 @@ class Versioned extends DataObjectDecorator {
* This is used by the versioning system to return database content on that date.
* @param string $baseTable The base table.
* @param string $date The date.
* @todo Ensure that this is DB abstracted
*/
protected function requireArchiveTempTable($baseTable, $date) {
if(!isset(self::$createdArchiveTempTable[$baseTable])) {
self::$createdArchiveTempTable[$baseTable] = true;
DB::query("CREATE TEMPORARY TABLE _Archive$baseTable (
RecordID INT NOT NULL PRIMARY KEY,
Version INT NOT NULL
DB::query("CREATE TEMPORARY TABLE \"_Archive$baseTable\" (
\"RecordID\" INT NOT NULL PRIMARY KEY,
\"Version\" INT NOT NULL
)");
DB::query("INSERT INTO _Archive$baseTable
SELECT RecordID, max(Version) FROM {$baseTable}_versions
WHERE LastEdited <= '$date'
GROUP BY RecordID");
DB::query("INSERT INTO \"_Archive$baseTable\"
SELECT \"RecordID\", max(\"Version\") FROM \"{$baseTable}_versions\"
WHERE \"LastEdited\" <= '$date'
GROUP BY \"RecordID\"");
}
}
/**
@ -398,7 +399,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;

View File

@ -583,16 +583,16 @@ class Debug {
$memberID = $_SESSION['loggedInAs'];
$groups = DB::query("SELECT GroupID from Group_Members WHERE MemberID=" . $memberID);
$groups = DB::query("SELECT \"GroupID\" from \"Group_Members\" WHERE \"MemberID\" = " . $memberID);
$groupCSV = implode($groups->column(), ',');
$permission = DB::query("
SELECT ID
FROM Permission
SELECT \"ID\"
FROM \"Permission\"
WHERE (
Code = 'ADMIN'
AND Type = " . Permission::GRANT_PERMISSION . "
AND GroupID IN ($groupCSV)
\"Code\" = 'ADMIN'
AND \"Type\" = " . Permission::GRANT_PERMISSION . "
AND \"GroupID\" IN ($groupCSV)
)
")->value();

View File

@ -200,6 +200,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
return $dbConn && (substr($dbConn->currentDatabase(),0,5) == 'tmpdb');
}
/**
* @todo Make this db agnostic
*/
static function kill_temp_db() {
// Delete our temporary database
if(self::using_temp_db()) {
@ -212,6 +215,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
}
}
/**
* @todo Make this db agnostic
*/
static function create_temp_db() {
// Create a temporary database
$dbConn = DB::getConn();

View File

@ -514,7 +514,7 @@ class Email_BounceHandler extends Controller {
$SQL_email = Convert::raw2sql($email);
$SQL_bounceTime = Convert::raw2sql("$date $time");
$duplicateBounce = DataObject::get_one("Email_BounceRecord", "BounceEmail = '$SQL_email' AND (BounceTime+INTERVAL 1 MINUTE) > '$SQL_bounceTime'");
$duplicateBounce = DataObject::get_one("Email_BounceRecord", "\"BounceEmail\" = '$SQL_email' AND (\"BounceTime\"+INTERVAL 1 MINUTE) > '$SQL_bounceTime'");
if(!$duplicateBounce) {
$record = new Email_BounceRecord();
@ -536,7 +536,7 @@ class Email_BounceHandler extends Controller {
$SQL_memberID = Convert::raw2sql($member->ID);
$SQL_newsletterID = Convert::raw2sql($newsletter_id_date_parts[0]);
// Log the bounce
$oldNewsletterSentRecipient = DataObject::get_one("Newsletter_SentRecipient", "MemberID = '$SQL_memberID' AND ParentID = '$SQL_newsletterID' AND Email = '$SQL_email'");
$oldNewsletterSentRecipient = DataObject::get_one("Newsletter_SentRecipient", "\"MemberID\" = '$SQL_memberID' AND \"ParentID\" = '$SQL_newsletterID' AND \"Email\" = '$SQL_email'");
// Update the Newsletter_SentRecipient record if it exists
if($oldNewsletterSentRecipient) {
$oldNewsletterSentRecipient->Result = 'Bounced';

View File

@ -150,7 +150,7 @@ class File extends DataObject {
foreach($parts as $part) {
if($part == "assets" && !$parentID) continue;
$item = DataObject::get_one("File", "Name = '$part' AND ParentID = $parentID");
$item = DataObject::get_one("File", "\"Name\" = '$part' AND \"ParentID\" = $parentID");
if(!$item) break;
$parentID = $item->ID;
}
@ -221,7 +221,7 @@ class File extends DataObject {
* Delete the database record (recursively for folders) without touching the filesystem
*/
public function deleteDatabaseOnly() {
if(is_numeric($this->ID)) DB::query("DELETE FROM File WHERE \"ID\" = $this->ID");
if(is_numeric($this->ID)) DB::query("DELETE FROM \"File\" WHERE \"ID\" = $this->ID");
}
/**
@ -287,7 +287,7 @@ class File extends DataObject {
$ext = "";
}
$suffix = 1;
while(DataObject::get_one("File", "Name = '" . addslashes($name) . "' AND ParentID = " . (int)$this->ParentID)) {
while(DataObject::get_one("File", "\"Name\" = '" . addslashes($name) . "' AND \"ParentID\" = " . (int)$this->ParentID)) {
$suffix++;
$name = "$base-$suffix$ext";
}
@ -418,7 +418,7 @@ class File extends DataObject {
function getRelativePath() {
if($this->ParentID) {
$p = DataObject::get_one('Folder', "ID={$this->ParentID}");
$p = DataObject::get_one('Folder', "\"ID\"={$this->ParentID}");
if($p->ID) return $p->getRelativePath() . $this->getField("Name");
else return ASSETS_DIR . "/" . $this->getField("Name");
@ -560,13 +560,15 @@ 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();
$columnsToAdd = array_diff($fileColumns, $excludeDbColumns);
foreach($columnsToAdd as $otherItem) $dataobject_select[] = '"File".' . $otherItem;
} else {
*/
$dataobject_select[] = $item;
}
//}
}
$query->select = $dataobject_select;

View File

@ -107,7 +107,9 @@ class Filesystem extends Object {
singleton('Folder')->syncChildren();
$finished = false;
while(!$finished) {
$orphans = DB::query("SELECT C.ID FROM File AS C LEFT JOIN File AS P ON C.ParentID = P.ID WHERE P.ID IS NULL AND C.ParentID > 0");
$orphans = DB::query("SELECT \"C\".\"ID\" FROM \"File\" AS \"C\"
LEFT JOIN \"File\" AS \"P\" ON \"C\".\"ParentID\" = \"P\".\"ID\"
WHERE \"P\".\"ID\" IS NULL AND \"C\".\"ParentID\" > 0");
$finished = true;
if($orphans) foreach($orphans as $orphan) {
$finished = false;

View File

@ -20,7 +20,7 @@ class Folder extends File {
$parentID = 0;
foreach($parts as $part) {
$item = DataObject::get_one("Folder", "Name = '$part' AND ParentID = $parentID");
$item = DataObject::get_one("Folder", "\"Name\" = '$part' AND \"ParentID\" = $parentID");
if(!$item) {
$item = new Folder();
$item->ParentID = $parentID;
@ -43,15 +43,15 @@ 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("UPDATE \"File\" SET \"ParentID\" = $keptChild WHERE \"ParentID\" = $removedChild");
DB::query("DELETE FROM \"File\" WHERE \"ID\" = $removedChild");
}
} else {
@ -62,7 +62,7 @@ class Folder extends File {
// Get index of database content
// We don't use DataObject so that things like subsites doesn't muck with this.
$dbChildren = DB::query("SELECT * FROM File WHERE ParentID = $parentID");
$dbChildren = DB::query("SELECT * FROM \"File\" WHERE \"ParentID\" = $parentID");
$hasDbChild = array();
if($dbChildren) {
foreach($dbChildren as $dbChild) {
@ -154,10 +154,9 @@ class Folder extends File {
$name = addslashes($name);
DB::query("INSERT INTO \"File\" SET
ClassName = '$className', ParentID = $this->ID, OwnerID = $ownerID,
Name = '$name', Filename = '$filename', Created = NOW(), LastEdited = NOW(),
Title = '$name'");
DB::query("INSERT INTO \"File\"
(\"ClassName\", \"ParentID\", \"OwnerID\", \"Name\", \"Filename\", \"Created\", \"LastEdited\", \"Title\")
VALUES ('$className', $this->ID, $ownerID, '$name', '$filename', NOW(), NOW(), '$name')");
return DB::getGeneratedID("File");
}
@ -253,7 +252,7 @@ class Folder extends File {
if($a == "DataObject") $baseClass = -1;
}
$g = DataObject::get($baseClass, "ParentID = " . $this->ID);
$g = DataObject::get($baseClass, "\"ParentID\" = " . $this->ID);
return $g;
}
@ -402,7 +401,7 @@ class Folder extends File {
* @returns String where clause which will work as filter.
*/
protected function getUsedFilesList() {
$result = DB::query("SELECT DISTINCT FileID FROM SiteTree_ImageTracking");
$result = DB::query("SELECT DISTINCT \"FileID\" FROM \"SiteTree_ImageTracking\"");
$usedFiles = array();
$where = "";
if($result->numRecords() > 0) {
@ -431,9 +430,9 @@ class Folder extends File {
foreach($usedFiles as $file) {
$where .= $file->ID . ',';
}
if($where == "") return "(ClassName = 'File' OR ClassName = 'Image')";
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

@ -58,7 +58,7 @@ class HtmlEditorField extends TextareaField {
} else if($link[0] == '/') {
$broken = true;
} else if(ereg('^assets/',$link)) {
if(!DataObject::get_one("File", "Filename = '$link'", false)) {
if(!DataObject::get_one("File", "\"Filename\" = '$link'", false)) {
$broken = true;
}
}
@ -132,7 +132,7 @@ class HtmlEditorField extends TextareaField {
} else if($link{0} == '/') {
$record->HasBrokenLink = 1;
} else if($candidateFile = DataObject::get_one("File", "Filename = '" . Convert::raw2sql(urldecode($link)) . "'", false)) {
} else if($candidateFile = DataObject::get_one("File", "\"Filename\" = '" . Convert::raw2sql(urldecode($link)) . "'", false)) {
$linkedFiles[] = $candidateFile->ID;
// $candidateFile->destroy();
}
@ -145,7 +145,7 @@ class HtmlEditorField extends TextareaField {
$image = Director::makeRelative($image);
if(substr($image,0,7) == 'assets/') {
$candidateImage = DataObject::get_one("File", "Filename = '$image'");
$candidateImage = DataObject::get_one("File", "\"Filename\" = '$image'");
if($candidateImage) $linkedFiles[] = $candidateImage->ID;
else $record->HasBrokenFile = 1;
}

View File

@ -126,7 +126,7 @@ class ScaffoldingComplexTableField_Popup extends Form {
$type = $request->getVar('type');
$value = $request->getVar('value');
if ($type && $value) {
$record = DataObject::get_one($this->dataObject->class, "$type = '$value'");
$record = DataObject::get_one($this->dataObject->class, "\"$type\" = '$value'");
header("Content-Type: text/plain");
echo json_encode(array("record"=>$record->toMap()));
}

View File

@ -442,8 +442,8 @@ JS
if($this->customQuery) {
$query = clone $this->customQuery;
$baseClass = ClassInfo::baseDataClass($this->sourceClass);
$query->select[] = "{$baseClass}.ID AS ID";
$query->select[] = "{$baseClass}.ClassName AS ClassName";
$query->select[] = "{$baseClass}.ID AS \"ID\"";
$query->select[] = "{$baseClass}.ClassName AS \"ClassName\"";
$query->select[] = "{$baseClass}.ClassName AS \"RecordClassName\"";
} else {
$query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter(), $this->sourceSort, null, $this->sourceJoin);
@ -830,7 +830,7 @@ JS
} else {
$countQuery->select = array();
$countQuery->groupby = array();
$countQuery->select[] = "COUNT(DISTINCT {$baseClass}.ID) AS TotalCount";
$countQuery->select[] = "COUNT(DISTINCT \"{$baseClass}\".\"ID\") AS \"TotalCount\"";
$records = $countQuery->execute();
$record = $records->nextRecord();
$this->totalCount = $record['TotalCount'];

View File

@ -84,7 +84,7 @@ HTML;
*/
public function getsubtree() {
if($this->keyField == "ID") $obj = DataObject::get_by_id($this->sourceObject, $_REQUEST['SubtreeRootID']);
else $obj = DataObject::get_one($this->sourceObject, "$this->keyField = '$_REQUEST[SubtreeRootID]'");
else $obj = DataObject::get_one($this->sourceObject, "\"$this->keyField\" = '$_REQUEST[SubtreeRootID]'");
if(!$obj) user_error("Can't find database record $this->sourceObject with $this->keyField = $_REQUEST[SubtreeRootID]", E_USER_ERROR);
if($this->filterFunc) $obj->setMarkingFilterFunction($this->filterFunc);
@ -103,7 +103,7 @@ HTML;
if($this->keyField == 'ID') {
return DataObject::get_by_id($this->sourceObject, $key);
} else {
return DataObject::get_one($this->sourceObject, "$this->keyField = '$key'");
return DataObject::get_one($this->sourceObject, "\"$this->keyField\" = '$key'");
}
}

View File

@ -176,14 +176,18 @@ class SearchForm extends Form {
$baseClass = reset($queryContent->from);
// There's no need to do all that joining
$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;
$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(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;
$fullQuery = $queryContent->sql() . " UNION " . $queryFiles->sql() . " ORDER BY $sortBy LIMIT $limit";

View File

@ -133,7 +133,7 @@ class Group extends DataObject {
* @param string $groupcode
*/
static function addToGroupByName($member, $groupcode) {
$group = DataObject::get_one('Group', "Code = '" . Convert::raw2sql($groupcode). "'");
$group = DataObject::get_one('Group', "\"Code\" = '" . Convert::raw2sql($groupcode). "'");
if($group) {
$member->Groups()->add($group);
$member->write();
@ -158,9 +158,9 @@ class Group extends DataObject {
if( is_numeric( $limit ) ) {
if( is_numeric( $offset ) )
$limit = "$offset, $limit";
$limit = "$limit OFFSET $offset";
else
$limit = "0, $limit";
$limit = "$limit OFFSET 0";
} else {
$limit = "";
}
@ -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

@ -216,7 +216,7 @@ class Member extends DataObject {
list($uid, $token) = explode(':', Cookie::get('alc_enc'), 2);
$SQL_uid = Convert::raw2sql($uid);
$member = DataObject::get_one("Member", "Member.ID = '$SQL_uid'");
$member = DataObject::get_one("Member", "\"Member\".\"ID\" = '$SQL_uid'");
if($member && $member->RememberLoginToken != $token) {
$member = null;
@ -462,7 +462,7 @@ class Member extends DataObject {
if($existingRecord) {
$newID = $existingRecord->ID;
if($this->ID) {
DB::query("UPDATE Group_Members SET MemberID = $newID WHERE MemberID = $this->ID");
DB::query("UPDATE \"Group_Members\" SET \"MemberID\" = $newID WHERE \"MemberID\" = $this->ID");
}
$this->ID = $newID;
// Merge existing data into the local record
@ -547,7 +547,7 @@ class Member extends DataObject {
$groupCheckObj = DataObject::get_by_id('Group', $group);
} elseif(is_string($group)) {
$SQL_group = Convert::raw2sql($group);
$groupCheckObj = DataObject::get_one('Group', "Code = '{$SQL_group}'");
$groupCheckObj = DataObject::get_one('Group', "\"Code\" = '{$SQL_group}'");
} elseif($group instanceof Group) {
$groupCheckObj = $group;
} else {
@ -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();
@ -1104,7 +1104,7 @@ class Member_GroupSet extends ComponentSet {
*/
function getGroupsFromIDs($ids){
if($ids && count($ids) > 1) {
return DataObject::get("Group", "ID IN (" . implode(",", $ids) . ")");
return DataObject::get("Group", "\"ID\" IN (" . implode(",", $ids) . ")");
} else {
return DataObject::get_by_id("Group", $ids[0]);
}
@ -1149,7 +1149,7 @@ class Member_GroupSet extends ComponentSet {
*/
protected function codenamesToGroups($codenames) {
$list = "'" . implode("', '", $codenames) . "'";
$output = DataObject::get("Group", "Code IN ($list)");
$output = DataObject::get("Group", "\"Code\" IN ($list)");
// Some are missing - throw warnings
if(!$output || ($output->Count() != sizeof($list))) {
@ -1358,7 +1358,7 @@ class Member_Validator extends RequiredFields {
$valid = parent::php($data);
$member = DataObject::get_one('Member',
"Email = '". Convert::raw2sql($data['Email']) ."'");
"\"Email\" = '". Convert::raw2sql($data['Email']) ."'");
// if we are in a complex table field popup, use ctf[childID], else use
// ID

View File

@ -50,7 +50,7 @@ class MemberAuthenticator extends Authenticator {
$member->extend('authenticated');
} else {
// failed login - we're trying to see if a user exists with this email (disregarding wrong passwords)
$existingMember = DataObject::get_one("Member", "Email = '$SQL_user'");
$existingMember = DataObject::get_one("Member", "\"Email\" = '$SQL_user'");
if($existingMember) {
$attempt->MemberID = $existingMember->ID;

View File

@ -193,7 +193,7 @@ class MemberLoginForm extends LoginForm {
function forgotPassword($data) {
$SQL_data = Convert::raw2sql($data);
$SQL_email = $SQL_data['Email'];
$member = DataObject::get_one('Member', "Email = '{$SQL_email}'");
$member = DataObject::get_one('Member', "\"Email\" = '{$SQL_email}'");
if($member) {
$member->generateAutologinHash();

View File

@ -73,7 +73,7 @@ class PasswordValidator extends Object {
}
if($this->historicalPasswordCount) {
$previousPasswords = DataObject::get("MemberPassword", "MemberID = $member->ID", "Created DESC, ID Desc", "", $this->historicalPasswordCount);
$previousPasswords = DataObject::get("MemberPassword", "\"MemberID\" = $member->ID", "\"Created\" DESC, \"ID\" Desc", "", $this->historicalPasswordCount);
if($previousPasswords) foreach($previousPasswords as $previousPasswords) {
if($previousPasswords->checkPassword($password)) {
$valid->error("You've already used that password in the past, please choose a new password", "PREVIOUS_PASSWORD");

View File

@ -356,8 +356,8 @@ class Permission extends DataObject {
$SQL_codeList = (is_array($code)) ? implode("','", Convert::raw2sql($code)) : Convert::raw2sql($code);
$SQL_filter = "Permission.Code IN ('" . $SQL_codeList . "') " .
"AND Permission.Type = " . self::GRANT_PERMISSION;
$SQL_filter = "\"Permission\".\"Code\" IN ('" . $SQL_codeList . "') " .
"AND \"Permission\".\"Type\" = " . self::GRANT_PERMISSION;
$toplevelGroups = DataObject::get(
'Group',
@ -380,7 +380,7 @@ 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\" "
@ -401,9 +401,9 @@ class Permission extends DataObject {
return DataObject::get(
'Group',
"Permission.Code IN ('$SQL_codes')",
"\"Permission\".\"Code\" IN ('$SQL_codes')",
"",
"LEFT JOIN Permission ON Group.ID = Permission.GroupID"
"LEFT JOIN \"Permission\" ON \"Group\".\"ID\" = \"Permission\".\"GroupID\""
);
}
@ -441,7 +441,7 @@ class Permission extends DataObject {
}
}
$otherPerms = DB::query("SELECT DISTINCT Code From Permission")
$otherPerms = DB::query("SELECT DISTINCT \"Code\" From \"Permission\"")
->column();
if($otherPerms) foreach($otherPerms as $otherPerm) {
if(!array_key_exists($otherPerm, $allCodes))

View File

@ -564,7 +564,7 @@ class Security extends Controller {
&& !empty(self::$default_username) && !empty(self::$default_password)) {
$member = self::findAnAdministrator();
} else {
$member = DataObject::get_one("Member", "Email = '$SQL_email' AND Password IS NOT NULL");
$member = DataObject::get_one("Member", "\"Email\" = '$SQL_email' AND \"Password\" IS NOT NULL");
if($member && ($member->checkPassword($RAW_password) == false)) {
$member = null;
}
@ -896,7 +896,7 @@ class Security extends Controller {
// Are there members with a clear text password?
$members = DataObject::get("Member",
"PasswordEncryption = 'none' AND Password IS NOT NULL");
"\"PasswordEncryption\" = 'none' AND \"Password\" IS NOT NULL");
if(!$members) {
print '<h1>'._t('Security.NOTHINGTOENCRYPT1', 'No passwords to encrypt')."</h1>\n";

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

@ -23,7 +23,7 @@ class DataObjectDecoratorTest extends SapphireTest {
unset($contact);
$contact = DataObject::get_one("DataObjectDecoratorTest_Member", "Website='http://www.example.com'");
$contact = DataObject::get_one("DataObjectDecoratorTest_Member", "\"Website\"='http://www.example.com'");
$this->assertType('DataObjectDecoratorTest_RelatedObject', $contact->RelatedObjects()->First());
$this->assertEquals("Lorem ipsum dolor", $contact->RelatedObjects()->First()->FieldOne);

View File

@ -57,28 +57,28 @@ class DataObjectTest extends SapphireTest {
$this->assertEquals(8, $comments->Count());
// Test WHERE clause
$comments = DataObject::get('PageComment', "Name='Bob'");
$comments = DataObject::get('PageComment', "\"Name\"='Bob'");
$this->assertEquals(2, $comments->Count());
foreach($comments as $comment) {
$this->assertEquals('Bob', $comment->Name);
}
// Test sorting
$comments = DataObject::get('PageComment', '', 'Name ASC');
$comments = DataObject::get('PageComment', '', '"Name" ASC');
$this->assertEquals(8, $comments->Count());
$this->assertEquals('Bob', $comments->First()->Name);
$comments = DataObject::get('PageComment', '', 'Name DESC');
$comments = DataObject::get('PageComment', '', '"Name" DESC');
$this->assertEquals(8, $comments->Count());
$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);
// Test limit
$comments = DataObject::get('PageComment', '', 'Name ASC', '', '1,2');
$comments = DataObject::get('PageComment', '', '"Name" ASC', '', '1,2');
$this->assertEquals(2, $comments->Count());
$this->assertEquals('Bob', $comments->First()->Name);
$this->assertEquals('Dean', $comments->Last()->Name);
@ -100,27 +100,27 @@ class DataObjectTest extends SapphireTest {
$this->assertEquals($homepageID, $page->ID);
// Test get_one() without caching
$comment1 = DataObject::get_one('PageComment', "Name='Joe'", false);
$comment1 = DataObject::get_one('PageComment', "\"Name\"='Joe'", false);
$comment1->Comment = "Something Else";
$comment2 = DataObject::get_one('PageComment', "Name='Joe'", false);
$comment2 = DataObject::get_one('PageComment', "\"Name\"='Joe'", false);
$this->assertNotEquals($comment1->Comment, $comment2->Comment);
// Test get_one() with caching
$comment1 = DataObject::get_one('PageComment', "Name='Jane'", true);
$comment1 = DataObject::get_one('PageComment', "\"Name\"='Jane'", true);
$comment1->Comment = "Something Else";
$comment2 = DataObject::get_one('PageComment', "Name='Jane'", true);
$comment2 = DataObject::get_one('PageComment', "\"Name\"='Jane'", true);
$this->assertEquals((string)$comment1->Comment, (string)$comment2->Comment);
// Test get_one() with order by without caching
$comment = DataObject::get_one('PageComment', '', false, 'Name ASC');
$comment = DataObject::get_one('PageComment', '', false, '"Name" ASC');
$this->assertEquals('Bob', $comment->Name);
$comment = DataObject::get_one('PageComment', '', false, 'Name DESC');
$comment = DataObject::get_one('PageComment', '', false, '"Name" DESC');
$this->assertEquals('Joe', $comment->Name);
// Test get_one() with order by with caching
$comment = DataObject::get_one('PageComment', '', true, 'Name ASC');
$comment = DataObject::get_one('PageComment', '', true, '"Name" ASC');
$this->assertEquals('Bob', $comment->Name);
$comment = DataObject::get_one('PageComment', '', true, 'Name DESC');
$comment = DataObject::get_one('PageComment', '', true, '"Name" DESC');
$this->assertEquals('Joe', $comment->Name);
}
@ -283,24 +283,24 @@ class DataObjectTest extends SapphireTest {
$captainID = $this->idFromFixture('DataObjectTest_Player', 'player1');
$team->CaptainID = $captainID;
$team->write();
$this->assertEquals($captainID, DB::query("SELECT CaptainID FROM DataObjectTest_Team WHERE \"ID\" = $team->ID")->value());
$this->assertEquals($captainID, DB::query("SELECT \"CaptainID\" FROM \"DataObjectTest_Team\" WHERE \"ID\" = $team->ID")->value());
/* After giving it a value, you should also be able to set it back to null */
$team->CaptainID = '';
$team->write();
$this->assertEquals(0, DB::query("SELECT CaptainID FROM DataObjectTest_Team WHERE \"ID\" = $team->ID")->value());
$this->assertEquals(0, DB::query("SELECT \"CaptainID\" FROM \"DataObjectTest_Team\" WHERE \"ID\" = $team->ID")->value());
/* You should also be able to save a blank to it when it's first created */
$team = new DataObjectTest_Team();
$team->CaptainID = '';
$team->write();
$this->assertEquals(0, DB::query("SELECT CaptainID FROM DataObjectTest_Team WHERE \"ID\" = $team->ID")->value());
$this->assertEquals(0, DB::query("SELECT \"CaptainID\" FROM \"DataObjectTest_Team\" WHERE \"ID\" = $team->ID")->value());
/* Ditto for existing records without a value */
$existingTeam = $this->objFromFixture('DataObjectTest_Team', 'team1');
$existingTeam->CaptainID = '';
$existingTeam->write();
$this->assertEquals(0, DB::query("SELECT CaptainID FROM DataObjectTest_Team WHERE \"ID\" = $existingTeam->ID")->value());
$this->assertEquals(0, DB::query("SELECT \"CaptainID\" FROM \"DataObjectTest_Team\" WHERE \"ID\" = $existingTeam->ID")->value());
}
function testCanAccessHasOneObjectsAsMethods() {
@ -323,9 +323,9 @@ class DataObjectTest extends SapphireTest {
$obj->write();
$this->assertNotNull($obj->ID);
$this->assertEquals('value1', DB::query("SELECT Data FROM DataObjectTest_FunnyFieldNames WHERE \"ID\" = $obj->ID")->value());
$this->assertEquals('value2', DB::query("SELECT DbObject FROM DataObjectTest_FunnyFieldNames WHERE \"ID\" = $obj->ID")->value());
$this->assertEquals('value3', DB::query("SELECT Duplicate FROM DataObjectTest_FunnyFieldNames WHERE \"ID\" = $obj->ID")->value());
$this->assertEquals('value1', DB::query("SELECT \"Data\" FROM \"DataObjectTest_FunnyFieldNames\" WHERE \"ID\" = $obj->ID")->value());
$this->assertEquals('value2', DB::query("SELECT \"DbObject\" FROM \"DataObjectTest_FunnyFieldNames\" WHERE \"ID\" = $obj->ID")->value());
$this->assertEquals('value3', DB::query("SELECT \"Duplicate\" FROM \"DataObjectTest_FunnyFieldNames\" WHERE \"ID\" = $obj->ID")->value());
}
/**
@ -508,7 +508,7 @@ class DataObjectTest extends SapphireTest {
/* Creating a new object of a subclass should set the ClassName field correctly */
$obj = new DataObjectTest_SubTeam();
$obj->write();
$this->assertEquals("DataObjectTest_SubTeam", DB::query("SELECT ClassName FROM DataObjectTest_Team WHERE \"ID\" = $obj->ID")->value());
$this->assertEquals("DataObjectTest_SubTeam", DB::query("SELECT \"ClassName\" FROM \"DataObjectTest_Team\" WHERE \"ID\" = $obj->ID")->value());
}
public function testForceInsert() {
@ -519,11 +519,11 @@ class DataObjectTest extends SapphireTest {
$obj->SubclassDatabaseField = 'asdfasdf';
$obj->write(false, true);
$this->assertEquals("DataObjectTest_SubTeam", DB::query("SELECT ClassName FROM DataObjectTest_Team WHERE \"ID\" = $obj->ID")->value());
$this->assertEquals("DataObjectTest_SubTeam", DB::query("SELECT \"ClassName\" FROM \"DataObjectTest_Team\" WHERE \"ID\" = $obj->ID")->value());
/* Check that it actually saves to the database with the correct ID */
$this->assertEquals("1001", DB::query("SELECT ID FROM DataObjectTest_SubTeam WHERE SubclassDatabaseField = 'asdfasdf'")->value());
$this->assertEquals("1001", DB::query("SELECT ID FROM DataObjectTest_Team WHERE Title = 'asdfasdf'")->value());
$this->assertEquals("1001", DB::query("SELECT \"ID\" FROM \"DataObjectTest_SubTeam\" WHERE \"SubclassDatabaseField\" = 'asdfasdf'")->value());
$this->assertEquals("1001", DB::query("SELECT \"ID\" FROM \"DataObjectTest_Team\" WHERE \"Title\" = 'asdfasdf'")->value());
}
public function TestHasOwnTable() {

View File

@ -41,7 +41,7 @@ class SiteTreeTest extends SapphireTest {
$obj = $this->fixture->objFromFixture('Page','about');
$obj->publish('Stage', 'Live');
$createdID = DB::query("SELECT ID FROM SiteTree_Live WHERE URLSegment = '$obj->URLSegment'")->value();
$createdID = DB::query("SELECT \"ID\" FROM \"SiteTree_Live\" WHERE \"URLSegment\" = '$obj->URLSegment'")->value();
$this->assertEquals($obj->ID, $createdID);
}
@ -79,7 +79,7 @@ class SiteTreeTest extends SapphireTest {
$oldStage = Versioned::current_stage();
Versioned::reading_stage('Live');
$checkSiteTree = DataObject::get_one("SiteTree", "URLSegment = 'get-one-test-page'");
$checkSiteTree = DataObject::get_one("SiteTree", "\"URLSegment\" = 'get-one-test-page'");
$this->assertEquals("V1", $checkSiteTree->Title);
}
@ -114,12 +114,12 @@ class SiteTreeTest extends SapphireTest {
$parentID = $this->idFromFixture('Page', 'home');
$page->ParentID = $parentID;
$page->write();
$this->assertEquals($parentID, DB::query("SELECT ParentID FROM SiteTree WHERE \"ID\" = $page->ID")->value());
$this->assertEquals($parentID, DB::query("SELECT \"ParentID\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value());
/* You should then be able to save a null/0/'' value to the relation */
$page->ParentID = null;
$page->write();
$this->assertEquals(0, DB::query("SELECT ParentID FROM SiteTree WHERE \"ID\" = $page->ID")->value());
$this->assertEquals(0, DB::query("SELECT \"ParentID\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value());
}
}

View File

@ -23,7 +23,7 @@ class CsvBulkLoaderTest extends SapphireTest {
$this->assertEquals(4, $results->Count(), 'Test correct count of imported data');
// Test that columns were correctly imported
$obj = Dataobject::get_one("CsvBulkLoaderTest_Player", "FirstName = 'John'");
$obj = Dataobject::get_one("CsvBulkLoaderTest_Player", "\"FirstName\" = 'John'");
$this->assertNotNull($obj);
$this->assertEquals("He's a good guy", $obj->Biography);
$this->assertEquals("1988-01-31", $obj->Birthday);
@ -53,7 +53,7 @@ class CsvBulkLoaderTest extends SapphireTest {
$this->assertEquals(4, $results->Count(), 'Test correct count of imported data');
// Test that columns were correctly imported
$obj = Dataobject::get_one("CsvBulkLoaderTest_Player", "FirstName = 'John'");
$obj = Dataobject::get_one("CsvBulkLoaderTest_Player", "\"FirstName\" = 'John'");
$this->assertNotNull($obj);
$this->assertEquals("He's a good guy", $obj->Biography);
$this->assertEquals("1988-01-31", $obj->Birthday);
@ -93,12 +93,12 @@ class CsvBulkLoaderTest extends SapphireTest {
$this->assertEquals(1, $results->Count(), 'Test correct count of imported data');
// Test of augumenting existing relation (created by fixture)
$testTeam = DataObject::get_one('CsvBulkLoaderTest_Team', null, null, 'Created DESC');
$testTeam = DataObject::get_one('CsvBulkLoaderTest_Team', null, null, '"Created" DESC');
$this->assertEquals('20', $testTeam->TeamSize, 'Augumenting existing has_one relation works');
// Test of creating relation
$testContract = DataObject::get_one('CsvBulkLoaderTest_PlayerContract');
$testPlayer = Dataobject::get_one("CsvBulkLoaderTest_Player", "FirstName = 'John'");
$testPlayer = Dataobject::get_one("CsvBulkLoaderTest_Player", "\"FirstName\" = 'John'");
$this->assertEquals($testPlayer->ContractID, $testContract->ID, 'Creating new has_one relation works');
// Test nested setting of relation properties
@ -194,7 +194,7 @@ class CsvBulkLoaderTest_Player extends DataObject implements TestOnly {
public function getTeamByTitle($title) {
$SQL_title = Convert::raw2sql($title);
return DataObject::get_one('CsvBulkLoaderTest_Team', "Title = '{$SQL_title}'");
return DataObject::get_one('CsvBulkLoaderTest_Team', "\"Title\" = '{$SQL_title}'");
}
/**

View File

@ -14,10 +14,9 @@ class CheckboxSetFieldTest extends SapphireTest {
$field->saveInto($article);
$this->assertNull(
DB::query("
SELECT *
FROM CheckboxSetFieldTest_Article_Tags
WHERE CheckboxSetFieldTest_Article_Tags.CheckboxSetFieldTest_ArticleID = $article->ID
DB::query("SELECT *
FROM \"CheckboxSetFieldTest_Article_Tags\"
WHERE \"CheckboxSetFieldTest_Article_Tags\".\"CheckboxSetFieldTest_ArticleID\" = $article->ID
")->value(),
'Nothing should go into manymany join table for a saved field without any ticked boxes'
);
@ -41,19 +40,17 @@ class CheckboxSetFieldTest extends SapphireTest {
$this->assertEquals(
array($tag1->ID,$tag2->ID),
DB::query("
SELECT CheckboxSetFieldTest_TagID
FROM CheckboxSetFieldTest_Article_Tags
WHERE CheckboxSetFieldTest_Article_Tags.CheckboxSetFieldTest_ArticleID = $article->ID
DB::query("SELECT \"CheckboxSetFieldTest_TagID\"
FROM \"CheckboxSetFieldTest_Article_Tags\"
WHERE \"CheckboxSetFieldTest_Article_Tags\".\"CheckboxSetFieldTest_ArticleID\" = $article->ID
")->column(),
'Data shold be saved into CheckboxSetField manymany relation table on the "right end"'
);
$this->assertEquals(
array($articleWithTags->ID,$article->ID),
DB::query("
SELECT CheckboxSetFieldTest_ArticleID
FROM CheckboxSetFieldTest_Article_Tags
WHERE CheckboxSetFieldTest_Article_Tags.CheckboxSetFieldTest_TagID = $tag1->ID
DB::query("SELECT \"CheckboxSetFieldTest_ArticleID\"
FROM \"CheckboxSetFieldTest_Article_Tags\"
WHERE \"CheckboxSetFieldTest_Article_Tags\".\"CheckboxSetFieldTest_TagID\" = $tag1->ID
")->column(),
'Data shold be saved into CheckboxSetField manymany relation table on the "left end"'
);

View File

@ -23,7 +23,7 @@ class MemberTest extends SapphireTest {
$member->Password = "test3";
$member->write();
$passwords = DataObject::get("MemberPassword", "MemberID = $member->ID", "Created DESC, ID DESC")->getIterator();
$passwords = DataObject::get("MemberPassword", "\"MemberID\" = $member->ID", "\"Created\" DESC, \"ID\" DESC")->getIterator();
$this->assertNotNull($passwords);
$record = $passwords->rewind();
$this->assertTrue($record->checkPassword('test3'), "Password test3 not found in MemberRecord");
@ -82,7 +82,7 @@ class MemberTest extends SapphireTest {
$this->assertTrue($valid->valid());
// Clear out the MemberPassword table to ensure that the system functions properly in that situation
DB::query("DELETE FROM MemberPassword");
DB::query("DELETE FROM \"MemberPassword\"");
// GOOD PASSWORDS

View File

@ -151,16 +151,16 @@ class SecurityTest extends FunctionalTest {
/* UNSUCCESSFUL ATTEMPTS WITH WRONG PASSWORD FOR EXISTING USER ARE LOGGED */
$this->doTestLoginForm('sam@silverstripe.com', 'wrongpassword');
$attempt = DataObject::get_one('LoginAttempt', "Email = 'sam@silverstripe.com'");
$attempt = DataObject::get_one('LoginAttempt', "\"Email\" = 'sam@silverstripe.com'");
$this->assertTrue(is_object($attempt));
$member = DataObject::get_one('Member', "Email = 'sam@silverstripe.com'");
$member = DataObject::get_one('Member', "\"Email\" = 'sam@silverstripe.com'");
$this->assertEquals($attempt->Status, 'Failure');
$this->assertEquals($attempt->Email, 'sam@silverstripe.com');
$this->assertEquals($attempt->Member(), $member);
/* UNSUCCESSFUL ATTEMPTS WITH NONEXISTING USER ARE LOGGED */
$this->doTestLoginForm('wronguser@silverstripe.com', 'wrongpassword');
$attempt = DataObject::get_one('LoginAttempt', "Email = 'wronguser@silverstripe.com'");
$attempt = DataObject::get_one('LoginAttempt', "\"Email\" = 'wronguser@silverstripe.com'");
$this->assertTrue(is_object($attempt));
$this->assertEquals($attempt->Status, 'Failure');
$this->assertEquals($attempt->Email, 'wronguser@silverstripe.com');
@ -171,8 +171,8 @@ class SecurityTest extends FunctionalTest {
/* SUCCESSFUL ATTEMPTS ARE LOGGED */
$this->doTestLoginForm('sam@silverstripe.com', '1nitialPassword');
$attempt = DataObject::get_one('LoginAttempt', "Email = 'sam@silverstripe.com'");
$member = DataObject::get_one('Member', "Email = 'sam@silverstripe.com'");
$attempt = DataObject::get_one('LoginAttempt', "\"Email\" = 'sam@silverstripe.com'");
$member = DataObject::get_one('Member', "\"Email\" = 'sam@silverstripe.com'");
$this->assertTrue(is_object($attempt));
$this->assertEquals($attempt->Status, 'Success');
$this->assertEquals($attempt->Email, 'sam@silverstripe.com');