minor fix to last committed test
[dbsrgits/DBIx-Class.git] / t / 41orrible.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use DBIx::Class::SQLAHacks::OracleJoins;
6
7 use lib qw(t/lib);
8 use DBICTest; # do not remove even though it is not used
9 use DBIC::SqlMakerTest;
10
11 plan tests => 4;
12
13 my $sa = new DBIx::Class::SQLAHacks::OracleJoins;
14
15 $sa->limit_dialect('RowNum');
16
17 is($sa->select('rubbish',
18                   [ 'foo.id', 'bar.id', \'TO_CHAR(foo.womble, "blah")' ],
19                   undef, undef, 1, 3),
20    'SELECT * FROM
21 (
22     SELECT A.*, ROWNUM r FROM
23     (
24         SELECT foo.id AS col1, bar.id AS col2, TO_CHAR(foo.womble, "blah") AS col3 FROM rubbish 
25     ) A
26     WHERE ROWNUM < 5
27 ) B
28 WHERE r >= 4
29 ', 'Munged stuff to make Oracle not explode');
30
31 # test WhereJoins
32 # search with undefined or empty $cond
33
34 #  my ($self, $table, $fields, $where, $order, @rest) = @_;
35 my ($sql, @bind) = $sa->select(
36     [
37         { me => "cd" },
38         [
39             { "-join_type" => "LEFT", artist => "artist" },
40             { "artist.artistid" => "me.artist" },
41         ],
42     ],
43     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
44     undef,
45     undef
46 );
47 is_same_sql_bind(
48   $sql, \@bind,
49   'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( artist.artistid(+) = me.artist )', [],
50   'WhereJoins search with empty where clause'
51 );
52
53 ($sql, @bind) = $sa->select(
54     [
55         { me => "cd" },
56         [
57             { "-join_type" => "", artist => "artist" },
58             { "artist.artistid" => "me.artist" },
59         ],
60     ],
61     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
62     { 'artist.artistid' => 3 },
63     undef
64 );
65 is_same_sql_bind(
66   $sql, \@bind,
67   'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid = me.artist ) AND ( artist.artistid = ? ) ) )', [3],
68   'WhereJoins search with where clause'
69 );
70
71 ($sql, @bind) = $sa->select(
72     [
73         { me => "cd" },
74         [
75             { "-join_type" => "LEFT", artist => "artist" },
76             { "artist.artistid" => "me.artist" },
77         ],
78     ],
79     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
80     [{ 'artist.artistid' => 3 }, { 'me.cdid' => 5 }],
81     undef
82 );
83 is_same_sql_bind(
84   $sql, \@bind,
85   'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid(+) = me.artist ) AND ( ( ( artist.artistid = ? ) OR ( me.cdid = ? ) ) ) ) )', [3, 5],
86   'WhereJoins search with or in where clause'
87 );
88
89