better type check for mssql+ado binary null strip
Rafael Kitover [Sun, 24 Jun 2012 06:59:11 +0000 (02:59 -0400)]
The data_type in the t/lib result class for the blob for the tests
changed to 'blob', while the binary type null stripper only expected
'binary' or 'image' data types, which is wrong for possibly
cross-deployed schemas.

Change _strip_trailing_binary_nulls in ::ADO::CursorUtils to use the
newly added and more generic ::Storage::DBI::_is_binary_type instead of
just checking for 'binary' or 'image'.

lib/DBIx/Class/Storage/DBI.pm
lib/DBIx/Class/Storage/DBI/ADO/CursorUtils.pm
lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm
lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server/Cursor.pm
lib/DBIx/Class/Storage/DBI/Replicated.pm

index f092bfa..45afefc 100644 (file)
@@ -2958,6 +2958,13 @@ sub _is_text_lob_type {
                         |national\s*character\s*varying))\z/xi);
 }
 
+# Determine if a data_type is some type of a binary type
+sub _is_binary_type {
+  my ($self, $data_type) = @_;
+  $data_type && ($self->_is_binary_lob_type($data_type)
+    || $data_type =~ /(?:var)?(?:binary|bit|graphic)(?:\s*varying)?/i);
+}
+
 1;
 
 =head1 USAGE NOTES
index 93053ce..63e6038 100644 (file)
@@ -8,7 +8,7 @@ use base 'Exporter';
 our @EXPORT_OK = qw/_normalize_guids _strip_trailing_binary_nulls/;
 
 sub _strip_trailing_binary_nulls {
-  my ($select, $col_infos, $data) = @_;
+  my ($select, $col_infos, $data, $storage) = @_;
 
   foreach my $select_idx (0..$#$select) {
 
@@ -18,7 +18,7 @@ sub _strip_trailing_binary_nulls {
       or next;
 
     $data->[$select_idx] =~ s/\0+\z//
-      if $data_type =~ /binary|image/i;
+      if $storage->_is_binary_type($data_type);
   }
 }
 
index 0d38311..6fb1b19 100644 (file)
@@ -144,7 +144,7 @@ sub select_single {
 
   _normalize_guids($select, $col_infos, \@row, $self);
 
-  _strip_trailing_binary_nulls($select, $col_infos, \@row);
+  _strip_trailing_binary_nulls($select, $col_infos, \@row, $self);
 
   return @row;
 }
index d421145..9c02e9a 100644 (file)
@@ -49,7 +49,7 @@ sub _dbh_next {
   my $select = $self->args->[1];
 
   _normalize_guids($select, $col_infos, \@row, $storage);
-  _strip_trailing_binary_nulls($select, $col_infos, \@row);
+  _strip_trailing_binary_nulls($select, $col_infos, \@row, $storage);
 
   return @row;
 }
@@ -67,7 +67,7 @@ sub _dbh_all {
 
   for (@rows) {
     _normalize_guids($select, $col_infos, $_, $storage);
-    _strip_trailing_binary_nulls($select, $col_infos, $_);
+    _strip_trailing_binary_nulls($select, $col_infos, $_, $storage);
   }
 
   return @rows;
index c58397c..84d0c5d 100644 (file)
@@ -354,6 +354,7 @@ my $method_dispatch = {
     _max_column_bytesize
     _is_lob_type
     _is_binary_lob_type
+    _is_binary_type
     _is_text_lob_type
 
     sth