[Bast-commits] r5760 - DBIx-Class/0.08/trunk/lib/DBIx/Class

arcanez at dev.catalyst.perl.org arcanez at dev.catalyst.perl.org
Mon Mar 16 19:53:35 GMT 2009


Author: arcanez
Date: 2009-03-16 19:53:34 +0000 (Mon, 16 Mar 2009)
New Revision: 5760

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
Log:
 * change search_literal to use \[] when passing into search (help with binding order)
 * provide documentation on how to use search instead of search_literal



Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-03-16 15:48:28 UTC (rev 5759)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-03-16 19:53:34 UTC (rev 5760)
@@ -388,19 +388,25 @@
 resultset query.
 
 CAVEAT: C<search_literal> is provided for Class::DBI compatibility and should
-only be used in that context. There are known problems using C<search_literal>
-in chained queries; it can result in bind values in the wrong order.  See
-L<DBIx::Class::Manual::Cookbook/Searching> and
+only be used in that context. C<search_literal> is a convenience method. 
+It is equivalent to calling $schema->search(\[]), but if you want to ensure
+columns are bound correctly, use C<search>.
+
+Example of how to use C<search> instead of C<search_literal>
+
+  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<DBIx::Class::Manual::Cookbook/Searching> and 
 L<DBIx::Class::Manual::FAQ/Searching> for searching techniques that do not
 require C<search_literal>.
 
 =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




More information about the Bast-commits mailing list