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 | |
ca4f826a |
20 | my ($sql, @bind) = $sql_maker->select('artist', '*', { 'artist.name' => { -ident => 'artist.pseudonym' } } ); |
cc422895 |
21 | is_same_sql_bind ( |
22 | $sql, |
23 | \@bind, |
24 | "SELECT * |
25 | FROM ${q}artist${q} |
26 | WHERE ${q}artist${q}.${q}name${q} = ${q}artist${q}.${q}pseudonym${q} |
27 | ", |
28 | [], |
29 | ); |
30 | |
ca4f826a |
31 | ($sql, @bind) = $sql_maker->update('artist', |
cc422895 |
32 | { 'artist.name' => { -ident => 'artist.pseudonym' } }, |
33 | { 'artist.name' => { '!=' => { -ident => 'artist.pseudonym' } } }, |
34 | ); |
35 | is_same_sql_bind ( |
36 | $sql, |
37 | \@bind, |
38 | "UPDATE ${q}artist${q} |
39 | SET ${q}artist${q}.${q}name${q} = ${q}artist${q}.${q}pseudonym${q} |
40 | WHERE ${q}artist${q}.${q}name${q} != ${q}artist${q}.${q}pseudonym${q} |
41 | ", |
42 | [], |
43 | ); |
d3162b5c |
44 | |
45 | ($sql) = $sql_maker->select( |
46 | \(my $from = 'foo JOIN bar ON foo.bar_id = bar.id'), |
47 | [ { -ident => [ 'foo', 'name' ] }, { -ident => [ 'bar', '*' ] } ] |
48 | ); |
49 | |
50 | is_same_sql_bind( |
51 | $sql, |
52 | undef, |
53 | "SELECT ${q}foo${q}.${q}name${q}, ${q}bar${q}.* |
54 | FROM $from" |
55 | ); |
cc422895 |
56 | } |
57 | |
58 | done_testing; |