blob: 6f098886fa02ead4ca6a85ef8a0f59ff2002d56a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<?php
namespace SqlParser\Tests\Builder;
use SqlParser\Parser;
use SqlParser\Tests\TestCase;
class SelectStatementTest extends TestCase
{
public function testBuilder()
{
$query = 'SELECT * FROM t1 LEFT JOIN (t2, t3, t4) '
. 'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)';
$parser = new Parser($query);
$stmt = $parser->statements[0];
$this->assertEquals(
'SELECT * FROM t1 LEFT JOIN (t2, t3, t4) '
. 'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c) ',
$stmt->build()
);
}
public function testBuilderUnion()
{
$parser = new Parser('SELECT 1 UNION SELECT 2');
$stmt = $parser->statements[0];
$this->assertEquals(
'SELECT 1 UNION SELECT 2 ',
$stmt->build()
);
}
public function testBuilderAlias()
{
$parser = new Parser(
'SELECT sgu.id, sgu.email_address FROM `sf_guard_user` sgu '
. 'RIGHT JOIN `student_course_booking` scb ON sgu.id = scb.user_id '
. 'WHERE `has_found_course` = \'1\' GROUP BY sgu.id '
. 'ORDER BY scb.id DESC LIMIT 0,300'
);
$stmt = $parser->statements[0];
$this->assertEquals(
'SELECT sgu.id, sgu.email_address FROM `sf_guard_user` AS `sgu` '
. 'RIGHT JOIN `student_course_booking` AS `scb` ON sgu.id = scb.user_id '
. 'WHERE `has_found_course` = \'1\' GROUP BY sgu.id ASC '
. 'ORDER BY scb.id DESC LIMIT 0, 300 ',
$stmt->build()
);
}
}
|