TYPO3 CMS  TYPO3_6-2
DatabaseConnectionMssqlTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $subject;
26 
32  public function setUp() {
33  $configuration = array(
34  'handlerCfg' => array(
35  '_DEFAULT' => array(
36  'type' => 'adodb',
37  'config' => array(
38  'driver' => 'mssql',
39  ),
40  ),
41  ),
42  'mapping' => array(
43  'tx_templavoila_tmplobj' => array(
44  'mapFieldNames' => array(
45  'datastructure' => 'ds',
46  ),
47  ),
48  'Members' => array(
49  'mapFieldNames' => array(
50  'pid' => '0',
51  'cruser_id' => '1',
52  'uid' => 'MemberID',
53  ),
54  ),
55  ),
56  );
57  $this->subject = $this->prepareSubject('mssql', $configuration);
58  }
59 
64  $this->assertTrue($this->subject->runningADOdbDriver('mssql'));
65  }
66 
71  public function findInSetIsProperlyRemapped() {
72  $expected = 'SELECT * FROM "fe_users" WHERE \',\'+"usergroup"+\',\' LIKE \'%,10,%\'';
73  $result = $this->subject->SELECTquery('*', 'fe_users', 'FIND_IN_SET(10, usergroup)');
74  $this->assertEquals($expected, $this->cleanSql($result));
75  }
76 
81  public function canParseSingleQuote() {
82  $parseString = 'SELECT * FROM pages WHERE title=\'1\'\'\' AND deleted=0';
83  $components = $this->subject->SQLparser->_callRef('parseSELECT', $parseString);
84 
85  $this->assertTrue(is_array($components), $components);
86  $this->assertEmpty($components['parseString']);
87  }
88 
90  // Tests concerning remapping with
91  // external (non-TYPO3) databases
93 
97  public function canRemapPidToZero() {
98  $selectFields = 'uid, FirstName, LastName';
99  $fromTables = 'Members';
100  $whereClause = 'pid=0 AND cruser_id=1';
101  $groupBy = '';
102  $orderBy = '';
103 
104  $remappedParameters = $this->subject->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
105  $result = $this->subject->_call('SELECTqueryFromArray', $remappedParameters);
106  $expected = 'SELECT "MemberID", "FirstName", "LastName" FROM "Members" WHERE 0 = 0 AND 1 = 1';
107  $this->assertEquals($expected, $this->cleanSql($result));
108  }
109 
111  // Tests concerning advanced operators
113 
118  $result = $this->subject->SELECTquery('*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure)>0 THEN 2' . ' ELSE 1' . ' END AS scope', 'tx_templavoila_tmplobj', '1=1');
119  $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "datastructure") > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
120  $this->assertEquals($expected, $this->cleanSql($result));
121  }
122 
128  $result = $this->subject->SELECTquery('*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure, 4)>0 THEN 2' . ' ELSE 1' . ' END AS scope', 'tx_templavoila_tmplobj', '1=1');
129  $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "datastructure", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
130  $this->assertEquals($expected, $this->cleanSql($result));
131  }
132 
138  $selectFields = '*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure, 4)>0 THEN 2' . ' ELSE 1' . ' END AS scope';
139  $fromTables = 'tx_templavoila_tmplobj';
140  $whereClause = '1=1';
141  $groupBy = '';
142  $orderBy = '';
143  $remappedParameters = $this->subject->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
144 
145  $result = $this->subject->_call('SELECTqueryFromArray', $remappedParameters);
146  $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "ds", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
147  $this->assertEquals($expected, $this->cleanSql($result));
148  }
149 
155  $selectFields = '*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', tx_templavoila_tmplobj.datastructure, 4)>0 THEN 2' . ' ELSE 1' . ' END AS scope';
156  $fromTables = 'tx_templavoila_tmplobj';
157  $whereClause = '1=1';
158  $groupBy = '';
159  $orderBy = '';
160  $remappedParameters = $this->subject->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
161 
162  $result = $this->subject->_call('SELECTqueryFromArray', $remappedParameters);
163  $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "tx_templavoila_tmplobj"."ds", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
164  $this->assertEquals($expected, $this->cleanSql($result));
165  }
166 
171  public function IfNullIsProperlyRemapped() {
172  $result = $this->subject->SELECTquery('*', 'tt_news_cat_mm', 'IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22)');
173  $expected = 'SELECT * FROM "tt_news_cat_mm" WHERE ISNULL("tt_news_cat_mm"."uid_foreign", 0) IN (21,22)';
174  $this->assertEquals($expected, $this->cleanSql($result));
175  }
176 
181  public function singleQuotesAreProperlyEscaped() {
182  $result = $this->subject->SELECTquery(
183  'ISEC.phash',
184  'index_section ISEC, index_fulltext IFT',
185  'IFT.fulltextdata LIKE \'%' . $this->subject->quoteStr("Don't worry", 'index_fulltext')
186  . '%\' AND ISEC.phash = IFT.phash',
187  'ISEC.phash'
188  );
189  $expected = 'SELECT "ISEC"."phash" FROM "index_section" "ISEC", "index_fulltext" "IFT" WHERE "IFT"."fulltextdata" LIKE \'%Don\'\'t worry%\' AND "ISEC"."phash" = "IFT"."phash" GROUP BY "ISEC"."phash"';
190  $this->assertEquals($expected, $this->cleanSql($result));
191  }
192 
193 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.