sub search_like {
my $class = shift;
- carp join ("\n",
- 'search_like() is deprecated and will be removed in 0.09.',
- 'Instead use ->search({ x => { -like => "y%" } })',
- '(note the outer pair of {}s - they are important!)'
+ carp (
+ 'search_like() is deprecated and will be removed in DBIC version 0.09.'
+ .' Instead use ->search({ x => { -like => "y%" } })'
+ .' (note the outer pair of {}s - they are important!)'
);
my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {});
my $query = ref $_[0] eq 'HASH' ? { %{shift()} }: {@_};
if ($func eq 'distinct') {
my $_fields = $fields->{$func};
if (ref $_fields eq 'ARRAY' && @{$_fields} > 1) {
- croak "Unsupported syntax, please use " .
- "{ group_by => [ qw/" . (join ' ', @$_fields) . "/ ] }" .
- " or " .
- "{ select => [ qw/" . (join ' ', @$_fields) . "/ ], distinct => 1 }";
+ croak (
+ 'The select => { distinct => ... } syntax is not supported for multiple columns.'
+ .' Instead please use { group_by => [ qw/' . (join ' ', @$_fields) . '/ ] }'
+ .' or { select => [ qw/' . (join ' ', @$_fields) . '/ ], distinct => 1 }'
+ );
}
else {
$_fields = @{$_fields}[0] if ref $_fields eq 'ARRAY';
- carp "This syntax will be deprecated in 09, please use " .
- "{ group_by => '${_fields}' }" .
- " or " .
- "{ select => '${_fields}', distinct => 1 }";
+ carp (
+ 'The select => { distinct => ... } syntax will be deprecated in DBIC version 0.09,'
+ ." please use { group_by => '${_fields}' } or { select => '${_fields}', distinct => 1 }"
+ );
}
}
-
return $self->_sqlcase($func)
.'( '.$self->_recurse_fields($fields->{$func}).' )';
}
$rs = $schema->resultset('Tag')->search({}, { select => 'length(me.tag)', distinct => 1 });
is($rs->count, 3, 'Count by distinct function result as select literal');
-my @warnings;
-{
- local $SIG{__WARN__} = sub { push @warnings, shift };
+eval {
+ my @warnings;
+ local $SIG{__WARN__} = sub { $_[0] =~ /The select => { distinct => ... } syntax will be deprecated/
+ ? push @warnings, @_
+ : warn @_
+ };
my $row = $schema->resultset('Tag')->search({}, { select => { distinct => 'tag' } })->first;
-}
+ is (@warnings, 1, 'Warned about deprecated distinct') if $DBIx::Class::VERSION < 0.09;
+};
+ok ($@, 'Exception on deprecated distinct usage thrown') if $DBIx::Class::VERSION >= 0.09;
-is(@warnings, 1, 'expecteing warn');
+throws_ok(
+ sub { my $row = $schema->resultset('Tag')->search({}, { select => { distinct => [qw/tag cd/] } })->first },
+ qr/select => { distinct => ... } syntax is not supported for multiple columns/,
+ 'throw on unsupported syntax'
+);
-dies_ok(sub { my $row = $schema->resultset('Tag')->search({}, { select => { distinct => [qw/tag cd/] } })->first }, 'expecting to die');
+# These two rely on the database to throw an exception. This might not be the case one day. Please revise.
dies_ok(sub { my $count = $schema->resultset('Tag')->search({}, { '+select' => \'tagid AS tag_id', distinct => 1 })->count }, 'expecting to die');
dies_ok(sub { my $count = $schema->resultset('Tag')->search({}, { select => { length => 'tag' }, distinct => 1 })->count }, 'expecting to die');