Commit | Line | Data |
f66596f9 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
f66596f9 |
5 | |
c7d50a7d |
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 | |
c61a0748 |
12 | use lib qw(t/lib); |
a5a7bb73 |
13 | use DBICTest ':DiffSQL'; |
70c28808 |
14 | use DBIx::Class::SQLMaker::OracleJoins; |
c61a0748 |
15 | |
c7d50a7d |
16 | my $sa = DBIx::Class::SQLMaker::OracleJoins->new; |
67bdc1ef |
17 | |
f6fff270 |
18 | for my $rhs ( "me.artist", { -ident => "me.artist" } ) { |
19 | |
67bdc1ef |
20 | # my ($self, $table, $fields, $where, $order, @rest) = @_; |
9b459129 |
21 | my ($sql, @bind) = $sa->select( |
22 | [ |
67bdc1ef |
23 | { me => "cd" }, |
24 | [ |
25 | { "-join_type" => "LEFT", artist => "artist" }, |
f6fff270 |
26 | { "artist.artistid" => $rhs }, |
67bdc1ef |
27 | ], |
28 | ], |
29 | [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], |
30 | undef, |
9b459129 |
31 | undef |
32 | ); |
33 | is_same_sql_bind( |
34 | $sql, \@bind, |
35 | 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( artist.artistid(+) = me.artist )', [], |
36 | 'WhereJoins search with empty where clause' |
37 | ); |
67bdc1ef |
38 | |
9b459129 |
39 | ($sql, @bind) = $sa->select( |
40 | [ |
67bdc1ef |
41 | { me => "cd" }, |
42 | [ |
43 | { "-join_type" => "", artist => "artist" }, |
f6fff270 |
44 | { "artist.artistid" => $rhs }, |
67bdc1ef |
45 | ], |
46 | ], |
47 | [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], |
48 | { 'artist.artistid' => 3 }, |
9b459129 |
49 | undef |
50 | ); |
51 | is_same_sql_bind( |
52 | $sql, \@bind, |
53 | '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], |
54 | 'WhereJoins search with where clause' |
55 | ); |
67bdc1ef |
56 | |
9b459129 |
57 | ($sql, @bind) = $sa->select( |
58 | [ |
67bdc1ef |
59 | { me => "cd" }, |
60 | [ |
f6fff270 |
61 | { "-join_type" => "right", artist => "artist" }, |
62 | { "artist.artistid" => $rhs }, |
63 | ], |
64 | ], |
65 | [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], |
66 | { 'artist.artistid' => 3 }, |
67 | undef |
68 | ); |
69 | is_same_sql_bind( |
70 | $sql, \@bind, |
71 | '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], |
72 | 'WhereJoins search with where clause' |
73 | ); |
74 | |
75 | ($sql, @bind) = $sa->select( |
76 | [ |
77 | { me => "cd" }, |
78 | [ |
67bdc1ef |
79 | { "-join_type" => "LEFT", artist => "artist" }, |
f6fff270 |
80 | { "artist.artistid" => $rhs }, |
67bdc1ef |
81 | ], |
82 | ], |
83 | [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], |
84 | [{ 'artist.artistid' => 3 }, { 'me.cdid' => 5 }], |
9b459129 |
85 | undef |
86 | ); |
87 | is_same_sql_bind( |
88 | $sql, \@bind, |
89 | '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], |
90 | 'WhereJoins search with or in where clause' |
91 | ); |
67bdc1ef |
92 | |
f6fff270 |
93 | } |
94 | |
327368bc |
95 | done_testing; |
67bdc1ef |
96 | |