column names, so we stay within the 30-char limit (RT#58271)
- Fix a Storage/$dbh leak introduced by th migration to
Try::Tiny (this is *not* a Try::Tiny bug)
+ - Fix corner case of count with group-by over a 1:1 join column
+ where the selector ends up with column name clashes
* Misc
- Test suite default on-disk database now checks for Win32
# Calculate subquery selector
if (my $g = $sub_attrs->{group_by}) {
+ my $sql_maker = $rsrc->storage->sql_maker;
+
# necessary as the group_by may refer to aliased functions
my $sel_index;
for my $sel (@{$attrs->{select}}) {
}
for my $g_part (@$g) {
- push @{$sub_attrs->{select}}, $sel_index->{$g_part} || $g_part;
+ my $colpiece = $sel_index->{$g_part} || $g_part;
+
+ # disqualify join-based group_by's. Arcane but possible query
+ # also horrible horrible hack to alias a column (not a func.)
+ # (probably need to introduce SQLA syntax)
+ if ($colpiece =~ /\./ && $colpiece !~ /^$attrs->{alias}\./) {
+ my $as = $colpiece;
+ $as =~ s/\./__/;
+ $colpiece = \ sprintf ('%s AS %s', map { $sql_maker->_quote ($_) } ($colpiece, $as) );
+ }
+ push @{$sub_attrs->{select}}, $colpiece;
}
}
else {
# check for proper grouped counts
{
- my $ansi_schema = DBICTest::Schema->connect ($dsn, $user, $pass, { on_connect_call => 'set_strict_mode' });
+ my $ansi_schema = DBICTest::Schema->connect ($dsn, $user, $pass, {
+ on_connect_call => 'set_strict_mode',
+ quote_char => '`',
+ name_sep => '.'
+ });
my $rs = $ansi_schema->resultset('CD');
my $years;
'grouped count correct',
);
}, 'Grouped count does not throw');
+
+ lives_ok( sub {
+ $ansi_schema->resultset('Owners')->search({}, {
+ join => 'books', group_by => [ 'me.id', 'books.id' ]
+ })->count();
+ }, 'count on grouped columns with the same name does not throw');
+
+
}
ZEROINSEARCH: {