Add import-time-skip support to OptDeps, switch most tests over to that
[dbsrgits/DBIx-Class.git] / t / sqlmaker / oraclejoin.t
1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'id_shortener';
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use lib qw(t/lib);
9 use DBICTest ':DiffSQL';
10 use DBIx::Class::SQLMaker::OracleJoins;
11
12 my $sa = DBIx::Class::SQLMaker::OracleJoins->new;
13
14 for my $rhs ( "me.artist", { -ident => "me.artist" } ) {
15
16 #  my ($self, $table, $fields, $where, $order, @rest) = @_;
17 my ($sql, @bind) = $sa->select(
18     [
19         { me => "cd" },
20         [
21             { "-join_type" => "LEFT", artist => "artist" },
22             { "artist.artistid" => $rhs },
23         ],
24     ],
25     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
26     undef,
27     undef
28 );
29 is_same_sql_bind(
30   $sql, \@bind,
31   'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( artist.artistid(+) = me.artist )', [],
32   'WhereJoins search with empty where clause'
33 );
34
35 ($sql, @bind) = $sa->select(
36     [
37         { me => "cd" },
38         [
39             { "-join_type" => "", artist => "artist" },
40             { "artist.artistid" => $rhs },
41         ],
42     ],
43     [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
44     { 'artist.artistid' => 3 },
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 ) AND ( artist.artistid = ? ) ) )', [3],
50   'WhereJoins search with where clause'
51 );
52
53 ($sql, @bind) = $sa->select(
54     [
55         { me => "cd" },
56         [
57             { "-join_type" => "right", artist => "artist" },
58             { "artist.artistid" => $rhs },
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" => $rhs },
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 }
90
91 done_testing;
92