Commit | Line | Data |
f66596f9 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
67bdc1ef |
5 | #use DBIx::Class::Storage::DBI; |
9b459129 |
6 | use SQL::Abstract::Test import => ['is_same_sql_bind']; |
67bdc1ef |
7 | use DBIx::Class::Storage::DBI::Oracle::WhereJoins; |
f66596f9 |
8 | |
67bdc1ef |
9 | plan tests => 4; |
f66596f9 |
10 | |
67bdc1ef |
11 | my $sa = new DBIC::SQL::Abstract::Oracle; |
f66596f9 |
12 | |
13 | $sa->limit_dialect('RowNum'); |
14 | |
15 | is($sa->select('rubbish', |
eac29141 |
16 | [ 'foo.id', 'bar.id', \'TO_CHAR(foo.womble, "blah")' ], |
f66596f9 |
17 | undef, undef, 1, 3), |
18 | 'SELECT * FROM |
19 | ( |
20 | SELECT A.*, ROWNUM r FROM |
21 | ( |
eac29141 |
22 | SELECT foo.id AS col1, bar.id AS col2, TO_CHAR(foo.womble, "blah") AS col3 FROM rubbish |
f66596f9 |
23 | ) A |
24 | WHERE ROWNUM < 5 |
25 | ) B |
26 | WHERE r >= 4 |
27 | ', 'Munged stuff to make Oracle not explode'); |
67bdc1ef |
28 | |
29 | # test WhereJoins |
30 | # search with undefined or empty $cond |
31 | |
32 | # my ($self, $table, $fields, $where, $order, @rest) = @_; |
9b459129 |
33 | my ($sql, @bind) = $sa->select( |
34 | [ |
67bdc1ef |
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, |
9b459129 |
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 | ); |
67bdc1ef |
50 | |
9b459129 |
51 | ($sql, @bind) = $sa->select( |
52 | [ |
67bdc1ef |
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 }, |
9b459129 |
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 | ); |
67bdc1ef |
68 | |
9b459129 |
69 | ($sql, @bind) = $sa->select( |
70 | [ |
67bdc1ef |
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 }], |
9b459129 |
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 | ); |
67bdc1ef |
86 | |
87 | |