Fix for SQLite to ignore the { for => ... } attribute
Moritz Onken [Wed, 3 Mar 2010 11:05:51 +0000 (11:05 +0000)]
Changes
lib/DBIx/Class/SQLAHacks/SQLite.pm [new file with mode: 0644]
lib/DBIx/Class/Storage/DBI/SQLite.pm
t/sqlahacks/sqlite.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 1ab1a7b..5a71df3 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,7 @@ Revision history for DBIx::Class
         - Fix regression on not properly throwing when $obj->relationship
           is unresolvable
         - Add has_relationship method to row objects
+               - Fix for SQLite to ignore the { for => ... } attribute
 
 0.08120 2010-02-24 08:58:00 (UTC)
         - Make sure possibly overwritten deployment_statements methods in
diff --git a/lib/DBIx/Class/SQLAHacks/SQLite.pm b/lib/DBIx/Class/SQLAHacks/SQLite.pm
new file mode 100644 (file)
index 0000000..dfc77ae
--- /dev/null
@@ -0,0 +1,17 @@
+package # Hide from PAUSE
+  DBIx::Class::SQLAHacks::SQLite;
+
+use base qw( DBIx::Class::SQLAHacks );
+use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
+
+#
+# SQLite does not understand SELECT ... FOR UPDATE
+# Adjust SQL here instead
+#
+sub select {
+  my $self = shift;
+  local $self->{_dbic_rs_attrs}{for} = undef;
+  return $self->SUPER::select (@_);
+}
+
+1;
index f7977bb..d096d80 100644 (file)
@@ -10,6 +10,8 @@ use POSIX 'strftime';
 use File::Copy;
 use File::Spec;
 
+__PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::SQLite');
+
 sub backup
 {
   my ($self, $dir) = @_;
diff --git a/t/sqlahacks/sqlite.t b/t/sqlahacks/sqlite.t
new file mode 100644 (file)
index 0000000..14fdc19
--- /dev/null
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+use DBIC::SqlMakerTest;
+
+my $schema = DBICTest->init_schema;
+
+is_same_sql_bind(
+      $schema->resultset('Artist')->search ({}, {for => 'update'})->as_query,
+      "(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me)", []);
+
+done_testing;