From: Rafael Kitover Date: Sun, 24 Jun 2012 06:59:11 +0000 (-0400) Subject: better type check for mssql+ado binary null strip X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5efba7fcc89e113c60d78fa246a0217c405ea1fc;p=dbsrgits%2FDBIx-Class-Historic.git better type check for mssql+ado binary null strip 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'. --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index f092bfa..45afefc 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -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 diff --git a/lib/DBIx/Class/Storage/DBI/ADO/CursorUtils.pm b/lib/DBIx/Class/Storage/DBI/ADO/CursorUtils.pm index 93053ce..63e6038 100644 --- a/lib/DBIx/Class/Storage/DBI/ADO/CursorUtils.pm +++ b/lib/DBIx/Class/Storage/DBI/ADO/CursorUtils.pm @@ -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); } } diff --git a/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm index 0d38311..6fb1b19 100644 --- a/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm @@ -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; } diff --git a/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server/Cursor.pm b/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server/Cursor.pm index d421145..9c02e9a 100644 --- a/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server/Cursor.pm +++ b/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server/Cursor.pm @@ -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; diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index c58397c..84d0c5d 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -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