On 18 Feb 2009, at 11:18, Joel Bernstein wrote:
2009/2/18 Joel Bernstein <[email protected]>:
Why do you feel that is a hack? It seems equivalent to your
original query..
$rs->search({ 1 => \'sql literal here', })
It's a perfectly common idiom so I'm not too sure why you feel it's
hacky?
I suppose you meant, it feels like a hack to use a SQL literal to
mimic the original query, and does DBIC have a more logical way to
achieve it?
Yes, thats what i meant.
I did manage to write my own special operator using SQL::Abstract
(1.49_02) which would handle the ANY keyword, but i couldn't see how i
could include this such that the DBIx::Class generated code could use
it, like so:
my $sql = SQL::Abstract->new(special_ops => [
{regex => qr/^any$/i,
handler => sub {
my ($self, $field, $op, $arg) = @_;
$arg = [$arg] if not ref $arg;
my $label = $self->_quote($field);
my ($placeholder) = $self->_convert('?');
my $sql = $placeholder . " = " . $self-
>_sqlcase('any') . "($label) ";
my @bind = $self->_bindtype($field, @$arg);
return ($sql, @bind);
}
},
]);
my %where = (
'my_array_col' => { -any => '1' }
);
my($stmt, @bind) = $sql->where(\%where);
can I define this special_ops within my DBIx::Class generated code?
thanks again for your help
adam
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]