minor cleanups
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase.pm
index cc8a0cc..8e65c99 100644 (file)
@@ -31,6 +31,9 @@ without doing a C<select max(col)>.
 
 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]]
@@ -58,11 +61,28 @@ sub _rebless {
     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;
@@ -116,9 +136,33 @@ sub connect_call_blob_setup {
 
 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;
 
@@ -278,8 +322,11 @@ sub _dbh_last_insert_id {
   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;
@@ -305,12 +352,12 @@ for L<DBIx::Class::InflateColumn::DateTime>.
 
 =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>.