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