From: John Napiorkowski Date: Wed, 10 Jan 2007 21:08:36 +0000 (+0000) Subject: Merge 'DBIx-Class-current' into 'param_bind' X-Git-Tag: v0.08010~150^2~106^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=48f82d6d7a9ea922f88dd2bd9db5bf4e63a00dd6;p=dbsrgits%2FDBIx-Class.git Merge 'DBIx-Class-current' into 'param_bind' Merge from current and fixed issue when a column has multiple bind values. --- 48f82d6d7a9ea922f88dd2bd9db5bf4e63a00dd6 diff --cc lib/DBIx/Class/Storage/DBI.pm index 27d4e66,37257c4..26effd6 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@@ -848,29 -838,8 +848,32 @@@ sub _execute my $rv; if ($sth) { my $time = time(); - $rv = eval { $sth->execute(@bind) }; + + $rv = eval { + + my $placeholder_index = 1; + + foreach my $bound (@bind) { + + my $attributes = {}; - my($column_name, $data) = @$bound; ++ my($column_name, @data) = @$bound; + if( $bind_attributes ) { + $attributes = $bind_attributes->{$column_name} + if defined $bind_attributes->{$column_name}; - } ++ } + - $data = ref $data ? ''.$data : $data; # stringify args ++ foreach my $data (@data) ++ { ++ $data = ref $data ? ''.$data : $data; # stringify args + - $sth->bind_param($placeholder_index, $data, $attributes); - $placeholder_index++; ++ $sth->bind_param($placeholder_index, $data, $attributes); ++ $placeholder_index++; ++ } + } - $sth->execute; ++ $sth->execute(); + }; + if ($@ || !$rv) { $self->throw_exception("Error executing '$sql': ".($@ || $sth->errstr)); } @@@ -925,72 -883,16 +928,71 @@@ sub insert_bulk # @bind = map { ref $_ ? ''.$_ : $_ } @bind; # stringify args my $rv; + ## This must be an arrayref, else nothing works! + my $tuple_status = []; -# use Data::Dumper; -# print STDERR Dumper($data); + + ##use Data::Dumper; + ##print STDERR Dumper( $data, $sql, [@bind] ); + if ($sth) { + my $time = time(); - $rv = eval { $sth->execute_array({ ArrayTupleFetch => sub { my $values = shift @$data; return if !$values; return [ @{$values}[@bind] ]}, - ArrayTupleStatus => $tuple_status }) }; -# print STDERR Dumper($tuple_status); -# print STDERR "RV: $rv\n"; + + #$rv = eval { + # + # $sth->execute_array({ + + # ArrayTupleFetch => sub { + + # my $values = shift @$data; + # return if !$values; + # return [ @{$values}[@bind] ]; + # }, + + # ArrayTupleStatus => $tuple_status, + # }) + #}; + + ## Get the bind_attributes, if any exist + + my $bind_attributes; + foreach my $column ($source->columns) { + + my $data_type = $source->column_info($column)->{data_type} || ''; - + $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type) + if $data_type; + } + + ## Bind the values and execute + + $rv = eval { + + my $placeholder_index = 1; + + foreach my $bound (@bind) { + + my $attributes = {}; + my ($column_name, $data_index) = @$bound; + + if( $bind_attributes ) { + $attributes = $bind_attributes->{$column_name} + if defined $bind_attributes->{$column_name}; + } + + my @data = map { $_->[$data_index] } @$data; + + $sth->bind_param_array( $placeholder_index, [@data], $attributes ); + $placeholder_index++; + } + $sth->execute_array( {ArrayTupleStatus => $tuple_status} ); + + }; + +#print STDERR Dumper($tuple_status); +#print STDERR "RV: $rv\n"; + if ($@ || !defined $rv) { my $errors = ''; foreach my $tuple (@$tuple_status)