Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class.git] / t / sqlmaker / msaccess.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
726c8f65 3use strict;
4use warnings;
5use Test::More;
c0329273 6
a5a7bb73 7use DBICTest ':DiffSQL';
726c8f65 8
ac0c0825 9# the entire point of the subclass is that parenthesis have to be
10# just right for ACCESS to be happy
11# globalize for entirety of the test
12$SQL::Abstract::Test::parenthesis_significant = 1;
726c8f65 13
ac0c0825 14my $schema = DBICTest->init_schema (storage_type => 'DBIx::Class::Storage::DBI::ACCESS', no_deploy => 1, quote_names => 1);
15
16is_same_sql_bind(
17 $schema->resultset('Artist')->search(
18 {
19 artistid => 1,
20 },
21 {
22 join => [{ cds => 'tracks' }],
23 '+select' => [ 'tracks.title' ],
24 '+as' => [ 'track_title' ],
25 }
26 )->as_query,
27 '(
28 SELECT [me].[artistid], [me].[name], [me].[rank], [me].[charfield],
29 [tracks].[title]
30 FROM (
31 (
32 [artist] [me]
33 LEFT JOIN cd [cds]
34 ON [cds].[artist] = [me].[artistid]
35 )
36 LEFT JOIN [track] [tracks]
37 ON [tracks].[cd] = [cds].[cdid]
38 )
39 WHERE ( [artistid] = ? )
40 )',
41 [
42 [{ sqlt_datatype => 'integer', dbic_colname => 'artistid' }
43 => 1 ],
44 ],
45 'correct SQL for two-step left join'
46);
47
48is_same_sql_bind(
49 $schema->resultset('Track')->search(
50 {
51 trackid => 1,
52 },
53 {
54 join => [{ cd => 'artist' }],
55 '+select' => [ 'artist.name' ],
56 '+as' => [ 'artist_name' ],
57 }
58 )->as_query,
59 '(
60 SELECT [me].[trackid], [me].[cd], [me].[position], [me].[title], [me].[last_updated_on], [me].[last_updated_at],
61 [artist].[name]
62 FROM (
63 (
64 [track] [me]
65 INNER JOIN cd [cd]
66 ON [cd].[cdid] = [me].[cd]
67 )
68 INNER JOIN [artist] [artist]
69 ON [artist].[artistid] = [cd].[artist]
70 )
71 WHERE ( [trackid] = ? )
72 )',
73 [
74 [{ sqlt_datatype => 'integer', dbic_colname => 'trackid' }
75 => 1 ],
76 ],
77 'correct SQL for two-step inner join',
78);
79
80
81my $sa = $schema->storage->sql_maker;
82# the legacy tests assume no quoting - leave things as-is
83local $sa->{quote_char};
726c8f65 84
85# my ($self, $table, $fields, $where, $order, @rest) = @_;
86my ($sql, @bind) = $sa->select(
87 [
88 { me => "cd" },
89 [
90 { "-join_type" => "LEFT", artist => "artist" },
1efc866d 91 { "artist.artistid" => { -ident => "me.artist" } },
726c8f65 92 ],
93 ],
94 [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
95 undef,
96 undef
97);
98is_same_sql_bind(
99 $sql, \@bind,
100 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM (cd me LEFT JOIN artist artist ON artist.artistid = me.artist)', [],
101 'one-step join parenthesized'
102);
103
104($sql, @bind) = $sa->select(
105 [
106 { me => "cd" },
107 [
108 { "-join_type" => "LEFT", track => "track" },
1efc866d 109 { "track.cd" => { -ident => "me.cdid" } },
726c8f65 110 ],
111 [
696ba760 112 { artist => "artist" },
1efc866d 113 { "artist.artistid" => { -ident => "me.artist" } },
726c8f65 114 ],
115 ],
116 [ 'track.title', 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
117 undef,
118 undef
119);
120is_same_sql_bind(
121 $sql, \@bind,
696ba760 122 'SELECT track.title, cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM ((cd me LEFT JOIN track track ON track.cd = me.cdid) INNER JOIN artist artist ON artist.artistid = me.artist)', [],
123 'two-step join parenthesized and inner join prepended with INNER'
726c8f65 124);
125
126done_testing;