{ -ident => undef } makes zero sense
[dbsrgits/SQL-Abstract.git] / t / 21op_ident.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Exception;
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
16   throws_ok {
17     $sql_maker->where({ foo => { -ident => undef } })
18   } qr/-ident requires a single plain scalar argument/;
19
20   my ($sql, @bind) = $sql_maker->select ('artist', '*', { 'artist.name' => { -ident => 'artist.pseudonym' } } );
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
31   ($sql, @bind) = $sql_maker->update ('artist',
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   );
44 }
45
46 done_testing;