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