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