c1725e053fdaa543248382f8ee868a21465fb030
[dbsrgits/DBIx-Class.git] / t / sqlmaker / oraclejoin.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 BEGIN {
7   require DBIx::Class::Optional::Dependencies;
8   plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('id_shortener')
9     unless DBIx::Class::Optional::Dependencies->req_ok_for ('id_shortener');
10 }
11
12 use lib qw(t/lib);
13 use DBICTest ':DiffSQL';
14 use DBIx::Class::SQLMaker::OracleJoins;
15
16 my $sa = DBIx::Class::SQLMaker::OracleJoins->new;
17
18 #  my ($self, $table, $fields, $where, $order, @rest) = @_;
19 my ($sql, @bind) = $sa->select(
20     [
21         { me => "cd" },
22         [
23             { "-join_type" => "LEFT", artist => "artist" },
24             { "artist.artistid" => "me.artist" },
25         ],
26     ],
27     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
28     undef,
29     undef
30 );
31 is_same_sql_bind(
32   $sql, \@bind,
33   'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( artist.artistid(+) = me.artist )', [],
34   'WhereJoins search with empty where clause'
35 );
36
37 ($sql, @bind) = $sa->select(
38     [
39         { me => "cd" },
40         [
41             { "-join_type" => "", artist => "artist" },
42             { "artist.artistid" => "me.artist" },
43         ],
44     ],
45     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
46     { 'artist.artistid' => 3 },
47     undef
48 );
49 is_same_sql_bind(
50   $sql, \@bind,
51   '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],
52   'WhereJoins search with where clause'
53 );
54
55 ($sql, @bind) = $sa->select(
56     [
57         { me => "cd" },
58         [
59             { "-join_type" => "LEFT", artist => "artist" },
60             { "artist.artistid" => "me.artist" },
61         ],
62     ],
63     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
64     [{ 'artist.artistid' => 3 }, { 'me.cdid' => 5 }],
65     undef
66 );
67 is_same_sql_bind(
68   $sql, \@bind,
69   '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],
70   'WhereJoins search with or in where clause'
71 );
72
73 done_testing;
74