Skip to content
This repository
Browse code

BUG Use prepStringForDB consistently across the framework.

Also remove a line from DBFieldTest, it's redundant with the previous
line.

Ref: os7229
  • Loading branch information...
commit 70dcb55fe0537e010d32632b236fd49cb7fcfe7b 1 parent a033ddf
Mateusz U authored July 17, 2012
2  model/DataQuery.php
@@ -223,7 +223,7 @@ function getFinalisedQuery($queriedColumns = null) {
223 223
 		}
224 224
 
225 225
 		$query->selectField("\"$baseClass\".\"ID\"", "ID");
226  
-		$query->selectField("CASE WHEN \"$baseClass\".\"ClassName\" IS NOT NULL THEN \"$baseClass\".\"ClassName\" ELSE '$baseClass' END", "RecordClassName");
  226
+		$query->selectField("CASE WHEN \"$baseClass\".\"ClassName\" IS NOT NULL THEN \"$baseClass\".\"ClassName\" ELSE ".DB::getConn()->prepStringForDB($baseClass)." END", "RecordClassName");
227 227
 
228 228
 		// TODO: Versioned, Translatable, SiteTreeSubsites, etc, could probably be better implemented as subclasses of DataQuery
229 229
 
1  tests/model/DBFieldTest.php
@@ -76,7 +76,6 @@ function testPrepValueForDB() {
76 76
 		
77 77
 		/* Varchar behaviour */
78 78
 		$this->assertEquals($db->prepStringForDB("0"), singleton('Varchar')->prepValueForDB(0));
79  
-		$this->assertEquals("'0'", singleton('Varchar')->prepValueForDB(0));
80 79
 		$this->assertEquals("null", singleton('Varchar')->prepValueForDB(null));
81 80
 		$this->assertEquals("null", singleton('Varchar')->prepValueForDB(false));
82 81
 		$this->assertEquals("null", singleton('Varchar')->prepValueForDB(''));
9  tests/model/DataListTest.php
@@ -65,22 +65,25 @@ function testClone() {
65 65
 	}
66 66
 	
67 67
 	function testSql() {
  68
+		$db = DB::getConn();
68 69
 		$list = DataObjectTest_TeamComment::get();
69  
-		$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"';
  70
+		$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"';
70 71
 		$this->assertEquals($expected, $list->sql());
71 72
 	}
72 73
 	
73 74
 	function testInnerJoin() {
  75
+		$db = DB::getConn();
74 76
 		$list = DataObjectTest_TeamComment::get();
75 77
 		$list->innerJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
76  
-		$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"';
  78
+		$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"';
77 79
 		$this->assertEquals($expected, $list->sql());
78 80
 	}
79 81
 	
80 82
 	function testLeftJoin() {
  83
+		$db = DB::getConn();
81 84
 		$list = DataObjectTest_TeamComment::get();
82 85
 		$list->leftJoin('DataObjectTest_Team', '"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"', 'Team');
83  
-		$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"';
  86
+		$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"';
84 87
 		$this->assertEquals($expected, $list->sql());
85 88
 	}
86 89
 	
20  tests/model/DataObjectLazyLoadingTest.php
@@ -22,49 +22,53 @@ class DataObjectLazyLoadingTest extends SapphireTest {
22 22
 	);
23 23
 
24 24
 	function testQueriedColumnsID() {
  25
+		$db = DB::getConn();
25 26
 		$playerList = new DataList('DataObjectTest_SubTeam');
26 27
 		$playerList = $playerList->setQueriedColumns(array('ID'));
27 28
 		$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
28 29
 			'"DataObjectTest_Team"."LastEdited", "DataObjectTest_Team"."ID", CASE WHEN '.
29 30
 			'"DataObjectTest_Team"."ClassName" IS NOT NULL THEN "DataObjectTest_Team"."ClassName" ELSE ' .
30  
-			'\'DataObjectTest_Team\' END AS "RecordClassName" FROM "DataObjectTest_Team" WHERE ' .
31  
-			'("DataObjectTest_Team"."ClassName" IN (\'DataObjectTest_SubTeam\'))';
  31
+			$db->prepStringForDB('DataObjectTest_Team').' END AS "RecordClassName" FROM "DataObjectTest_Team" WHERE ' .
  32
+			'("DataObjectTest_Team"."ClassName" IN ('.$db->prepStringForDB('DataObjectTest_SubTeam').'))';
32 33
 		$this->assertEquals($expected, $playerList->sql());
33 34
 	}
34 35
 
35 36
 	function testQueriedColumnsFromBaseTableAndSubTable() {
  37
+		$db = DB::getConn();
36 38
 		$playerList = new DataList('DataObjectTest_SubTeam');
37 39
 		$playerList = $playerList->setQueriedColumns(array('Title', 'SubclassDatabaseField'));
38 40
 		$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
39 41
 			'"DataObjectTest_Team"."LastEdited", "DataObjectTest_Team"."Title", ' .
40 42
 			'"DataObjectTest_SubTeam"."SubclassDatabaseField", "DataObjectTest_Team"."ID", CASE WHEN ' .
41 43
 			'"DataObjectTest_Team"."ClassName" IS NOT NULL THEN "DataObjectTest_Team"."ClassName" ELSE ' .
42  
-			'\'DataObjectTest_Team\' END AS "RecordClassName" FROM "DataObjectTest_Team" LEFT JOIN ' .
  44
+			$db->prepStringForDB('DataObjectTest_Team').' END AS "RecordClassName" FROM "DataObjectTest_Team" LEFT JOIN ' .
43 45
 			'"DataObjectTest_SubTeam" ON "DataObjectTest_SubTeam"."ID" = "DataObjectTest_Team"."ID" WHERE ' .
44  
-			'("DataObjectTest_Team"."ClassName" IN (\'DataObjectTest_SubTeam\'))';
  46
+			'("DataObjectTest_Team"."ClassName" IN ('.$db->prepStringForDB('DataObjectTest_SubTeam').'))';
45 47
 		$this->assertEquals($expected, $playerList->sql());
46 48
 	}
47 49
 
48 50
 	function testQueriedColumnsFromBaseTable() {
  51
+		$db = DB::getConn();
49 52
 		$playerList = new DataList('DataObjectTest_SubTeam');
50 53
 		$playerList = $playerList->setQueriedColumns(array('Title'));
51 54
 		$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
52 55
 			'"DataObjectTest_Team"."LastEdited", "DataObjectTest_Team"."Title", "DataObjectTest_Team"."ID", ' .
53 56
 			'CASE WHEN "DataObjectTest_Team"."ClassName" IS NOT NULL THEN "DataObjectTest_Team"."ClassName" ELSE ' .
54  
-			'\'DataObjectTest_Team\' END AS "RecordClassName" FROM "DataObjectTest_Team" WHERE ' .
55  
-			'("DataObjectTest_Team"."ClassName" IN (\'DataObjectTest_SubTeam\'))';
  57
+			$db->prepStringForDB('DataObjectTest_Team').' END AS "RecordClassName" FROM "DataObjectTest_Team" WHERE ' .
  58
+			'("DataObjectTest_Team"."ClassName" IN ('.$db->prepStringForDB('DataObjectTest_SubTeam').'))';
56 59
 		$this->assertEquals($expected, $playerList->sql());
57 60
 	}
58 61
 
59 62
 	function testQueriedColumnsFromSubTable() {
  63
+		$db = DB::getConn();
60 64
 		$playerList = new DataList('DataObjectTest_SubTeam');
61 65
 		$playerList = $playerList->setQueriedColumns(array('SubclassDatabaseField'));
62 66
 		$expected = 'SELECT DISTINCT "DataObjectTest_Team"."ClassName", "DataObjectTest_Team"."Created", ' .
63 67
 			'"DataObjectTest_Team"."LastEdited", "DataObjectTest_SubTeam"."SubclassDatabaseField", ' .
64 68
 			'"DataObjectTest_Team"."ID", CASE WHEN "DataObjectTest_Team"."ClassName" IS NOT NULL THEN ' .
65  
-			'"DataObjectTest_Team"."ClassName" ELSE \'DataObjectTest_Team\' END AS "RecordClassName" FROM ' .
  69
+			'"DataObjectTest_Team"."ClassName" ELSE '.$db->prepStringForDB('DataObjectTest_Team').' END AS "RecordClassName" FROM ' .
66 70
 			'"DataObjectTest_Team" LEFT JOIN "DataObjectTest_SubTeam" ON "DataObjectTest_SubTeam"."ID" = ' .
67  
-			'"DataObjectTest_Team"."ID" WHERE ("DataObjectTest_Team"."ClassName" IN (\'DataObjectTest_SubTeam\'))';
  71
+			'"DataObjectTest_Team"."ID" WHERE ("DataObjectTest_Team"."ClassName" IN ('.$db->prepStringForDB('DataObjectTest_SubTeam').'))';
68 72
 		$this->assertEquals($expected, $playerList->sql());
69 73
 	}
70 74
 

0 notes on commit 70dcb55

Please sign in to comment.
Something went wrong with that request. Please try again.