$type && $type =~ /(?:text|image|lob|bytea|binary|memo)/i;
}
-sub _is_lob_column {
- my ($self, $source, $column) = @_;
-
- return $self->_is_lob_type($source->column_info($column)->{data_type});
-}
-
sub _prep_for_execute {
my $self = shift;
my ($op, $extra_bind, $ident, $args) = @_;
sub update {
my $self = shift;
- my ($source, $fields, $where, @rest) = @_;
+ my ($source, $fields, $where) = @_;
my $wantarray = wantarray;
-
my $blob_cols = $self->_remove_blob_cols($source, $fields);
- my $table = $source->name;
-
- my $identity_col = List::Util::first
- { $source->column_info($_)->{is_auto_increment} }
- $source->columns;
-
- my $is_identity_update = $identity_col && defined $fields->{$identity_col};
-
if (not $blob_cols) {
- $self->_set_identity_insert($table, 'update') if $is_identity_update;
return $self->next::method(@_);
- $self->_unset_identity_insert($table, 'update') if $is_identity_update;
- }
-
-# check that we're not updating a blob column that's also in $where
- for my $blob (grep $self->_is_lob_column($source, $_), $source->columns) {
- if (exists $where->{$blob} && exists $fields->{$blob}) {
- croak
-'Update of TEXT/IMAGE column that is also in search condition impossible';
- }
}
# update+blob update(s) done atomically on separate connection
my $guard = $self->txn_scope_guard;
-# First update the blob columns to be updated to '' (taken from $fields, where
-# it is originally put by _remove_blob_cols .)
- my %blobs_to_empty = map { ($_ => delete $fields->{$_}) } keys %$blob_cols;
-
- $self->next::method($source, \%blobs_to_empty, $where, @rest);
-
-# Now update the blobs before the other columns in case the update of other
-# columns makes the search condition invalid.
- $self->_update_blobs($source, $blob_cols, $where);
-
my @res;
- if (%$fields) {
- $self->_set_identity_insert($table, 'update') if $is_identity_update;
-
- if ($wantarray) {
- @res = $self->next::method(@_);
- }
- elsif (defined $wantarray) {
- $res[0] = $self->next::method(@_);
- }
- else {
- $self->next::method(@_);
- }
-
- $self->_unset_identity_insert($table, 'update') if $is_identity_update;
+ if ($wantarray) {
+ @res = $self->next::method(@_);
+ }
+ elsif (defined $wantarray) {
+ $res[0] = $self->next::method(@_);
}
+ else {
+ $self->next::method(@_);
+ }
+
+ $self->_update_blobs($source, $blob_cols, $where);
$guard->commit;
### the insert_bulk stuff stolen from DBI/MSSQL.pm
sub _set_identity_insert {
- my ($self, $table, $op) = @_;
+ my ($self, $table) = @_;
my $sql = sprintf (
- 'SET IDENTITY_%s %s ON',
- (uc($op) || 'INSERT'),
+ 'SET IDENTITY_INSERT %s ON',
$self->sql_maker->_quote ($table),
);
- $self->_query_start($sql);
-
my $dbh = $self->_get_dbh;
eval { $dbh->do ($sql) };
- my $exception = $@;
-
- $self->_query_end($sql);
-
- if ($exception) {
+ if ($@) {
$self->throw_exception (sprintf "Error executing '%s': %s",
$sql,
$dbh->errstr,
}
sub _unset_identity_insert {
- my ($self, $table, $op) = @_;
+ my ($self, $table) = @_;
my $sql = sprintf (
- 'SET IDENTITY_%s %s OFF',
- (uc($op) || 'INSERT'),
+ 'SET IDENTITY_INSERT %s OFF',
$self->sql_maker->_quote ($table),
);
- $self->_query_start($sql);
-
my $dbh = $self->_get_dbh;
$dbh->do ($sql);
-
- $self->_query_end($sql);
}
# XXX this should use the DBD::Sybase bulk API, where possible
### end of stolen insert_bulk section
-# Make sure blobs are not bound as placeholders, and return any non-empty ones
-# as a hash.
sub _remove_blob_cols {
my ($self, $source, $fields) = @_;
for my $col (keys %$fields) {
if ($self->_is_lob_type($source->column_info($col)->{data_type})) {
- my $blob_val = delete $fields->{$col};
- if (not defined $blob_val) {
- $fields->{$col} = \'NULL';
- }
- else {
- $fields->{$col} = \"''";
- $blob_cols{$col} = $blob_val unless $blob_val eq '';
- }
+ $blob_cols{$col} = delete $fields->{$col};
+ $fields->{$col} = \"''";
}
}
my (@primary_cols) = $source->primary_columns;
- croak "Cannot update TEXT/IMAGE column(s) without a primary key"
+ $self->throw_exception('Cannot update TEXT/IMAGE column(s) without a primary key')
unless @primary_cols;
# check if we're updating a single row by PK
my ($self, $source, $blob_cols, $row) = @_;
my $dbh = $self->_get_dbh;
- my $table = $source->name;
+ my $table = $source->from;
my %row = %$row;
my (@primary_cols) = $source->primary_columns;
- croak "Cannot update TEXT/IMAGE column(s) without a primary key"
+ $self->throw_exception('Cannot update TEXT/IMAGE column(s) without a primary key')
unless @primary_cols;
- if ((grep { defined $row{$_} } @primary_cols) != @primary_cols) {
- croak "Cannot update TEXT/IMAGE column(s) without primary key values";
- }
+ $self->throw_exception('Cannot update TEXT/IMAGE column(s) without primary key values')
+ if ((grep { defined $row{$_} } @primary_cols) != @primary_cols);
for my $col (keys %$blob_cols) {
my $blob = $blob_cols->{$col};
$cursor->next;
my $sth = $cursor->sth;
- if (not $sth) {
- require Data::Dumper;
- local $Data::Dumper::Terse = 1;
- local $Data::Dumper::Indent = 1;
- local $Data::Dumper::Useqq = 1;
- local $Data::Dumper::Quotekeys = 0;
- local $Data::Dumper::Sortkeys = 1;
-
- croak "\nCould not find row in table '$table' for blob update:\n".
- Data::Dumper::Dumper(\%where)."\n";
- }
-
eval {
do {
$sth->func('CS_GET', 1, 'ct_data_info') or die $sth->errstr;
$sth->finish if $sth;
if ($exception) {
if ($self->using_freetds) {
- croak (
+ $self->throw_exception (
'TEXT/IMAGE operation failed, probably because you are using FreeTDS: '
. $exception
);
} else {
- croak $exception;
+ $self->throw_exception($exception);
}
}
}