From: Brandon L. Black Date: Thu, 31 May 2007 20:48:31 +0000 (+0000) Subject: integrate nobindvars/_prep_for_execute with the bind_params changes (also converted... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d944c5aea7c21750ce97107aacb50db173ff2ddb;p=dbsrgits%2FDBIx-Class-Historic.git integrate nobindvars/_prep_for_execute with the bind_params changes (also converted some arrays to arrayrefs in the arg lists of private methods) --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 1a6d1f9..2556ce1 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -830,15 +830,14 @@ sub txn_rollback { # easier to override in NoBindVars without duping the rest. It takes up # all of _execute's args, and emits $sql, @bind. sub _prep_for_execute { - my ($self, $op, $extra_bind, $ident, @args) = @_; + my ($self, $op, $extra_bind, $ident, $args) = @_; - my ($sql, @bind) = $self->sql_maker->$op($ident, @args); + my ($sql, @bind) = $self->sql_maker->$op($ident, @$args); unshift(@bind, map { ref $_ eq 'ARRAY' ? $_ : [ '!!dummy', $_ ] } @$extra_bind) if $extra_bind; - @bind = map { ref $_ ? ''.$_ : $_ } @bind; # stringify args - return ($sql, @bind); + return ($sql, \@bind); } sub _execute { @@ -847,15 +846,12 @@ sub _execute { if( blessed($ident) && $ident->isa("DBIx::Class::ResultSource") ) { $ident = $ident->from(); } - - my ($sql, @bind) = $self->sql_maker->$op($ident, @args); - unshift(@bind, - map { ref $_ eq 'ARRAY' ? $_ : [ '!!dummy', $_ ] } @$extra_bind) - if $extra_bind; + + my ($sql, $bind) = $self->_prep_for_execute($op, $extra_bind, $ident, \@args); if ($self->debug) { my @debug_bind = - map { defined ($_ && $_->[1]) ? qq{'$_->[1]'} : q{'NULL'} } @bind; + map { defined ($_ && $_->[1]) ? qq{'$_->[1]'} : q{'NULL'} } @$bind; $self->debugobj->query_start($sql, @debug_bind); } @@ -865,7 +861,7 @@ sub _execute { my $rv = eval { my $placeholder_index = 1; - foreach my $bound (@bind) { + foreach my $bound (@$bind) { my $attributes = {}; my($column_name, @data) = @$bound; @@ -889,10 +885,10 @@ sub _execute { if ($self->debug) { my @debug_bind = - map { defined ($_ && $_->[1]) ? qq{'$_->[1]'} : q{'NULL'} } @bind; + map { defined ($_ && $_->[1]) ? qq{'$_->[1]'} : q{'NULL'} } @$bind; $self->debugobj->query_end($sql, @debug_bind); } - return (wantarray ? ($rv, $sth, @bind) : $rv); + return (wantarray ? ($rv, $sth, @$bind) : $rv); } sub insert { diff --git a/lib/DBIx/Class/Storage/DBI/NoBindVars.pm b/lib/DBIx/Class/Storage/DBI/NoBindVars.pm index 2877ee2..c5fa9af 100644 --- a/lib/DBIx/Class/Storage/DBI/NoBindVars.pm +++ b/lib/DBIx/Class/Storage/DBI/NoBindVars.pm @@ -25,7 +25,7 @@ We can't cache very effectively without bind variables, so force the Cnext::method(@_); + my $retval = $self->next::method(@_); $self->disable_sth_caching(1); $retval; } @@ -38,9 +38,19 @@ Manually subs in the values for the usual C placeholders. sub _prep_for_execute { my $self = shift; - my ($sql, @bind) = $self->next::method(@_); - - $sql =~ s/\?/$self->_dbh->quote(shift(@bind))/eg; + my ($sql, $bind) = $self->next::method(@_); + + # stringify args, quote via $dbh, and manually insert + + foreach my $bound (@$bind) { + shift @$bound; + foreach my $data (@$bound) { + if(ref $data) { + $data = ''.$data; + } + $sql =~ s/\?/$self->_dbh->quote($data)/e; + } + } return ($sql); } diff --git a/t/93nobindvars.t b/t/93nobindvars.t index f90cf7d..e64dbb6 100644 --- a/t/93nobindvars.t +++ b/t/93nobindvars.t @@ -21,13 +21,17 @@ plan tests => 4; { # Fake storage driver for mysql + no bind variables package DBIx::Class::Storage::DBI::MySQLNoBindVars; + use Class::C3; use base qw/ - DBIx::Class::Storage::DBI::mysql DBIx::Class::Storage::DBI::NoBindVars + DBIx::Class::Storage::DBI::mysql /; $INC{'DBIx/Class/Storage/DBI/MySQLNoBindVars.pm'} = 1; } +# XXX Class::C3 doesn't like some of the Storage stuff happening late... +Class::C3::reinitialize(); + my $schema = DBICTest::Schema->clone; $schema->storage_type('::DBI::MySQLNoBindVars'); $schema->connection($dsn, $user, $pass);