line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Local::Romani::Query::XML::Select; |
4
|
1
|
|
|
1
|
|
1553
|
use base qw(Test::Class); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
85
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
686
|
use DBIx::Romani::Query::XML::Select; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use DBIx::Romani::Driver::sqlite; |
8
|
|
|
|
|
|
|
use XML::GDOME; |
9
|
|
|
|
|
|
|
use Test::More; |
10
|
|
|
|
|
|
|
use strict; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Data::Dumper; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# utility function makes SQL out of whatever |
15
|
|
|
|
|
|
|
sub generate_sql { return DBIx::Romani::Driver::sqlite->new()->generate_sql( @_ ) }; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub parse |
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
my $xml = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $doc = XML::GDOME->createDocFromString( $xml ); |
22
|
|
|
|
|
|
|
my $query = DBIx::Romani::Query::XML::Select::create_select_from_node( $doc->getDocumentElement() ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return $query; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub xmlSelect1Short : Test(1) |
28
|
|
|
|
|
|
|
{ |
29
|
|
|
|
|
|
|
my $xml = << "EOF"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
xmlns="http://www.carspot.com/query"> |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
column_name |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
EOF |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $query = parse( $xml ); |
39
|
|
|
|
|
|
|
my $sql = generate_sql( $query ); |
40
|
|
|
|
|
|
|
is ( $sql, 'SELECT column_name FROM table_name'); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub xmlSelect1Long : Test(1) |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
my $xml = << "EOF"; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
xmlns="http://www.carspot.com/query"> |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
column_name |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
EOF |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $query = parse( $xml ); |
58
|
|
|
|
|
|
|
my $sql = generate_sql( $query ); |
59
|
|
|
|
|
|
|
is ( $sql, 'SELECT column_name FROM table_name'); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub xmlSelectColumn1 : Test(1) |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
my $xml = << "EOF"; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
xmlns="http://www.carspot.com/query"> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
column_name |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
EOF |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $query = parse( $xml ); |
74
|
|
|
|
|
|
|
my $sql = generate_sql( $query ); |
75
|
|
|
|
|
|
|
is ( $sql, 'SELECT table_name.column_name AS alias_name FROM table_name'); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub xmlSelectExpression1 : Test(1) |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
my $xml = << "EOF"; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
xmlns="http://www.carspot.com/query"> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
column_name |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
EOF |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $query = parse( $xml ); |
97
|
|
|
|
|
|
|
my $sql = generate_sql( $query ); |
98
|
|
|
|
|
|
|
is ( $sql, 'SELECT COUNT(DISTINCT column_name) AS count FROM table_name'); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub xmlSelectWhere1 : Test(1) |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
my $xml = << "EOF"; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
xmlns="http://www.carspot.com/query"> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
column_name |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
column_name |
112
|
|
|
|
|
|
|
123 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
EOF |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $query = parse( $xml ); |
119
|
|
|
|
|
|
|
my $sql = generate_sql( $query ); |
120
|
|
|
|
|
|
|
is ( $sql, "SELECT column_name FROM table_name WHERE (column_name = '123')"); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# TODO: The XML format has fallen into disrepair, but since its not actually used for |
124
|
|
|
|
|
|
|
# anything, I have simply to decided to disable the following tests which fail, rather |
125
|
|
|
|
|
|
|
# than actually fix this. So, someday, fix this. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#sub xmlSelectGroupBy1Short : Test(1) |
128
|
|
|
|
|
|
|
#{ |
129
|
|
|
|
|
|
|
# my $xml = << "EOF"; |
130
|
|
|
|
|
|
|
# |
131
|
|
|
|
|
|
|
#xmlns="http://www.carspot.com/query"> |
132
|
|
|
|
|
|
|
# |
133
|
|
|
|
|
|
|
# column_name |
134
|
|
|
|
|
|
|
# |
135
|
|
|
|
|
|
|
# |
136
|
|
|
|
|
|
|
# |
137
|
|
|
|
|
|
|
#EOF |
138
|
|
|
|
|
|
|
# |
139
|
|
|
|
|
|
|
# my $query = parse( $xml ); |
140
|
|
|
|
|
|
|
# my $sql = generate_sql( $query ); |
141
|
|
|
|
|
|
|
# is ( $sql, 'SELECT column_name FROM table_name GROUP BY column2'); |
142
|
|
|
|
|
|
|
#} |
143
|
|
|
|
|
|
|
# |
144
|
|
|
|
|
|
|
#sub xmlSelectGroupBy1Long : Test(1) |
145
|
|
|
|
|
|
|
#{ |
146
|
|
|
|
|
|
|
# my $xml = << "EOF"; |
147
|
|
|
|
|
|
|
# |
148
|
|
|
|
|
|
|
#xmlns="http://www.carspot.com/query"> |
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
# column_name |
151
|
|
|
|
|
|
|
# |
152
|
|
|
|
|
|
|
# |
153
|
|
|
|
|
|
|
# column2 |
154
|
|
|
|
|
|
|
# |
155
|
|
|
|
|
|
|
# |
156
|
|
|
|
|
|
|
#EOF |
157
|
|
|
|
|
|
|
# |
158
|
|
|
|
|
|
|
# my $query = parse( $xml ); |
159
|
|
|
|
|
|
|
# my $sql = generate_sql( $query ); |
160
|
|
|
|
|
|
|
# is ( $sql, 'SELECT column_name FROM table_name GROUP BY column2'); |
161
|
|
|
|
|
|
|
#} |
162
|
|
|
|
|
|
|
# |
163
|
|
|
|
|
|
|
#sub xmlSelectOrderBy1Short : Test(1) |
164
|
|
|
|
|
|
|
#{ |
165
|
|
|
|
|
|
|
# my $xml = << "EOF"; |
166
|
|
|
|
|
|
|
# |
167
|
|
|
|
|
|
|
#xmlns="http://www.carspot.com/query"> |
168
|
|
|
|
|
|
|
# |
169
|
|
|
|
|
|
|
# column_name |
170
|
|
|
|
|
|
|
# |
171
|
|
|
|
|
|
|
# |
172
|
|
|
|
|
|
|
# |
173
|
|
|
|
|
|
|
#EOF |
174
|
|
|
|
|
|
|
# |
175
|
|
|
|
|
|
|
# my $query = parse( $xml ); |
176
|
|
|
|
|
|
|
# my $sql = generate_sql( $query ); |
177
|
|
|
|
|
|
|
# is ( $sql, 'SELECT column_name FROM table_name ORDER BY column2 DESC'); |
178
|
|
|
|
|
|
|
#} |
179
|
|
|
|
|
|
|
# |
180
|
|
|
|
|
|
|
#sub xmlSelectOrderBy1Long : Test(1) |
181
|
|
|
|
|
|
|
#{ |
182
|
|
|
|
|
|
|
# my $xml = << "EOF"; |
183
|
|
|
|
|
|
|
# |
184
|
|
|
|
|
|
|
#xmlns="http://www.carspot.com/query"> |
185
|
|
|
|
|
|
|
# |
186
|
|
|
|
|
|
|
# column_name |
187
|
|
|
|
|
|
|
# |
188
|
|
|
|
|
|
|
# |
189
|
|
|
|
|
|
|
# column2 |
190
|
|
|
|
|
|
|
# |
191
|
|
|
|
|
|
|
# |
192
|
|
|
|
|
|
|
#EOF |
193
|
|
|
|
|
|
|
# |
194
|
|
|
|
|
|
|
# my $query = parse( $xml ); |
195
|
|
|
|
|
|
|
# my $sql = generate_sql( $query ); |
196
|
|
|
|
|
|
|
# is ( $sql, 'SELECT column_name FROM table_name ORDER BY column2 DESC'); |
197
|
|
|
|
|
|
|
#} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub xmlSelectJoin1 : Test(1) |
200
|
|
|
|
|
|
|
{ |
201
|
|
|
|
|
|
|
my $xml = << "EOF"; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
xmlns="http://www.carspot.com/query" |
204
|
|
|
|
|
|
|
xmlns:op="http://www.carspot.com/query-operator"> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
column_name |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
table1.key |
211
|
|
|
|
|
|
|
table2.table1_key |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
EOF |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
my $query = parse( $xml ); |
218
|
|
|
|
|
|
|
my $sql = generate_sql( $query ); |
219
|
|
|
|
|
|
|
is ($sql, 'SELECT column_name FROM table1 INNER JOIN table2 ON table1.key = table2.table1_key'); |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
1; |
223
|
|
|
|
|
|
|
|