5 use DBICTest ':DiffSQL';
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;
12 my $schema = DBICTest->init_schema (storage_type => 'DBIx::Class::Storage::DBI::ACCESS', no_deploy => 1, quote_names => 1);
15 $schema->resultset('Artist')->search(
20 join => [{ cds => 'tracks' }],
21 '+select' => [ 'tracks.title' ],
22 '+as' => [ 'track_title' ],
26 SELECT [me].[artistid], [me].[name], [me].[rank], [me].[charfield],
32 ON [cds].[artist] = [me].[artistid]
34 LEFT JOIN [track] [tracks]
35 ON [tracks].[cd] = [cds].[cdid]
37 WHERE ( [artistid] = ? )
40 [{ sqlt_datatype => 'integer', dbic_colname => 'artistid' }
43 'correct SQL for two-step left join'
47 $schema->resultset('Track')->search(
52 join => [{ cd => 'artist' }],
53 '+select' => [ 'artist.name' ],
54 '+as' => [ 'artist_name' ],
58 SELECT [me].[trackid], [me].[cd], [me].[position], [me].[title], [me].[last_updated_on], [me].[last_updated_at],
64 ON [cd].[cdid] = [me].[cd]
66 INNER JOIN [artist] [artist]
67 ON [artist].[artistid] = [cd].[artist]
69 WHERE ( [trackid] = ? )
72 [{ sqlt_datatype => 'integer', dbic_colname => 'trackid' }
75 'correct SQL for two-step inner join',
79 my $sa = $schema->storage->sql_maker;
80 # the legacy tests assume no quoting - leave things as-is
81 local $sa->{quote_char};
83 # my ($self, $table, $fields, $where, $order, @rest) = @_;
84 my ($sql, @bind) = $sa->select(
88 { "-join_type" => "LEFT", artist => "artist" },
89 { "artist.artistid" => { -ident => "me.artist" } },
92 [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
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'
102 ($sql, @bind) = $sa->select(
106 { "-join_type" => "LEFT", track => "track" },
107 { "track.cd" => { -ident => "me.cdid" } },
110 { artist => "artist" },
111 { "artist.artistid" => { -ident => "me.artist" } },
114 [ 'track.title', 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ],
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'