File: query-builder.t

package info (click to toggle)
librose-db-object-perl 1%3A0.815-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,048 kB
  • sloc: perl: 79,670; sql: 28; makefile: 7
file content (51 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl -w

use strict;

use Test::More tests => 2;

BEGIN 
{
  require 't/test-lib.pl';
  use_ok('Rose::DB::Object::QueryBuilder');
  Rose::DB::Object::QueryBuilder->import(qw(build_select));
}

SKIP:
{
  skip("all tests", 1)  unless(have_db('sqlite_admin'));

  my $dbh = get_dbh('sqlite');

  my $sql = 
    build_select
    (
      dbh     => $dbh,
      select  => 'COUNT(*)',
      tables  => [ 'articles' ],
      columns => { articles => [ qw(id category type title date) ] },
      query   =>
      [
        category => [ 'sports', 'science' ],
        type     => 'news',
        title    => { like => [ '%million%', 
                                '%resident%' ] },
        id => [ \q(id), 1 ],
      ],
      query_is_sql => 1
    );

  is($sql . "\n", <<"EOF", 'build_select() IN scalar ref');
SELECT 
COUNT(*)
FROM
  articles t1
WHERE
  t1.id IN (id, '1') AND
  t1.category IN ('sports', 'science') AND
  t1.type = 'news' AND
  (t1.title LIKE '%million%' OR t1.title LIKE '%resident%')
EOF

  # XXX: Need more tests here...
}