From: Peter Rabbitson <ribasushi@cpan.org>
Date: Wed, 4 Jun 2014 12:53:48 +0000 (+0200)
Subject: Teach FC about literals
X-Git-Tag: v0.082800~188
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a524980e87f8d0063f051a4f949e0a4a20cd4a8f;p=dbsrgits%2FDBIx-Class.git

Teach FC about literals
---

diff --git a/Changes b/Changes
index 0b971bd..d1f8cdd 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for DBIx::Class
 
+    * Notable Changes and Deprecations
+        - DBIC::FilterColumn now properly bypasses \'' and \[] literals, just
+          like the rest of DBIC
+
     * Fixes
         - Fix on_connect_* not always firing in some cases - a race condition
           existed between storage accessor setters and the determine_driver
diff --git a/lib/DBIx/Class/FilterColumn.pm b/lib/DBIx/Class/FilterColumn.pm
index 6d7e48c..6fdf1ad 100644
--- a/lib/DBIx/Class/FilterColumn.pm
+++ b/lib/DBIx/Class/FilterColumn.pm
@@ -2,7 +2,9 @@ package DBIx::Class::FilterColumn;
 use strict;
 use warnings;
 
-use base qw/DBIx::Class::Row/;
+use base 'DBIx::Class::Row';
+use DBIx::Class::_Util 'is_literal_value';
+use namespace::clean;
 
 sub filter_column {
   my ($self, $col, $attrs) = @_;
@@ -30,7 +32,11 @@ sub filter_column {
 sub _column_from_storage {
   my ($self, $col, $value) = @_;
 
-  return $value unless defined $value;
+  return $value if (
+    ! defined $value
+      or
+    is_literal_value($value)
+  );
 
   my $info = $self->column_info($col)
     or $self->throw_exception("No column info for $col");
@@ -45,6 +51,8 @@ sub _column_from_storage {
 sub _column_to_storage {
   my ($self, $col, $value) = @_;
 
+  return $value if is_literal_value($value);
+
   my $info = $self->column_info($col) or
     $self->throw_exception("No column info for $col");
 
diff --git a/t/row/filter_column.t b/t/row/filter_column.t
index fb8dd00..785206d 100644
--- a/t/row/filter_column.t
+++ b/t/row/filter_column.t
@@ -140,6 +140,33 @@ for my $artist_maker (
   is( $artist->get_column('rank'), 21, 'Proper filtered value' );
 }
 
+# test literals
+for my $v ( \ '16', \[ '?', '16' ] ) {
+  my $art = $schema->resultset('Artist')->new({ rank => 10 });
+  $art->rank($v);
+
+  is_deeply( $art->rank, $v);
+  is_deeply( $art->get_filtered_column("rank"), $v);
+  is_deeply( $art->get_column("rank"), $v);
+
+  $art->insert;
+  $art->discard_changes;
+
+  is ($art->get_column("rank"), 16, "Literal inserted into database properly");
+  is ($art->rank, 32, "filtering still works");
+
+  $art->update({ rank => $v });
+
+  is_deeply( $art->rank, $v);
+  is_deeply( $art->get_filtered_column("rank"), $v);
+  is_deeply( $art->get_column("rank"), $v);
+
+  $art->discard_changes;
+
+  is ($art->get_column("rank"), 16, "Literal inserted into database properly");
+  is ($art->rank, 32, "filtering still works");
+}
+
 IC_DIE: {
   throws_ok {
      DBICTest::Schema::Artist->inflate_column(rank =>