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