File Coverage: t/09-sql-select.t

# File Coverage

File: | t/09-sql-select.t
Coverage: | 100.0%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 |  | 24 3 9 | use lib 'lib';
2 | 1 1 1 |  |  | 1 |  | 10 3 6 | use strict;
3 | 1 1 1 |  |  | 1 |  | 8 2 15 | use warnings;
4 |
5 | 1 1 1 |  |  | 1 |  | 15 6 25 | use Test::More tests => 9;
6 | 1 |  |  | 1 |  | 8 | BEGIN { use_ok('SQL::Select'); }
7 |
8 | 1 |  |  | 1 |  | 32 | sub _Q { "'$_[0]'" }
9 |
10 | 1 |  |  |  |  | 12 | my $select = SQL::Select->new;
11 | 1 |  |  |  |  | 11 | $select->select( qw<name type label> )
12 |  |  |  |  |  |  | ->from( '_columns' );
13 |
14 | 1 |  |  |  |  | 8 | is $select->generate, <<_EOC_;
15 |  |  |  |  |  |  | select name, type, label from _columns;
16 |  |  |  |  |  |  | _EOC_
17 |
18 | 1 |  |  |  |  | 5 | is "$select", <<_EOC_;
19 |  |  |  |  |  |  | select name, type, label from _columns;
20 |  |  |  |  |  |  | _EOC_
21 |
22 | 1 |  |  |  |  | 16 | $select->where("table_name", '=', _Q('blah'));
23 |
24 | 1 |  |  |  |  | 14 | is $select->generate, <<_EOC_;
25 |  |  |  |  |  |  | select name, type, label from _columns where table_name = 'blah';
26 |  |  |  |  |  |  | _EOC_
27 |
28 | 1 |  |  |  |  | 17 | $select->order_by("foo");
29 |
30 | 1 |  |  |  |  | 13 | is $select->generate, <<_EOC_;
31 |  |  |  |  |  |  | select name, type, label from _columns where table_name = 'blah' order by foo;
32 |  |  |  |  |  |  | _EOC_
33 |
34 | 1 |  |  |  |  | 18 | $select->where("Foo", '>', 'bar')->where('Bar' => '3');
35 | 1 |  |  |  |  | 5 | is "$select", <<'_EOC_';
36 |  |  |  |  |  |  | select name, type, label from _columns where table_name = 'blah' and Foo > bar and Bar = 3 order by foo;
37 |  |  |  |  |  |  | _EOC_
38 |
39 | 1 |  |  |  |  | 33 | $select->reset( qw<name type label> )
40 |  |  |  |  |  |  | ->from( '_columns' )->limit(5)->offset(29);
41 | 1 |  |  |  |  | 9 | is $select->generate, <<_EOC_;
42 |  |  |  |  |  |  | select name, type, label from _columns limit 5 offset 29;
43 |  |  |  |  |  |  | _EOC_
44 |
45 | 1 |  |  |  |  | 20 | $select->reset( qw<name> )->from("users")
46 |  |  |  |  |  |  | ->order_by( foo => 'asc' )->order_by( bar => 'desc' )->limit(0);
47 | 1 |  |  |  |  | 12 | is $select->generate, <<_EOC_;
48 |  |  |  |  |  |  | select name from users order by foo asc, bar desc limit 0;
49 |  |  |  |  |  |  | _EOC_
50 |
51 | 1 |  |  |  |  | 20 | $select->reset( qw<name> )->from("users")->op('or')
52 |  |  |  |  |  |  | ->where(foo => 1)->where(bar => 2)->where(baz => 3);
53 | 1 |  |  |  |  | 5 | is "$select", <<_EOC_;
54 |  |  |  |  |  |  | select name from users where foo = 1 or bar = 2 or baz = 3;
55 |  |  |  |  |  |  | _EOC_
56 |