unless ref $values eq 'HASH';
my $cond = $self->_cond_for_update_delete;
-
+
+ my $bind_attributes;
+ foreach my $column ($self->result_source->columns) {
+
+ $bind_attributes->{$column} = $self->result_source->column_info($column)->{bind_attributes}
+ if defined $self->result_source->column_info($column)->{bind_attributes};
+ }
+ $self->result_source->storage->bind_attributes($bind_attributes);
+
return $self->result_source->storage->update(
$self->result_source->from, $values, $cond
);
my $source = $self->{result_source};
$self->throw_exception("No result_source set on this object; can't insert")
unless $source;
- #use Data::Dumper; warn Dumper($self);
+
+ my $bind_attributes;
+ foreach my $column ($self->result_source->columns) {
+
+ $bind_attributes->{$column} = $self->result_source->column_info($column)->{bind_attributes}
+ if defined $self->result_source->column_info($column)->{bind_attributes};
+ }
+ $self->result_source->storage->bind_attributes($bind_attributes);
+
$source->storage->insert($source->from, { $self->get_columns });
$self->in_storage(1);
$self->{_dirty_columns} = {};
my $ident_cond = $self->ident_condition;
$self->throw_exception("Cannot safely update a row in a PK-less table")
if ! keys %$ident_cond;
+
+ my $bind_attributes;
+ foreach my $column ($self->result_source->columns) {
+
+ $bind_attributes->{$column} = $self->result_source->column_info($column)->{bind_attributes}
+ if defined $self->result_source->column_info($column)->{bind_attributes};
+ }
+ $self->result_source->storage->bind_attributes($bind_attributes);
+
my $rows = $self->result_source->storage->update(
$self->result_source->from, \%to_update, $ident_cond);
if ($rows == 0) {
__PACKAGE__->mk_group_accessors(
'simple' =>
qw/_connect_info _dbh _sql_maker _sql_maker_opts _conn_pid _conn_tid
- disable_sth_caching cursor on_connect_do transaction_depth/
+ disable_sth_caching cursor on_connect_do transaction_depth bind_attributes/
);
BEGIN {
sub _sql_maker_args {
my ($self) = @_;
- return ( limit_dialect => $self->dbh, %{$self->_sql_maker_opts} );
+ return ( bindtype=>'columns', limit_dialect => $self->dbh, %{$self->_sql_maker_opts} );
}
sub sql_maker {
}
sub _execute {
- my $self = shift;
-
- my ($sql, @bind) = $self->_prep_for_execute(@_);
-
+ my ($self, $op, $extra_bind, $ident, @args) = @_;
+ my ($sql, @bind) = $self->sql_maker->$op($ident, @args);
+ unshift(@bind, @$extra_bind) if $extra_bind;
if ($self->debug) {
- my @debug_bind = map { defined $_ ? qq{'$_'} : 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) };
- my $sth = $self->sth($sql);
+ if (!$sth || $@) {
+ $self->throw_exception(
+ 'no sth generated via sql (' . ($@ || $self->_dbh->errstr) . "): $sql"
+ );
+ }
my $rv;
if ($sth) {
my $time = time();
- $rv = eval { $sth->execute(@bind) };
+
+ $rv = eval {
+
+ my $placeholder_index = 1;
+ my $bind_attributes = $self->bind_attributes;
+
+ foreach my $bound (@bind) {
+
+ my $attributes = {};
+ 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
+
+ $sth->bind_param($placeholder_index, $data, $attributes);
+ $placeholder_index++;
+ }
+ $sth->execute;
+ };
+ $self->bind_attributes({});
+
if ($@ || !$rv) {
$self->throw_exception("Error executing '$sql': ".($@ || $sth->errstr));
}
$self->throw_exception("'$sql' did not generate a statement.");
}
if ($self->debug) {
- my @debug_bind = map { defined $_ ? qq{`$_'} : q{`NULL'} } @bind;
+ my @debug_bind = map { defined ($_ && $_->[1]) ? qq{'$_->[1]'} : q{'NULL'} } @bind;
$self->debugobj->query_end($sql, @debug_bind);
}
return (wantarray ? ($rv, $sth, @bind) : $rv);
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 2;
+
+# figure out if we've got a version of sqlite that is older than 3.2.6, in
+# which case COUNT(DISTINCT()) doesn't work
+my $is_broken_sqlite = 0;
+my ($sqlite_major_ver,$sqlite_minor_ver,$sqlite_patch_ver) =
+ split /\./, $schema->storage->dbh->get_info(18);
+if( $schema->storage->dbh->get_info(17) eq 'SQLite' &&
+ ( ($sqlite_major_ver < 3) ||
+ ($sqlite_major_ver == 3 && $sqlite_minor_ver < 2) ||
+ ($sqlite_major_ver == 3 && $sqlite_minor_ver == 2 && $sqlite_patch_ver < 6) ) ) {
+ $is_broken_sqlite = 1;
+}
+
+
+#Bindtest
+{
+ my $new = $schema->resultset("Artist")->new({
+
+ artistid=>25,
+ name=>'JohnNapiorkowski',
+ });
+
+ $new->update_or_insert;
+
+ my $resultset = $schema->resultset("Artist")->find({artistid=>25});
+
+ is($resultset->id, 25, 'Testing New ID');
+ is($resultset->name, 'JohnNapiorkowski', 'Testing New Name');
+}
+
+
__PACKAGE__->add_columns(
'artistid' => {
data_type => 'integer',
- is_auto_increment => 1
+ is_auto_increment => 1,
+ bind_attributes => { testkey1 => 1},
},
'name' => {
data_type => 'varchar',
size => 100,
is_nullable => 1,
+ bind_attributes => {testkey2 =>2},
},
);
__PACKAGE__->set_primary_key('artistid');