But your queries will be cached.
+You need at least version C<1.09> of L<DBD::Sybase> for placeholder support.
+Otherwise your storage will be automatically reblessed into C<::NoBindVars>.
+
A recommended L<DBIx::Class::Storage::DBI/connect_info> settings:
on_connect_call => [['datetime_setup'], [blob_setup => log_on_update => 0]]
if (!$exception && $dbtype && $self->load_optional_class($subclass)) {
bless $self, $subclass;
$self->_rebless;
- } else {
- # real Sybase
+ } else { # real Sybase
+ my $no_bind_vars = 'DBIx::Class::Storage::DBI::Sybase::NoBindVars';
+
if (not $self->dbh->{syb_dynamic_supported}) {
- $self->ensure_class_loaded('DBIx::Class::Storage::DBI::Sybase::NoBindVars');
- bless $self, 'DBIx::Class::Storage::DBI::Sybase::NoBindVars';
+ $self->ensure_class_loaded($no_bind_vars);
+ bless $self, $no_bind_vars;
+ $self->_rebless;
+ }
+
+ if ($DBD::Sybase::VERSION < 1.09) {
+ carp <<'EOF';
+
+Your version of Sybase potentially supports placeholders and query caching,
+however your version of DBD::Sybase is too old to do this properly. Please
+upgrade to at least version 1.09 if you want this feature.
+
+TEXT/IMAGE column support will also not work in older versions of DBD::Sybase.
+
+See perldoc DBIx::Class::Storage::DBI::Sybase for more details.
+EOF
+ $self->ensure_class_loaded($no_bind_vars);
+ bless $self, $no_bind_vars;
$self->_rebless;
}
$self->_set_maxConnect;
if ($dsn !~ /maxConnect=/) {
$self->_dbi_connect_info->[0] = "$dsn;maxConnect=256";
- # will take effect next connection
my $connected = defined $self->_dbh;
$self->disconnect;
$self->ensure_connected if $connected;
sub _is_lob_type {
my $self = shift;
- shift =~ /(?:text|image|lob|bytea|binary)/i;
+ my $type = shift;
+ $type && $type =~ /(?:text|image|lob|bytea|binary)/i;
}
+## This will be useful if we ever implement BLOB filehandle inflation and will
+## need to use the API, but for now it isn't.
+#
+#sub order_columns_for_select {
+# my ($self, $source) = @_;
+#
+# my (@non_blobs, @blobs);
+#
+# for my $col ($source->columns) {
+# if ($self->_is_lob_type($source->column_info($col)->{data_type})) {
+# push @blobs, $col;
+# } else {
+# push @non_blobs, $col;
+# }
+# }
+#
+# croak "cannot select more than a one TEXT/IMAGE column at a time"
+# if @blobs > 1;
+#
+# return (@non_blobs, @blobs);
+#}
+
+# override to handle TEXT/IMAGE
sub insert {
my ($self, $source, $to_insert) = splice @_, 0, 3;
my %blob_cols;
for my $col (keys %$fields) {
- $blob_cols{$col} = delete $fields->{$col}
- if $self->_is_lob_type($source->column_info($col)->{data_type});
+ if ($self->_is_lob_type($source->column_info($col)->{data_type})) {
+ $blob_cols{$col} = delete $fields->{$col};
+ $fields->{$col} = \"''";
+ }
}
return \%blob_cols;
my $table = $source->from;
+ my %inserted = %$inserted;
my (@primary_cols) = $source->primary_columns;
- croak "Cannot update TEXT/IMAGE without a primary key!"
+ croak "Cannot update TEXT/IMAGE column(s) without a primary key"
unless @primary_cols;
- my $search_cond = join ',' => map "$_ = ?", @primary_cols;
+ if ((grep { defined $inserted{$_} } @primary_cols) != @primary_cols) {
+ if (@primary_cols == 1) {
+ my $col = $primary_cols[0];
+ $inserted{$col} = $self->last_insert_id($source, $col);
+ } else {
+ croak "Cannot update TEXT/IMAGE column(s) without primary key values";
+ }
+ }
for my $col (keys %$blob_cols) {
my $blob = $blob_cols->{$col};
+ my $sth;
-# First update to empty string in case it's NULL, can't update a NULL blob using
-# the API.
- my $sth = $dbh->prepare_cached(
- qq{update $table set $col = '' where $search_cond}
- );
- $sth->execute(map $inserted->{$_}, @primary_cols) or die $sth->errstr;
- $sth->finish;
+ if (not $self->isa('DBIx::Class::Storage::DBI::NoBindVars')) {
+ my $search_cond = join ',' => map "$_ = ?", @primary_cols;
+
+ $sth = $self->sth(
+ "select $col from $table where $search_cond"
+ );
+ $sth->execute(map $inserted{$_}, @primary_cols);
+ } else {
+ my $search_cond = join ',' => map "$_ = $inserted{$_}", @primary_cols;
- $sth = $dbh->prepare_cached(
- "select $col from $table where $search_cond"
- );
- $sth->execute(map $inserted->{$_}, @primary_cols);
+ $sth = $dbh->prepare(
+ "select $col from $table where $search_cond"
+ );
+ $sth->execute;
+ }
eval {
while ($sth->fetch) {
my ($self, $dbh, $source, $col) = @_;
# sorry, there's no other way!
- my $sth = $dbh->prepare_cached("select max($col) from ".$source->from);
- return ($dbh->selectrow_array($sth))[0];
+ my $sth = $self->sth("select max($col) from ".$source->from);
+ my ($id) = $dbh->selectrow_array($sth);
+ $sth->finish;
+
+ return $id;
}
1;
=head1 IMAGE AND TEXT COLUMNS
+You need at least version C<1.09> of L<DBD::Sybase> for C<TEXT/IMAGE> column
+support.
+
See L</connect_call_blob_setup> for a L<DBIx::Class::Storage::DBI/connect_info>
setting you need to work with C<IMAGE> columns.
-Due to limitations in L<DBD::Sybase> and this driver, it is only possible to
-select one C<TEXT> or C<IMAGE> column at a time.
-
=head1 AUTHORS
See L<DBIx::Class/CONTRIBUTORS>.