mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Use prepStringForDB consistently across the framework.
Also remove a line from DBFieldTest, it's redundant with the previous line. Ref: os7229
This commit is contained in:
parent
a033ddf773
commit
70dcb55fe0
@ -223,7 +223,7 @@ class DataQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$query->selectField("\"$baseClass\".\"ID\"", "ID");
|
$query->selectField("\"$baseClass\".\"ID\"", "ID");
|
||||||
$query->selectField("CASE WHEN \"$baseClass\".\"ClassName\" IS NOT NULL THEN \"$baseClass\".\"ClassName\" ELSE '$baseClass' END", "RecordClassName");
|
$query->selectField("CASE WHEN \"$baseClass\".\"ClassName\" IS NOT NULL THEN \"$baseClass\".\"ClassName\" ELSE ".DB::getConn()->prepStringForDB($baseClass)." END", "RecordClassName");
|
||||||
|
|
||||||
// TODO: Versioned, Translatable, SiteTreeSubsites, etc, could probably be better implemented as subclasses of DataQuery
|
// TODO: Versioned, Translatable, SiteTreeSubsites, etc, could probably be better implemented as subclasses of DataQuery
|
||||||
|
|
||||||
|
@ -76,7 +76,6 @@ class DBFieldTest extends SapphireTest {
|
|||||||
|
|
||||||
/* Varchar behaviour */
|
/* Varchar behaviour */
|
||||||
$this->assertEquals($db->prepStringForDB("0"), singleton('Varchar')->prepValueForDB(0));
|
$this->assertEquals($db->prepStringForDB("0"), singleton('Varchar')->prepValueForDB(0));
|
||||||
$this->assertEquals("'0'", singleton('Varchar')->prepValueForDB(0));
|
|
||||||
$this->assertEquals("null", singleton('Varchar')->prepValueForDB(null));
|
$this->assertEquals("null", singleton('Varchar')->prepValueForDB(null));
|
||||||
$this->assertEquals("null", singleton('Varchar')->prepValueForDB(false));
|
$this->assertEquals("null", singleton('Varchar')->prepValueForDB(false));
|
||||||
$this->assertEquals("null", singleton('Varchar')->prepValueForDB(''));
|
$this->assertEquals("null", singleton('Varchar')->prepValueForDB(''));
|
||||||
|
@ -65,22 +65,25 @@ class DataListTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testSql() {
|
function testSql() {
|
||||||
|
$db = DB::getConn();
|
||||||
$list = DataObjectTest_TeamComment::get();
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE \'DataObjectTest_TeamComment\' END AS "RecordClassName" FROM "DataObjectTest_TeamComment"';
|
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE '.$db->prepStringForDB('DataObjectTest_TeamComment').' END AS "RecordClassName" FROM "DataObjectTest_TeamComment"';
|
||||||
$this->assertEquals($expected, $list->sql());
|
$this->assertEquals($expected, $list->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testInnerJoin() {
|
function testInnerJoin() {
|
||||||
|
$db = DB::getConn();
|
||||||
$list = DataObjectTest_TeamComment::get();
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->innerJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
|
$list->innerJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE \'DataObjectTest_TeamComment\' END AS "RecordClassName" FROM "DataObjectTest_TeamComment" INNER JOIN "DataObjectTest_Team" AS "Team" ON "DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"';
|
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE '.$db->prepStringForDB('DataObjectTest_TeamComment').' END AS "RecordClassName" FROM "DataObjectTest_TeamComment" INNER JOIN "DataObjectTest_Team" AS "Team" ON "DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"';
|
||||||
$this->assertEquals($expected, $list->sql());
|
$this->assertEquals($expected, $list->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testLeftJoin() {
|
function testLeftJoin() {
|
||||||
|
$db = DB::getConn();
|
||||||
$list = DataObjectTest_TeamComment::get();
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$list->leftJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
|
$list->leftJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE \'DataObjectTest_TeamComment\' END AS "RecordClassName" FROM "DataObjectTest_TeamComment" LEFT JOIN "DataObjectTest_Team" AS "Team" ON "DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"';
|
$expected = 'SELECT DISTINCT "DataObjectTest_TeamComment"."ClassName", "DataObjectTest_TeamComment"."Created", "DataObjectTest_TeamComment"."LastEdited", "DataObjectTest_TeamComment"."Name", "DataObjectTest_TeamComment"."Comment", "DataObjectTest_TeamComment"."TeamID", "DataObjectTest_TeamComment"."ID", CASE WHEN "DataObjectTest_TeamComment"."ClassName" IS NOT NULL THEN "DataObjectTest_TeamComment"."ClassName" ELSE '.$db->prepStringForDB('DataObjectTest_TeamComment').' END AS "RecordClassName" FROM "DataObjectTest_TeamComment" LEFT JOIN "DataObjectTest_Team" AS "Team" ON "DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"';
|
||||||
$this->assertEquals($expected, $list->sql());
|
$this->assertEquals($expected, $list->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,49 +22,53 @@ class DataObjectLazyLoadingTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function testQueriedColumnsID() {
|
function testQueriedColumnsID() {
|
||||||
|
$db = DB::getConn();
|
||||||
$playerList = new DataList('DataObjectTest_SubTeam');
|
$playerList = new DataList('DataObjectTest_SubTeam');
|
||||||
$playerList = $playerList->setQueriedColumns(array('ID'));
|
$playerList = $playerList->setQueriedColumns(array('ID'));
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
|
$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
|
||||||
'"DataObjectTest_Team"."LastEdited", "DataObjectTest_Team"."ID", CASE WHEN '.
|
'"DataObjectTest_Team"."LastEdited", "DataObjectTest_Team"."ID", CASE WHEN '.
|
||||||
'"DataObjectTest_Team"."ClassName" IS NOT NULL THEN "DataObjectTest_Team"."ClassName" ELSE ' .
|
'"DataObjectTest_Team"."ClassName" IS NOT NULL THEN "DataObjectTest_Team"."ClassName" ELSE ' .
|
||||||
'\'DataObjectTest_Team\' END AS "RecordClassName" FROM "DataObjectTest_Team" WHERE ' .
|
$db->prepStringForDB('DataObjectTest_Team').' END AS "RecordClassName" FROM "DataObjectTest_Team" WHERE ' .
|
||||||
'("DataObjectTest_Team"."ClassName" IN (\'DataObjectTest_SubTeam\'))';
|
'("DataObjectTest_Team"."ClassName" IN ('.$db->prepStringForDB('DataObjectTest_SubTeam').'))';
|
||||||
$this->assertEquals($expected, $playerList->sql());
|
$this->assertEquals($expected, $playerList->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testQueriedColumnsFromBaseTableAndSubTable() {
|
function testQueriedColumnsFromBaseTableAndSubTable() {
|
||||||
|
$db = DB::getConn();
|
||||||
$playerList = new DataList('DataObjectTest_SubTeam');
|
$playerList = new DataList('DataObjectTest_SubTeam');
|
||||||
$playerList = $playerList->setQueriedColumns(array('Title', 'SubclassDatabaseField'));
|
$playerList = $playerList->setQueriedColumns(array('Title', 'SubclassDatabaseField'));
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
|
$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
|
||||||
'"DataObjectTest_Team"."LastEdited", "DataObjectTest_Team"."Title", ' .
|
'"DataObjectTest_Team"."LastEdited", "DataObjectTest_Team"."Title", ' .
|
||||||
'"DataObjectTest_SubTeam"."SubclassDatabaseField", "DataObjectTest_Team"."ID", CASE WHEN ' .
|
'"DataObjectTest_SubTeam"."SubclassDatabaseField", "DataObjectTest_Team"."ID", CASE WHEN ' .
|
||||||
'"DataObjectTest_Team"."ClassName" IS NOT NULL THEN "DataObjectTest_Team"."ClassName" ELSE ' .
|
'"DataObjectTest_Team"."ClassName" IS NOT NULL THEN "DataObjectTest_Team"."ClassName" ELSE ' .
|
||||||
'\'DataObjectTest_Team\' END AS "RecordClassName" FROM "DataObjectTest_Team" LEFT JOIN ' .
|
$db->prepStringForDB('DataObjectTest_Team').' END AS "RecordClassName" FROM "DataObjectTest_Team" LEFT JOIN ' .
|
||||||
'"DataObjectTest_SubTeam" ON "DataObjectTest_SubTeam"."ID" = "DataObjectTest_Team"."ID" WHERE ' .
|
'"DataObjectTest_SubTeam" ON "DataObjectTest_SubTeam"."ID" = "DataObjectTest_Team"."ID" WHERE ' .
|
||||||
'("DataObjectTest_Team"."ClassName" IN (\'DataObjectTest_SubTeam\'))';
|
'("DataObjectTest_Team"."ClassName" IN ('.$db->prepStringForDB('DataObjectTest_SubTeam').'))';
|
||||||
$this->assertEquals($expected, $playerList->sql());
|
$this->assertEquals($expected, $playerList->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testQueriedColumnsFromBaseTable() {
|
function testQueriedColumnsFromBaseTable() {
|
||||||
|
$db = DB::getConn();
|
||||||
$playerList = new DataList('DataObjectTest_SubTeam');
|
$playerList = new DataList('DataObjectTest_SubTeam');
|
||||||
$playerList = $playerList->setQueriedColumns(array('Title'));
|
$playerList = $playerList->setQueriedColumns(array('Title'));
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
|
$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
|
||||||
'"DataObjectTest_Team"."LastEdited", "DataObjectTest_Team"."Title", "DataObjectTest_Team"."ID", ' .
|
'"DataObjectTest_Team"."LastEdited", "DataObjectTest_Team"."Title", "DataObjectTest_Team"."ID", ' .
|
||||||
'CASE WHEN "DataObjectTest_Team"."ClassName" IS NOT NULL THEN "DataObjectTest_Team"."ClassName" ELSE ' .
|
'CASE WHEN "DataObjectTest_Team"."ClassName" IS NOT NULL THEN "DataObjectTest_Team"."ClassName" ELSE ' .
|
||||||
'\'DataObjectTest_Team\' END AS "RecordClassName" FROM "DataObjectTest_Team" WHERE ' .
|
$db->prepStringForDB('DataObjectTest_Team').' END AS "RecordClassName" FROM "DataObjectTest_Team" WHERE ' .
|
||||||
'("DataObjectTest_Team"."ClassName" IN (\'DataObjectTest_SubTeam\'))';
|
'("DataObjectTest_Team"."ClassName" IN ('.$db->prepStringForDB('DataObjectTest_SubTeam').'))';
|
||||||
$this->assertEquals($expected, $playerList->sql());
|
$this->assertEquals($expected, $playerList->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testQueriedColumnsFromSubTable() {
|
function testQueriedColumnsFromSubTable() {
|
||||||
|
$db = DB::getConn();
|
||||||
$playerList = new DataList('DataObjectTest_SubTeam');
|
$playerList = new DataList('DataObjectTest_SubTeam');
|
||||||
$playerList = $playerList->setQueriedColumns(array('SubclassDatabaseField'));
|
$playerList = $playerList->setQueriedColumns(array('SubclassDatabaseField'));
|
||||||
$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
|
$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
|
||||||
'"DataObjectTest_Team"."LastEdited", "DataObjectTest_SubTeam"."SubclassDatabaseField", ' .
|
'"DataObjectTest_Team"."LastEdited", "DataObjectTest_SubTeam"."SubclassDatabaseField", ' .
|
||||||
'"DataObjectTest_Team"."ID", CASE WHEN "DataObjectTest_Team"."ClassName" IS NOT NULL THEN ' .
|
'"DataObjectTest_Team"."ID", CASE WHEN "DataObjectTest_Team"."ClassName" IS NOT NULL THEN ' .
|
||||||
'"DataObjectTest_Team"."ClassName" ELSE \'DataObjectTest_Team\' END AS "RecordClassName" FROM ' .
|
'"DataObjectTest_Team"."ClassName" ELSE '.$db->prepStringForDB('DataObjectTest_Team').' END AS "RecordClassName" FROM ' .
|
||||||
'"DataObjectTest_Team" LEFT JOIN "DataObjectTest_SubTeam" ON "DataObjectTest_SubTeam"."ID" = ' .
|
'"DataObjectTest_Team" LEFT JOIN "DataObjectTest_SubTeam" ON "DataObjectTest_SubTeam"."ID" = ' .
|
||||||
'"DataObjectTest_Team"."ID" WHERE ("DataObjectTest_Team"."ClassName" IN (\'DataObjectTest_SubTeam\'))';
|
'"DataObjectTest_Team"."ID" WHERE ("DataObjectTest_Team"."ClassName" IN ('.$db->prepStringForDB('DataObjectTest_SubTeam').'))';
|
||||||
$this->assertEquals($expected, $playerList->sql());
|
$this->assertEquals($expected, $playerList->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user