~ubuntu-branches/ubuntu/precise/libjifty-dbi-perl/precise

« back to all changes in this revision

Viewing changes to t/14handle-pg.t

  • Committer: Bazaar Package Importer
  • Author(s): AGOSTINI Yves
  • Date: 2008-04-17 08:11:44 UTC
  • Revision ID: james.westby@ubuntu.com-20080417081144-jcpvqplvkkh07s1g
Tags: upstream-0.49
ImportĀ upstreamĀ versionĀ 0.49

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Test methods in Jifty::DBI::Handle::Pg
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
use Test::More tests => 2;
 
7
 
 
8
my $package;
 
9
BEGIN {
 
10
    $package = 'Jifty::DBI::Handle::Pg';
 
11
    use_ok($package);
 
12
}
 
13
use Jifty::DBI::Collection;
 
14
 
 
15
package Foo::Bar::Collection;
 
16
our @ISA = 'Jifty::DBI::Collection';
 
17
 
 
18
sub query_columns { "blah" }
 
19
sub table { "bars" }
 
20
 
 
21
package main;
 
22
 
 
23
{
 
24
    # Test sub distinct_query
 
25
    my $collection = bless {
 
26
        order_by => [
 
27
          {
 
28
            alias  => 'main',
 
29
            column => 'id',
 
30
            order  => 'asc',
 
31
          },
 
32
          {
 
33
            alias  => 'main',
 
34
            column => 'name',
 
35
            order  => 'desc',
 
36
          },
 
37
          {
 
38
            alias  => 'foo',
 
39
            column => 'id',
 
40
            order  => 'desc',
 
41
          },
 
42
          {
 
43
            alias  => 'foo',
 
44
            column => 'name',
 
45
            order  => 'desc',
 
46
          },
 
47
          {
 
48
            alias  => '',
 
49
            column => 'id',
 
50
            order  => 'ASC',
 
51
          },
 
52
          {
 
53
            alias  => undef,
 
54
            column => 'blood',
 
55
            order  => 'ASC'
 
56
          },
 
57
          {
 
58
            column => 'session_offset',
 
59
            order  => 'asc'
 
60
          },
 
61
        ],
 
62
    }, 'Foo::Bar::Collection';
 
63
    my $stmt = 'select * from users';
 
64
    $package->distinct_query(\$stmt, $collection);
 
65
    is $stmt,
 
66
       'SELECT blah FROM ( SELECT main.id FROM select * from users  GROUP BY main.id'
 
67
       . '   ORDER BY main.id ASC, min(main.name) DESC, min(foo.id) DESC, '
 
68
       . 'min(foo.name) DESC, id ASC, min(blood) ASC, min(session_offset) ASC  ) '
 
69
       . 'distinctquery, bars main WHERE (main.id = distinctquery.id)',
 
70
       'distinct_query works';
 
71
}