TYPO3 CMS  TYPO3_6-2
SqlParserTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $subject;
26 
30  public function setUp() {
31  $subject = $this->getAccessibleMock('TYPO3\\CMS\\Dbal\\Database\\SqlParser', array('dummy'), array(), '', FALSE);
32 
33  $mockDatabaseConnection = $this->getMock('TYPO3\\CMS\\Dbal\\Database\\DatabaseConnection', array(), array(), '', FALSE);
34  $mockDatabaseConnection->lastHandlerKey = '_DEFAULT';
35  $subject->_set('databaseConnection', $mockDatabaseConnection);
36 
37  $this->subject = $subject;
38  }
39 
43  public function canExtractPartsOfAQuery() {
44  $parseString = 'SELECT *' . LF . 'FROM pages WHERE pid IN (1,2,3,4)';
45  $regex = '^SELECT[[:space:]]+(.*)[[:space:]]+';
46  $trimAll = TRUE;
47  $fields = $this->subject->_callRef('nextPart', $parseString, $regex, $trimAll);
48  $this->assertEquals('*', $fields);
49  $this->assertEquals('FROM pages WHERE pid IN (1,2,3,4)', $parseString);
50  $regex = '^FROM ([^)]+) WHERE';
51  $table = $this->subject->_callRef('nextPart', $parseString, $regex);
52  $this->assertEquals('pages', $table);
53  $this->assertEquals('pages WHERE pid IN (1,2,3,4)', $parseString);
54  }
55 
59  public function canGetIntegerValue() {
60  $parseString = '1024';
61  $result = $this->subject->_callRef('getValue', $parseString);
62  $expected = array(1024);
63  $this->assertEquals($expected, $result);
64  }
65 
70  public function canGetStringValue() {
71  $parseString = '"some owner\\\'s string"';
72  $result = $this->subject->_callRef('getValue', $parseString);
73  $expected = array('some owner\'s string', '"');
74  $this->assertEquals($expected, $result);
75  }
76 
82  $parseString = '\'some owner\\\'s string\'';
83  $result = $this->subject->_callRef('getValue', $parseString);
84  $expected = array('some owner\'s string', '\'');
85  $this->assertEquals($expected, $result);
86  }
87 
93  $parseString = '"the \\"owner\\" is here"';
94  $result = $this->subject->_callRef('getValue', $parseString);
95  $expected = array('the "owner" is here', '"');
96  $this->assertEquals($expected, $result);
97  }
98 
102  public function canGetListOfValues() {
103  $parseString = '( 1, 2, 3 ,4)';
104  $operator = 'IN';
105  $result = $this->subject->_callRef('getValue', $parseString, $operator);
106  $expected = array(
107  array(1),
108  array(2),
109  array(3),
110  array(4)
111  );
112  $this->assertEquals($expected, $result);
113  }
114 
118  public function parseWhereClauseReturnsArray() {
119  $parseString = 'uid IN (1,2) AND (starttime < ' . time() . ' OR cruser_id + 10 < 20)';
120  $result = $this->subject->parseWhereClause($parseString);
121  $this->assertInternalType('array', $result);
122  $this->assertEmpty($parseString);
123  }
124 
128  public function canSelectAllFieldsFromPages() {
129  $sql = 'SELECT * FROM pages';
130  $expected = $sql;
131  $result = $this->subject->debug_testSQL($sql);
132  $this->assertEquals($expected, $this->cleanSql($result));
133  }
134 
138  public function canParseTruncateTable() {
139  $sql = 'TRUNCATE TABLE be_users';
140  $expected = $sql;
141  $result = $this->subject->debug_testSQL($sql);
142  $this->assertEquals($expected, $this->cleanSql($result));
143  }
144 
150  $parseString = '((scheduled BETWEEN 1265068628 AND 1265068828 ) OR scheduled <= 1265068728) AND NOT exec_time AND NOT process_id AND page_id=1 AND parameters_hash = \'854e9a2a77\'';
151  $result = $this->subject->parseWhereClause($parseString);
152  $this->assertInternalType('array', $result);
153  $this->assertEmpty($parseString);
154 
155  $result = $this->subject->compileWhereClause($result);
156  $expected = '((scheduled BETWEEN 1265068628 AND 1265068828) OR scheduled <= 1265068728) AND NOT exec_time AND NOT process_id AND page_id = 1 AND parameters_hash = \'854e9a2a77\'';
157  $this->assertEquals($expected, $this->cleanSql($result));
158  }
159 
164  $parseString = 'INSERT INTO static_country_zones VALUES(\'483\', \'0\', \'NL\', \'NLD\', \'528\', \'DR\', \'Drenthe\', \'\');';
165  $components = $this->subject->_callRef('parseINSERT', $parseString);
166  $this->assertInternalType('array', $components);
167 
168  $result = $this->subject->_callRef('compileINSERT', $components);
169  $expected = 'INSERT INTO static_country_zones VALUES (\'483\',\'0\',\'NL\',\'NLD\',\'528\',\'DR\',\'Drenthe\',\'\')';
170  $this->assertEquals($expected, $this->cleanSql($result));
171  }
172 
177  $parseString = 'INSERT INTO static_country_zones VALUES (\'483\', \'0\', \'NL\', \'NLD\', \'528\', \'DR\', \'Drenthe\', \'\');';
178  $components = $this->subject->_callRef('parseINSERT', $parseString);
179  $this->assertInternalType('array', $components);
180 
181  $result = $this->subject->_callRef('compileINSERT', $components);
182  $expected = 'INSERT INTO static_country_zones VALUES (\'483\',\'0\',\'NL\',\'NLD\',\'528\',\'DR\',\'Drenthe\',\'\')';
183  $this->assertEquals($expected, $this->cleanSql($result));
184  }
185 
189  public function canParseInsertWithFields() {
190  $parseString = 'INSERT INTO static_territories (uid, pid, tr_iso_nr, tr_parent_iso_nr, tr_name_en) ';
191  $parseString .= 'VALUES (\'1\', \'0\', \'2\', \'0\', \'Africa\');';
192  $components = $this->subject->_callRef('parseINSERT', $parseString);
193  $this->assertInternalType('array', $components);
194 
195  $result = $this->subject->_callRef('compileINSERT', $components);
196  $expected = 'INSERT INTO static_territories (uid,pid,tr_iso_nr,tr_parent_iso_nr,tr_name_en) ';
197  $expected .= 'VALUES (\'1\',\'0\',\'2\',\'0\',\'Africa\')';
198  $this->assertEquals($expected, $this->cleanSql($result));
199  }
200 
204  public function canParseExtendedInsert() {
205  $parseString = 'INSERT INTO static_territories VALUES (\'1\', \'0\', \'2\', \'0\', \'Africa\'),(\'2\', \'0\', \'9\', \'0\', \'Oceania\'),' . '(\'3\', \'0\', \'19\', \'0\', \'Americas\'),(\'4\', \'0\', \'142\', \'0\', \'Asia\');';
206  $components = $this->subject->_callRef('parseINSERT', $parseString);
207  $this->assertInternalType('array', $components);
208 
209  $result = $this->subject->_callRef('compileINSERT', $components);
210  $expected = 'INSERT INTO static_territories VALUES (\'1\',\'0\',\'2\',\'0\',\'Africa\'),(\'2\',\'0\',\'9\',\'0\',\'Oceania\'),(\'3\',\'0\',\'19\',\'0\',\'Americas\'),(\'4\',\'0\',\'142\',\'0\',\'Asia\')';
211  $this->assertEquals($expected, $this->cleanSql($result));
212  }
213 
218  $parseString = 'INSERT INTO static_territories (uid, pid, tr_iso_nr, tr_parent_iso_nr, tr_name_en) ';
219  $parseString .= 'VALUES (\'1\', \'0\', \'2\', \'0\', \'Africa\'),(\'2\', \'0\', \'9\', \'0\', \'Oceania\');';
220  $components = $this->subject->_callRef('parseINSERT', $parseString);
221  $this->assertInternalType('array', $components);
222 
223  $result = $this->subject->_callRef('compileINSERT', $components);
224  $expected = 'INSERT INTO static_territories (uid,pid,tr_iso_nr,tr_parent_iso_nr,tr_name_en) ';
225  $expected .= 'VALUES (\'1\',\'0\',\'2\',\'0\',\'Africa\'),(\'2\',\'0\',\'9\',\'0\',\'Oceania\')';
226  $this->assertEquals($expected, $this->cleanSql($result));
227  }
228 
233  public function canParseIfNullOperator() {
234  $parseString = 'IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22)';
235  $result = $this->subject->parseWhereClause($parseString);
236  $this->assertInternalType('array', $result);
237  $this->assertEmpty($parseString);
238  }
239 
245  $parseString = '1=1 AND IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22) AND tt_news.sys_language_uid IN (0,-1) ';
246  $parseString .= 'AND tt_news.pid > 0 AND tt_news.pid IN (61) AND tt_news.deleted=0 AND tt_news.t3ver_state<=0 ';
247  $parseString .= 'AND tt_news.hidden=0 AND tt_news.starttime<=1266065460 AND (tt_news.endtime=0 OR tt_news.endtime>1266065460) ';
248  $parseString .= 'AND (tt_news.fe_group=\'\' OR tt_news.fe_group IS NULL OR tt_news.fe_group=\'0\' ';
249  $parseString .= 'OR (tt_news.fe_group LIKE \'%,0,%\' OR tt_news.fe_group LIKE \'0,%\' OR tt_news.fe_group LIKE \'%,0\' ';
250  $parseString .= 'OR tt_news.fe_group=\'0\') OR (tt_news.fe_group LIKE \'%,-1,%\' OR tt_news.fe_group LIKE \'-1,%\' ';
251  $parseString .= 'OR tt_news.fe_group LIKE \'%,-1\' OR tt_news.fe_group=\'-1\'))';
252 
253  $result = $this->subject->parseWhereClause($parseString);
254  $this->assertInternalType('array', $result);
255  $this->assertEmpty($parseString);
256  }
257 
262  public function canCompileIfNullOperator() {
263  $parseString = 'SELECT * FROM tx_irfaq_q_cat_mm WHERE IFNULL(tx_irfaq_q_cat_mm.uid_foreign,0) = 1';
264  $components = $this->subject->_callRef('parseSELECT', $parseString);
265  $this->assertInternalType('array', $components);
266 
267  $result = $this->subject->_callRef('compileSELECT', $components);
268  $expected = 'SELECT * FROM tx_irfaq_q_cat_mm WHERE IFNULL(tx_irfaq_q_cat_mm.uid_foreign, 0) = 1';
269  $this->assertEquals($expected, $this->cleanSql($result));
270  }
271 
276  public function canParseCastOperator() {
277  $parseString = 'CAST(parent AS CHAR) != \'\'';
278  $result = $this->subject->parseWhereClause($parseString);
279  $this->assertInternalType('array', $result);
280  $this->assertEmpty($parseString);
281  }
282 
287  public function canCompileCastOperator() {
288  $parseString = 'SELECT * FROM sys_category WHERE CAST(parent AS CHAR) != \'\'';
289  $components = $this->subject->_callRef('parseSELECT', $parseString);
290  $this->assertInternalType('array', $components);
291 
292  $result = $this->subject->_callRef('compileSELECT', $components);
293  $expected = 'SELECT * FROM sys_category WHERE CAST(parent AS CHAR) != \'\'';
294  $this->assertEquals($expected, $this->cleanSql($result));
295  }
296 
301  public function canParseAlterEngineStatement() {
302  $parseString = 'ALTER TABLE tx_realurl_pathcache ENGINE=InnoDB';
303  $components = $this->subject->_callRef('parseALTERTABLE', $parseString);
304  $this->assertInternalType('array', $components);
305 
306  $result = $this->subject->_callRef('compileALTERTABLE', $components);
307  $expected = 'ALTER TABLE tx_realurl_pathcache ENGINE = InnoDB';
308  $this->assertEquals($expected, $this->cleanSql($result));
309  }
310 
316  $parseString = 'ALTER TABLE `index_phash` DEFAULT CHARACTER SET utf8';
317  $components = $this->subject->_callRef('parseALTERTABLE', $parseString);
318  $this->assertInternalType('array', $components);
319 
320  $result = $this->subject->_callRef('compileALTERTABLE', $components);
321  $expected = 'ALTER TABLE index_phash DEFAULT CHARACTER SET utf8';
322  $this->assertEquals($expected, $this->cleanSql($result));
323  }
324 
329  public function canParseFindInSetStatement() {
330  $parseString = 'SELECT * FROM fe_users WHERE FIND_IN_SET(10, usergroup)';
331  $components = $this->subject->_callRef('parseSELECT', $parseString);
332  $this->assertInternalType('array', $components);
333 
334  $result = $this->subject->_callRef('compileSELECT', $components);
335  $expected = 'SELECT * FROM fe_users WHERE FIND_IN_SET(10, usergroup)';
336  $this->assertEquals($expected, $this->cleanSql($result));
337  }
338 
343  public function canParseSingleQuote() {
344  $parseString = 'SELECT * FROM pages WHERE title=\'1\\\'\' AND deleted=0';
345  $result = $this->subject->_callRef('parseSELECT', $parseString);
346  $this->assertInternalType('array', $result);
347  $this->assertEmpty($result['parseString']);
348  }
349 
351  // Tests concerning JOINs
353 
357  $parseString = 'be_users INNER JOIN pages ON pages.cruser_id = be_users.uid';
358 
359  $result = $this->subject->parseFromTables($parseString);
360  $this->assertInternalType('array', $result);
361  $this->assertEmpty($parseString);
362  }
363 
368  $parseString = 'be_users LEFT OUTER JOIN pages ON be_users.uid = pages.cruser_id';
369 
370  $result = $this->subject->parseFromTables($parseString);
371  $this->assertInternalType('array', $result);
372  $this->assertEmpty($parseString);
373  }
374 
380  $parseString = 'tx_powermail_fieldsets RIGHT JOIN tt_content ON tx_powermail_fieldsets.tt_content = tt_content.uid';
381 
382  $result = $this->subject->parseFromTables($parseString);
383  $this->assertInternalType('array', $result);
384  $this->assertEmpty($parseString);
385  }
386 
391  $parseString = 'be_users LEFT OUTER JOIN pages ON be_users.uid = pages.cruser_id INNER JOIN cache_pages cp ON cp.page_id = pages.uid';
392  $result = $this->subject->parseFromTables($parseString);
393  $this->assertInternalType('array', $result);
394  $this->assertEmpty($parseString);
395  }
396 
402  $parseString = 'tx_powermail_fieldsets RIGHT JOIN tt_content ON tx_powermail_fieldsets.tt_content = tt_content.uid LEFT JOIN tx_powermail_fields ON tx_powermail_fieldsets.uid = tx_powermail_fields.fieldset';
403  $result = $this->subject->parseFromTables($parseString);
404  $this->assertInternalType('array', $result);
405  $this->assertEmpty($parseString);
406  }
407 
411  public function canUseInnerJoinInSelect() {
412  $sql = 'SELECT pages.uid, be_users.username FROM be_users INNER JOIN pages ON pages.cruser_id = be_users.uid';
413 
414  $result = $this->subject->debug_testSQL($sql);
415  $expected = 'SELECT pages.uid, be_users.username FROM be_users INNER JOIN pages ON pages.cruser_id=be_users.uid';
416  $this->assertEquals($expected, $this->cleanSql($result));
417  }
418 
423  $sql = 'SELECT * FROM tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid = tt_news_cat_mm.uid_foreign INNER JOIN tt_news ON tt_news.uid = tt_news_cat_mm.uid_local';
424 
425  $result = $this->subject->debug_testSQL($sql);
426  $expected = 'SELECT * FROM tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid=tt_news_cat_mm.uid_foreign INNER JOIN tt_news ON tt_news.uid=tt_news_cat_mm.uid_local';
427  $this->assertEquals($expected, $this->cleanSql($result));
428  }
429 
434  public function canParseMultipleJoinConditions() {
435  $sql = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.pid = T1.uid AND T2.size = 4 WHERE T1.cr_userid = 1';
436 
437  $result = $this->subject->debug_testSQL($sql);
438  $expected = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.pid=T1.uid AND T2.size=4 WHERE T1.cr_userid = 1';
439  $this->assertEquals($expected, $this->cleanSql($result));
440  }
441 
447  $sql = 'SELECT * FROM sys_file_processedfile LEFT JOIN sys_registry ON entry_key = sys_file_processedfile.uid AND entry_namespace = \'ProcessedFileChecksumUpdate\'';
448 
449  $result = $this->subject->debug_testSQL($sql);
450  $expected = 'SELECT * FROM sys_file_processedfile LEFT JOIN sys_registry ON entry_key=sys_file_processedfile.uid AND entry_namespace=\'ProcessedFileChecksumUpdate\'';
451  $this->assertEquals($expected, $this->cleanSql($result));
452  }
453 
459  $sql = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.size < 4 OR T2.pid = T1.uid WHERE T1.cr_userid = 1';
460 
461  $result = $this->subject->debug_testSQL($sql);
462  $expected = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.size<4 OR T2.pid=T1.uid WHERE T1.cr_userid = 1';
463  $this->assertEquals($expected, $this->cleanSql($result));
464  }
465 
467  // Tests concerning DB management
469 
474  $parseString = '
475  CREATE TABLE tx_realurl_uniqalias (
476  uid int(11) NOT NULL auto_increment,
477  tstamp int(11) DEFAULT \'0\' NOT NULL,
478  tablename varchar(60) DEFAULT \'\' NOT NULL,
479  field_alias varchar(255) DEFAULT \'\' NOT NULL,
480  field_id varchar(60) DEFAULT \'\' NOT NULL,
481  value_alias varchar(255) DEFAULT \'\' NOT NULL,
482  value_id int(11) DEFAULT \'0\' NOT NULL,
483  lang int(11) DEFAULT \'0\' NOT NULL,
484  expire int(11) DEFAULT \'0\' NOT NULL,
485 
486  PRIMARY KEY (uid),
487  KEY tablename (tablename),
488  KEY bk_realurl01 (field_alias,field_id,value_id,lang,expire),
489  KEY bk_realurl02 (tablename,field_alias,field_id,value_alias(220),expire)
490  );
491  ';
492  $result = $this->subject->_callRef('parseCREATETABLE', $parseString);
493  $this->assertInternalType('array', $result);
494  }
495 
501  $parseString = 'ALTER TABLE tx_realurl_uniqalias ADD KEY bk_realurl02 (tablename,field_alias,field_id,value_alias(220),expire)';
502  $result = $this->subject->_callRef('parseALTERTABLE', $parseString);
503  $this->assertInternalType('array', $result);
504  }
505 
510  public function canParseUniqueIndexCreation() {
511  $sql = 'ALTER TABLE static_territories ADD UNIQUE uid (uid)';
512  $expected = $sql;
513  $alterTables = $this->subject->_callRef('parseALTERTABLE', $sql);
514  $queries = $this->subject->compileSQL($alterTables);
515  $this->assertEquals($expected, $queries);
516  }
517 
519  // Tests concerning subqueries
521 
525  public function inWhereClauseSupportsSubquery() {
526  $parseString = 'process_id IN (SELECT process_id FROM tx_crawler_process WHERE active=0 AND deleted=0)';
527  $result = $this->subject->parseWhereClause($parseString);
528  $this->assertInternalType('array', $result);
529  $this->assertEmpty($parseString);
530  }
531 
537  $sql = 'SELECT * FROM tx_crawler_queue WHERE process_id IN (SELECT process_id FROM tx_crawler_process WHERE active=0 AND deleted=0)';
538 
539  $result = $this->subject->debug_testSQL($sql);
540  $expected = 'SELECT * FROM tx_crawler_queue WHERE process_id IN (SELECT process_id FROM tx_crawler_process WHERE active = 0 AND deleted = 0)';
541  $this->assertEquals($expected, $this->cleanSql($result));
542  }
543 
549  $parseString = 'EXISTS (SELECT * FROM tx_crawler_queue WHERE tx_crawler_queue.process_id = tx_crawler_process.process_id AND tx_crawler_queue.exec_time = 0)';
550  $result = $this->subject->parseWhereClause($parseString);
551  $this->assertInternalType('array', $result);
552  $this->assertEmpty($parseString);
553  }
554 
559  public function existsClauseIsProperlyCompiled() {
560  $sql = 'SELECT * FROM tx_crawler_process WHERE active = 0 AND NOT EXISTS (SELECT * FROM tx_crawler_queue WHERE tx_crawler_queue.process_id = tx_crawler_process.process_id AND tx_crawler_queue.exec_time = 0)';
561 
562  $result = $this->subject->debug_testSQL($sql);
563  $expected = 'SELECT * FROM tx_crawler_process WHERE active = 0 AND NOT EXISTS (SELECT * FROM tx_crawler_queue WHERE tx_crawler_queue.process_id = tx_crawler_process.process_id AND tx_crawler_queue.exec_time = 0)';
564  $this->assertEquals($expected, $this->cleanSql($result));
565  }
566 
568  // Tests concerning advanced operators
570 
575  $parseString = 'CASE WHEN 1>0 THEN 2 ELSE 1 END AS foo, other_column';
576  $result = $this->subject->parseFieldList($parseString);
577  $this->assertInternalType('array', $result);
578  $this->assertEmpty($parseString);
579  }
580 
586  $sql = 'SELECT CASE WHEN 1>0 THEN 2 ELSE 1 END AS foo, other_column FROM mytable';
587 
588  $result = $this->subject->debug_testSQL($sql);
589  $expected = 'SELECT CASE WHEN 1 > 0 THEN 2 ELSE 1 END AS foo, other_column FROM mytable';
590  $this->assertEquals($expected, $this->cleanSql($result));
591  }
592 
598  $parseString = 'CASE column WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS number';
599  $result = $this->subject->parseFieldList($parseString);
600  $this->assertInternalType('array', $result);
601  $this->assertEmpty($parseString);
602  }
603 
609  $sql = 'SELECT CASE column WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS number FROM mytable';
610 
611  $result = $this->subject->debug_testSQL($sql);
612  $expected = 'SELECT CASE column WHEN 1 THEN \'one\' WHEN 2 THEN \'two\' ELSE \'out of range\' END AS number FROM mytable';
613  $this->assertEquals($expected, $this->cleanSql($result));
614  }
615 
620  public function locateIsSupported() {
621  $sql = 'SELECT * FROM tx_templavoila_tmplobj WHERE LOCATE(\'(fce)\', datastructure)>0';
622 
623  $result = $this->subject->debug_testSQL($sql);
624  $expected = 'SELECT * FROM tx_templavoila_tmplobj WHERE LOCATE(\'(fce)\', datastructure) > 0';
625  $this->assertEquals($expected, $this->cleanSql($result));
626  }
627 
632  public function locateWithPositionIsSupported() {
633  $sql = 'SELECT * FROM tx_templavoila_tmplobj WHERE LOCATE(\'(fce)\' , datastructure ,10)>0';
634  $expected = 'SELECT * FROM tx_templavoila_tmplobj WHERE LOCATE(\'(fce)\', datastructure, 10) > 0';
635  $result = $this->cleanSql($this->subject->debug_testSQL($sql));
636  $this->assertEquals($expected, $result);
637  }
638 
644  public function locateWithinCaseIsSupported() {
645  $sql = 'SELECT *, CASE WHEN LOCATE(\'(fce)\', datastructure)>0 THEN 2 ELSE 1 END AS scope FROM tx_templavoila_tmplobj';
646 
647  $result = $this->subject->debug_testSQL($sql);
648  $expected = 'SELECT *, CASE WHEN LOCATE(\'(fce)\', datastructure) > 0 THEN 2 ELSE 1 END AS scope FROM tx_templavoila_tmplobj';
649  $this->assertEquals($expected, $this->cleanSql($result));
650  }
651 
653  // Tests concerning prepared queries
655 
659  public function namedPlaceholderIsSupported() {
660  $sql = 'SELECT * FROM pages WHERE pid = :pid ORDER BY title';
661 
662  $result = $this->subject->debug_testSQL($sql);
663  $expected = 'SELECT * FROM pages WHERE pid = :pid ORDER BY title';
664  $this->assertEquals($expected, $this->cleanSql($result));
665  }
666 
672  $sql = 'SELECT * FROM pages WHERE pid = ? ORDER BY title';
673 
674  $result = $this->subject->debug_testSQL($sql);
675  $expected = 'SELECT * FROM pages WHERE pid = ? ORDER BY title';
676  $this->assertEquals($expected, $this->cleanSql($result));
677  }
678 
683  public function parametersAreReferenced() {
684  $sql = 'SELECT * FROM pages WHERE pid = :pid1 OR pid = :pid2';
685  $components = $this->subject->_callRef('parseSELECT', $sql);
686  $this->assertInternalType('array', $components['parameters']);
687  $this->assertEquals(2, count($components['parameters']));
688  $this->assertTrue(isset($components['parameters'][':pid1']));
689  $this->assertTrue(isset($components['parameters'][':pid2']));
690  }
691 
697  $sql = 'SELECT * FROM pages WHERE uid = :pageId OR uid IN (SELECT uid FROM pages WHERE pid = :pageId)';
698  $pageId = 12;
699  $components = $this->subject->_callRef('parseSELECT', $sql);
700  $components['parameters'][':pageId'][0] = $pageId;
701 
702  $result = $this->subject->_callRef('compileSELECT', $components);
703  $expected = 'SELECT * FROM pages WHERE uid = 12 OR uid IN (SELECT uid FROM pages WHERE pid = 12)';
704  $this->assertEquals($expected, $this->cleanSql($result));
705  }
706 
712  $sql = 'SELECT * FROM pages WHERE pid = :pid AND title NOT LIKE \':pid\'';
713  $pid = 12;
714  $components = $this->subject->_callRef('parseSELECT', $sql);
715  $components['parameters'][':pid'][0] = $pid;
716 
717  $result = $this->subject->_callRef('compileSELECT', $components);
718  $expected = 'SELECT * FROM pages WHERE pid = ' . $pid . ' AND title NOT LIKE \':pid\'';
719  $this->assertEquals($expected, $this->cleanSql($result));
720  }
721 
727  $sql = 'SELECT * FROM pages WHERE pid = ? AND timestamp < ? AND title != \'How to test?\'';
728  $parameterValues = array(12, 1281782690);
729  $components = $this->subject->_callRef('parseSELECT', $sql);
730  for ($i = 0; $i < count($components['parameters']['?']); $i++) {
731  $components['parameters']['?'][$i][0] = $parameterValues[$i];
732  }
733 
734  $result = $this->subject->_callRef('compileSELECT', $components);
735  $expected = 'SELECT * FROM pages WHERE pid = 12 AND timestamp < 1281782690 AND title != \'How to test?\'';
736  $this->assertEquals($expected, $this->cleanSql($result));
737  }
738 }
$sql
Definition: server.php:82
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
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.