From: Justin Hunter Date: Mon, 16 Mar 2009 19:53:34 +0000 (+0000) Subject: * change search_literal to use \[] when passing into search (help with binding order) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=90f80a179bef37e4d96d6f8c0baaf513240db986;p=dbsrgits%2FDBIx-Class-Historic.git * change search_literal to use \[] when passing into search (help with binding order) * provide documentation on how to use search instead of search_literal --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index dd911ad..e600144 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -388,19 +388,25 @@ Pass a literal chunk of SQL to be added to the conditional part of the resultset query. CAVEAT: C is provided for Class::DBI compatibility and should -only be used in that context. There are known problems using C -in chained queries; it can result in bind values in the wrong order. See -L and +only be used in that context. C is a convenience method. +It is equivalent to calling $schema->search(\[]), but if you want to ensure +columns are bound correctly, use C. + +Example of how to use C instead of C + + my @cds = $cd_rs->search_literal('cdid = ? AND (artist = ? OR artist = ?)', (2, 1, 2)); + my @cds = $cd_rs->search(\[ 'cdid = ? AND (artist = ? OR artist = ?)', [ 'cdid', 2 ], [ 'artist', 1 ], [ 'artist', 2 ] ]); + + +See L and L for searching techniques that do not require C. =cut sub search_literal { - my ($self, $cond, @vals) = @_; - my $attrs = (ref $vals[$#vals] eq 'HASH' ? { %{ pop(@vals) } } : {}); - $attrs->{bind} = [ @{$self->{attrs}{bind}||[]}, @vals ]; - return $self->search(\$cond, $attrs); + my ($self, $sql, @bind) = @_; + return $self->search(\[ $sql, map [ __DUMMY__ => $_ ], @bind ]); } =head2 find