File Coverage

test/Romani/Query/Select.pm
Criterion Covered Total %
statement 69 140 49.2
branch n/a
condition n/a
subroutine 23 34 67.6
pod n/a
total 92 174 52.8


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             package Local::Romani::Query::Select;
4 1     1   1823 use base qw(Test::Class);
  1         2  
  1         1427  
5              
6 1     1   53984 use DBIx::Romani::Query::Select;
  1         2  
  1         25  
7 1     1   503 use DBIx::Romani::Query::Comparison;
  1         2  
  1         24  
8 1     1   534 use DBIx::Romani::Query::SQL::Generate;
  1         3  
  1         38  
9 1     1   971 use DBIx::Romani::Query::SQL::Column;
  1         3  
  1         36  
10 1     1   1071 use DBIx::Romani::Query::SQL::TTT::Function;
  1         2  
  1         30  
11 1     1   681 use DBIx::Romani::Query::SQL::TTT::Keyword;
  1         4  
  1         88  
12 1     1   630 use DBIx::Romani::Query::SQL::TTT::Join;
  1         20  
  1         34  
13 1     1   671 use DBIx::Romani::Query::Function::Count;
  1         2  
  1         30  
14 1     1   673 use DBIx::Romani::Driver::sqlite;
  1         3  
  1         34  
15 1     1   1298 use Test::More;
  1         12839  
  1         11  
16 1     1   322 use strict;
  1         3  
  1         34  
17              
18 1     1   6 use Data::Dumper;
  1         1  
  1         173  
19              
20             # utility function makes SQL out of whatever
21 0     0     sub generate_sql { return DBIx::Romani::Driver::sqlite->new()->generate_sql( @_ ) };
22              
23             =pod example
24              
25            
26            
27             column_name
28            
29            
30              
31             =cut
32             sub querySelect1 : Test(1)
33             {
34 0     0   0 my $query = DBIx::Romani::Query::Select->new();
35 0         0 $query->add_from( "table_name" );
36 0         0 $query->add_result( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
37              
38             # generate the SQL
39 0         0 my $sql = generate_sql( $query );
40 0         0 is ( $sql, 'SELECT column_name FROM table_name');
41 1     1   6 }
  1         2  
  1         10  
42              
43             =pod example
44              
45            
46            
47             column_name
48            
49            
50              
51             =cut
52             sub querySelect2 : Test(1)
53             {
54 0     0   0 my $query = DBIx::Romani::Query::Select->new();
55 0         0 $query->add_from( "table_name" );
56 0         0 $query->add_result( DBIx::Romani::Query::SQL::Column->new("table_name", "column_name"), "alias_name" );
57              
58             # generate the SQL
59 0         0 my $sql = generate_sql( $query );
60 0         0 is ( $sql, 'SELECT table_name.column_name AS alias_name FROM table_name');
61 1     1   386 }
  1         3  
  1         5  
62              
63             =pod example
64              
65            
66            
67            
68            
69            
70             column_name
71            
72            
73            
74            
75              
76             =cut
77             sub querySelect3 : Test(1)
78             {
79 0     0   0 my $query = DBIx::Romani::Query::Select->new();
80 0         0 $query->add_from( "table_name" );
81              
82 0         0 my $count_func = DBIx::Romani::Query::SQL::TTT::Function->new( "COUNT" );
83 0         0 my $ttt_join = DBIx::Romani::Query::SQL::TTT::Join->new();
84 0         0 $ttt_join->add( DBIx::Romani::Query::SQL::TTT::Keyword->new('DISTINCT') );
85 0         0 $ttt_join->add( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
86 0         0 $count_func->add( $ttt_join );
87              
88 0         0 $query->add_result({ value => $count_func, as => "count" });
89            
90             # generate the SQL
91 0         0 my $sql = generate_sql( $query );
92 0         0 is ( $sql, 'SELECT COUNT(DISTINCT column_name) AS count FROM table_name');
93 1     1   365 }
  1         3  
  1         4  
94              
95             =pod example
96              
97            
98            
99            
100            
101             column_name
102            
103            
104            
105            
106              
107             =cut
108             sub querySelect4 : Test(1)
109             {
110 0     0   0 my $query = DBIx::Romani::Query::Select->new();
111 0         0 $query->add_from( "table_name" );
112              
113 0         0 my $count_func = DBIx::Romani::Query::Function::Count->new( "COUNT" );
114 0         0 $count_func->set_distinct( 1 );
115 0         0 $count_func->add( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
116 0         0 $query->add_result({ value => $count_func, as => "count" });
117            
118             # generate the SQL
119 0         0 my $sql = generate_sql( $query );
120 0         0 is ( $sql, 'SELECT COUNT(DISTINCT column_name) AS count FROM table_name');
121 1     1   336 }
  1         3  
  1         5  
122              
123             =pod example
124              
125            
126            
127             column_name
128            
129            
130            
131             column_name
132             123
133            
134            
135            
136              
137             =cut
138             sub querySelect5 : Test(1)
139             {
140 0     0   0 my $query = DBIx::Romani::Query::Select->new();
141 0         0 $query->add_from( "table_name" );
142 0         0 $query->add_result( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
143              
144 0         0 my $where = DBIx::Romani::Query::Comparison->new( $DBIx::Romani::Query::Comparison::EQUAL );
145 0         0 $where->add( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
146 0         0 $where->add( DBIx::Romani::Query::SQL::Literal->new( "123" ) );
147 0         0 $query->set_where( $where );
148              
149             # generate the SQL
150 0         0 my $sql = generate_sql( $query );
151 0         0 is ( $sql, "SELECT column_name FROM table_name WHERE column_name = '123'");
152 1     1   356 }
  1         2  
  1         4  
153              
154             =pod example
155              
156            
157            
158             column_name
159            
160            
161            
162              
163             =cut
164             sub querySelect6 : Test(1)
165             {
166 0     0   0 my $query = DBIx::Romani::Query::Select->new();
167 0         0 $query->add_from( "table_name" );
168 0         0 $query->add_result( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
169 0         0 $query->add_group_by( DBIx::Romani::Query::SQL::Column->new( undef, "column2" ) );
170              
171             # generate the SQL
172 0         0 my $sql = generate_sql( $query );
173 0         0 is ( $sql, 'SELECT column_name FROM table_name GROUP BY column2');
174 1     1   313 }
  1         2  
  1         11  
175              
176             =pod example
177              
178            
179            
180             column_name
181            
182            
183            
184              
185             =cut
186             sub querySelect7 : Test(1)
187             {
188 0     0   0 my $query = DBIx::Romani::Query::Select->new();
189 0         0 $query->add_from( "table_name" );
190 0         0 $query->add_result( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
191 0         0 $query->add_order_by( DBIx::Romani::Query::SQL::Column->new( undef, "column2" ), "asc" );
192              
193             # generate the SQL
194 0         0 my $sql = generate_sql( $query );
195 0         0 is ( $sql, 'SELECT column_name FROM table_name ORDER BY column2 ASC');
196 1     1   322 }
  1         3  
  1         9  
197              
198             =pod example
199              
200            
201             xmlns="http://www.carspot.com/query"
202             xmlns:op="http://www.carspot.com/query-operator">
203            
204             column_name
205            
206            
207            
208             table1.key
209             table2.table1_key
210            
211            
212            
213              
214             =cut
215             sub querySelect8 : Test(1)
216             {
217 0     0   0 my $query = DBIx::Romani::Query::Select->new();
218 0         0 $query->add_from( "table1" );
219 0         0 $query->add_result( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
220              
221 0         0 my $eq_op = DBIx::Romani::Query::Comparison->new( $DBIx::Romani::Query::Comparison::EQUAL );
222 0         0 $eq_op->add( DBIx::Romani::Query::SQL::Column->new( 'table1', 'key' ) );
223 0         0 $eq_op->add( DBIx::Romani::Query::SQL::Column->new( 'table2', 'table1_key' ) );
224 0         0 $query->set_join({ type => 'inner', table => 'table2', on => $eq_op });
225              
226             # generate the SQL
227 0         0 my $sql = generate_sql( $query );
228 0         0 is ($sql, 'SELECT column_name FROM table1 INNER JOIN table2 ON table1.key = table2.table1_key');
229 1     1   480 }
  1         2  
  1         5  
230              
231             =pod example
232              
233            
234            
235             column_name
236            
237            
238              
239             =cut
240             sub querySelect9 : Test(1)
241             {
242 0     0   0 my $query = DBIx::Romani::Query::Select->new();
243 0         0 $query->add_from( "table_name" );
244 0         0 $query->add_result( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
245 0         0 $query->set_limit( 10, 20 );
246              
247             # generate the SQL
248 0         0 my $sql = generate_sql( $query );
249 0         0 is ( $sql, 'SELECT column_name FROM table_name LIMIT 10 OFFSET 20');
250 1     1   266 }
  1         2  
  1         5  
251              
252             =pod example
253              
254            
255            
256             column_name
257            
258            
259              
260             =cut
261             sub querySelectDistinct : Test(1)
262             {
263 0     0     my $query = DBIx::Romani::Query::Select->new();
264 0           $query->set_distinct( 1 );
265 0           $query->add_from( "table_name" );
266 0           $query->add_result( DBIx::Romani::Query::SQL::Column->new( undef, "column_name" ) );
267              
268             # generate the SQL
269 0           my $sql = generate_sql( $query );
270 0           is ( $sql, 'SELECT DISTINCT column_name FROM table_name');
271 1     1   260 }
  1         2  
  1         4  
272              
273             1;
274