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