use DBIx::Class::Storage::DBI::Cursor;
use DBIx::Class::Storage::Statistics;
use IO::File;
+use Scalar::Util 'blessed';
__PACKAGE__->mk_group_accessors(
'simple' =>
my ($self, $op, $extra_bind, $ident, @args) = @_;
my ($sql, @bind) = $self->sql_maker->$op($ident, @args);
- unshift(@bind, @$extra_bind) if $extra_bind;
+ unshift(@bind,
+ map { ref $_ eq 'ARRAY' ? $_ : [ '!!dummy', $_ ] } @$extra_bind)
+ if $extra_bind;
@bind = map { ref $_ ? ''.$_ : $_ } @bind; # stringify args
return ($sql, @bind);
sub _execute {
my ($self, $op, $extra_bind, $ident, $bind_attributes, @args) = @_;
+ if( blessed($ident) && $ident->isa("DBIx::Class::ResultSource") )
+ {
+ $ident = $ident->from();
+ }
+
my ($sql, @bind) = $self->sql_maker->$op($ident, @args);
- unshift(@bind, @$extra_bind) if $extra_bind;
+ unshift(@bind,
+ map { ref $_ eq 'ARRAY' ? $_ : [ '!!dummy', $_ ] } @$extra_bind)
+ if $extra_bind;
if ($self->debug) {
- my @debug_bind = map { defined ($_ && $_->[1]) ? qq{'$_->[1]'} : q{'NULL'} } @bind;
+ my @debug_bind =
+ map { defined ($_ && $_->[1]) ? qq{'$_->[1]'} : q{'NULL'} } @bind;
$self->debugobj->query_start($sql, @debug_bind);
}
my $sth = eval { $self->sth($sql,$op) };
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) {
my ($self, $source, $to_insert) = @_;
my $ident = $source->from;
- 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;
- }
-
+ my $bind_attributes = $self->source_bind_attributes($source);
+
$self->throw_exception(
"Couldn't insert ".join(', ',
map "$_ => $to_insert->{$_}", keys %$to_insert
)." into ${ident}"
- ) unless ($self->_execute('insert' => [], $ident, $bind_attributes, $to_insert));
+ ) unless ($self->_execute('insert' => [], $source, $bind_attributes, $to_insert));
return $to_insert;
}
#};
## 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;
- }
-
+ my $bind_attributes = $self->source_bind_attributes($source);
+
## Bind the values and execute
-
$rv = eval {
my $placeholder_index = 1;
};
-#print STDERR Dumper($tuple_status);
-#print STDERR "RV: $rv\n";
-
if ($@ || !defined $rv) {
my $errors = '';
foreach my $tuple (@$tuple_status)
sub update {
my $self = shift @_;
my $source = shift @_;
+ my $bind_attributes = $self->source_bind_attributes($source);
- 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;
- }
-
- my $ident = $source->from;
- return $self->_execute('update' => [], $ident, $bind_attributes, @_);
+ return $self->_execute('update' => [], $source, $bind_attributes, @_);
}
my $source = shift @_;
my $bind_attrs = {}; ## If ever it's needed...
- my $ident = $source->from;
- return $self->_execute('delete' => [], $ident, $bind_attrs, @_);
+ return $self->_execute('delete' => [], $source, $bind_attrs, @_);
}
sub _select {
return $self->_execute(@args);
}
+sub source_bind_attributes {
+ my ($self, $source) = @_;
+
+ 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;
+ }
+
+ return $bind_attributes;
+}
+
=head2 select
=over 4