File: 22op_value.t

package info (click to toggle)
libsql-abstract-perl 2.000001-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 744 kB
  • sloc: perl: 3,443; makefile: 8
file content (77 lines) | stat: -rw-r--r-- 1,881 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use strict;
use warnings;

use Test::More;
use SQL::Abstract;
use SQL::Abstract::Test import => [qw/is_same_sql_bind/];

for my $q ('', '"') {
for my $col_btype (0,1) {

  my $sql_maker = SQL::Abstract->new(
    quote_char => $q,
    name_sep => $q ? '.' : '',
    $col_btype ? (bindtype => 'columns') : (),
  );

  my ($sql, @bind) = $sql_maker->select('artist', '*', { arr1 => { -value => [1,2] }, arr2 => { '>', { -value => [3,4] } }, field => [5,6] } );

  is_same_sql_bind (
    $sql,
    \@bind,
    "SELECT *
      FROM ${q}artist${q}
      WHERE ${q}arr1${q} = ? AND
            ${q}arr2${q} > ? AND
            ( ${q}field${q} = ? OR ${q}field${q} = ? )
    ",
    [
      $col_btype
        ? (
          [ arr1 => [ 1, 2 ] ],
          [ arr2 => [ 3, 4 ] ],
          [ field => 5 ],
          [ field => 6 ],
        ) : (
          [ 1, 2 ],
          [ 3, 4 ],
          5,
          6,
        )
    ],
  );

  {
    local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /Supplying an undefined argument to '(?:NOT )?LIKE'/ };

    ($sql, @bind) = $sql_maker->where({
      c1 => undef,
      c2 => { -value => undef },
      c3 => { '=' => { -value => undef } },
      c4 => { '!=' => { -value => undef } },
      c5 => { '<>' => { -value => undef } },
      c6 => { '-like' => { -value => undef } },
      c7 => { '-not_like' => { -value => undef } },
      c8 => { 'is' => { -value => undef } },
      c9 => { 'is not' => { -value => undef } },
    });

    is_same_sql_bind (
      $sql,
      \@bind,
      "WHERE  ${q}c1${q} IS NULL
          AND ${q}c2${q} IS NULL
          AND ${q}c3${q} IS NULL
          AND ${q}c4${q} IS NOT NULL
          AND ${q}c5${q} IS NOT NULL
          AND ${q}c6${q} IS NULL
          AND ${q}c7${q} IS NOT NULL
          AND ${q}c8${q} IS NULL
          AND ${q}c9${q} IS NOT NULL
      ",
      [],
    );
  }
}}

done_testing;