Commit | Line | Data |
cc422895 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
8aa76984 |
5 | use Test::Exception; |
cc422895 |
6 | use SQL::Abstract; |
7 | use SQL::Abstract::Test import => [qw/is_same_sql_bind/]; |
8 | |
9 | |
10 | for my $q ('', '"') { |
11 | my $sql_maker = SQL::Abstract->new( |
12 | quote_char => $q, |
13 | name_sep => $q ? '.' : '', |
14 | ); |
15 | |
8aa76984 |
16 | throws_ok { |
17 | $sql_maker->where({ foo => { -ident => undef } }) |
18 | } qr/-ident requires a single plain scalar argument/; |
19 | |
5d3c8944 |
20 | throws_ok { |
21 | local $sql_maker->{disable_old_special_ops} = 1; |
22 | $sql_maker->where({'-or' => [{'-ident' => 'foo'},'foo']}) |
23 | } qr/Illegal.*top-level/; |
24 | |
25 | throws_ok { |
26 | local $sql_maker->{disable_old_special_ops} = 1; |
27 | $sql_maker->where({'-or' => [{'-ident' => 'foo'},{'=' => \'bozz'}]}) |
28 | } qr/Illegal.*top-level/; |
29 | |
ca4f826a |
30 | my ($sql, @bind) = $sql_maker->select('artist', '*', { 'artist.name' => { -ident => 'artist.pseudonym' } } ); |
cc422895 |
31 | is_same_sql_bind ( |
32 | $sql, |
33 | \@bind, |
34 | "SELECT * |
35 | FROM ${q}artist${q} |
36 | WHERE ${q}artist${q}.${q}name${q} = ${q}artist${q}.${q}pseudonym${q} |
37 | ", |
38 | [], |
39 | ); |
40 | |
ca4f826a |
41 | ($sql, @bind) = $sql_maker->update('artist', |
cc422895 |
42 | { 'artist.name' => { -ident => 'artist.pseudonym' } }, |
43 | { 'artist.name' => { '!=' => { -ident => 'artist.pseudonym' } } }, |
44 | ); |
45 | is_same_sql_bind ( |
46 | $sql, |
47 | \@bind, |
48 | "UPDATE ${q}artist${q} |
49 | SET ${q}artist${q}.${q}name${q} = ${q}artist${q}.${q}pseudonym${q} |
50 | WHERE ${q}artist${q}.${q}name${q} != ${q}artist${q}.${q}pseudonym${q} |
51 | ", |
52 | [], |
53 | ); |
b011372e |
54 | |
55 | ($sql) = $sql_maker->select( |
56 | \(my $from = 'foo JOIN bar ON foo.bar_id = bar.id'), |
57 | [ { -ident => [ 'foo', 'name' ] }, { -ident => [ 'bar', '*' ] } ] |
58 | ); |
59 | |
60 | is_same_sql_bind( |
61 | $sql, |
62 | undef, |
63 | "SELECT ${q}foo${q}.${q}name${q}, ${q}bar${q}.* |
64 | FROM $from" |
65 | ); |
cc422895 |
66 | } |
67 | |
68 | done_testing; |