fix subtle bug with Sybase database type determination
[dbsrgits/DBIx-Class.git] / t / 41orrible.t
CommitLineData
f66596f9 1use strict;
2use warnings;
3
4use Test::More;
6f4ddea1 5use DBIx::Class::SQLAHacks::OracleJoins;
f66596f9 6
c61a0748 7use lib qw(t/lib);
d8190011 8use DBICTest; # do not remove even though it is not used
c61a0748 9use DBIC::SqlMakerTest;
10
67bdc1ef 11plan tests => 4;
f66596f9 12
6f4ddea1 13my $sa = new DBIx::Class::SQLAHacks::OracleJoins;
f66596f9 14
15$sa->limit_dialect('RowNum');
16
17is($sa->select('rubbish',
eac29141 18 [ 'foo.id', 'bar.id', \'TO_CHAR(foo.womble, "blah")' ],
f66596f9 19 undef, undef, 1, 3),
20 'SELECT * FROM
21(
22 SELECT A.*, ROWNUM r FROM
23 (
eac29141 24 SELECT foo.id AS col1, bar.id AS col2, TO_CHAR(foo.womble, "blah") AS col3 FROM rubbish
f66596f9 25 ) A
26 WHERE ROWNUM < 5
27) B
28WHERE r >= 4
29', 'Munged stuff to make Oracle not explode');
67bdc1ef 30
31# test WhereJoins
32# search with undefined or empty $cond
33
34# my ($self, $table, $fields, $where, $order, @rest) = @_;
9b459129 35my ($sql, @bind) = $sa->select(
36 [
67bdc1ef 37 { me => "cd" },
38 [
39 { "-join_type" => "LEFT", artist => "artist" },
40 { "artist.artistid" => "me.artist" },
41 ],
42 ],
43 [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
44 undef,
9b459129 45 undef
46);
47is_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 )', [],
50 'WhereJoins search with empty where clause'
51);
67bdc1ef 52
9b459129 53($sql, @bind) = $sa->select(
54 [
67bdc1ef 55 { me => "cd" },
56 [
57 { "-join_type" => "", artist => "artist" },
58 { "artist.artistid" => "me.artist" },
59 ],
60 ],
61 [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
62 { 'artist.artistid' => 3 },
9b459129 63 undef
64);
65is_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);
67bdc1ef 70
9b459129 71($sql, @bind) = $sa->select(
72 [
67bdc1ef 73 { me => "cd" },
74 [
75 { "-join_type" => "LEFT", artist => "artist" },
76 { "artist.artistid" => "me.artist" },
77 ],
78 ],
79 [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
80 [{ 'artist.artistid' => 3 }, { 'me.cdid' => 5 }],
9b459129 81 undef
82);
83is_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);
67bdc1ef 88
89