From: Matt S Trout Date: Sun, 24 Aug 2008 15:29:27 +0000 (+0000) Subject: first cut at vairable bind vars for sybase X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b50a5275b5637b79d7e8f11b06fff9d9273c949d;p=dbsrgits%2FDBIx-Class-Historic.git first cut at vairable bind vars for sybase --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 806cef8..6b6b423 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1055,6 +1055,10 @@ sub txn_rollback { # all of _execute's args, and emits $sql, @bind. sub _prep_for_execute { my ($self, $op, $extra_bind, $ident, $args) = @_; + + if( blessed($ident) && $ident->isa("DBIx::Class::ResultSource") ) { + $ident = $ident->from(); + } my ($sql, @bind) = $self->sql_maker->$op($ident, @$args); unshift(@bind, @@ -1101,10 +1105,6 @@ sub _query_end { sub _dbh_execute { my ($self, $dbh, $op, $extra_bind, $ident, $bind_attributes, @args) = @_; - - if( blessed($ident) && $ident->isa("DBIx::Class::ResultSource") ) { - $ident = $ident->from(); - } my ($sql, $bind) = $self->_prep_for_execute($op, $extra_bind, $ident, \@args); diff --git a/lib/DBIx/Class/Storage/DBI/NoBindVars.pm b/lib/DBIx/Class/Storage/DBI/NoBindVars.pm index 80f367d..51ef7d5 100644 --- a/lib/DBIx/Class/Storage/DBI/NoBindVars.pm +++ b/lib/DBIx/Class/Storage/DBI/NoBindVars.pm @@ -38,6 +38,9 @@ Manually subs in the values for the usual C placeholders. sub _prep_for_execute { my $self = shift; + + my ($op, $extra_bind, $ident) = @_; + my ($sql, $bind) = $self->next::method(@_); # stringify args, quote via $dbh, and manually insert @@ -46,12 +49,14 @@ sub _prep_for_execute { my $new_sql; foreach my $bound (@$bind) { - shift @$bound; + my $col = shift @$bound; + my $do_quote = $self->should_quote_data_type($col); foreach my $data (@$bound) { if(ref $data) { $data = ''.$data; } - $new_sql .= shift(@sql_part) . $self->_dbh->quote($data); + $data = $self->_dbh->quote($data) if $do_quote; + $new_sql .= shift(@sql_part) . $data; } } $new_sql .= join '', @sql_part; @@ -59,6 +64,8 @@ sub _prep_for_execute { return ($new_sql); } +sub should_quote_data_type { 1 } + =head1 AUTHORS Brandon Black diff --git a/lib/DBIx/Class/Storage/DBI/Sybase.pm b/lib/DBIx/Class/Storage/DBI/Sybase.pm index 87acdde..f18de95 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase.pm @@ -5,6 +5,15 @@ use warnings; use base qw/DBIx::Class::Storage::DBI::NoBindVars/; +my %noquote = map ($_ => 1), qw(int integer); + +sub should_quote_data_type { + my $self = shift; + my ($type) = @_; + return 0 if $noquote{$type}; + return $self->next::method(@_); +} + 1; =head1 NAME