Merge 'sybase_insert_bulk' into 'sybase_support'
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase.pm
index f6073cb..9851303 100644 (file)
@@ -18,6 +18,9 @@ __PACKAGE__->mk_group_accessors('simple' =>
 );
 
 my @also_proxy_to_writer_storage = qw/
+  connect_call_set_auto_cast auto_cast connect_call_blob_setup
+  connect_call_datetime_setup
+
   disconnect _connect_info _sql_maker _sql_maker_opts disable_sth_caching
   auto_savepoint unsafe cursor_class debug debugobj schema
 /;
@@ -124,12 +127,14 @@ sub _init {
 
   $writer_storage->_is_writer_storage(1);
   $writer_storage->connect_info($self->connect_info);
+  $writer_storage->auto_cast($self->auto_cast);
 
   $self->_writer_storage($writer_storage);
 }
 
 for my $method (@also_proxy_to_writer_storage) {
   no strict 'refs';
+  no warnings 'redefine';
 
   my $replaced = __PACKAGE__->can($method);
 
@@ -467,6 +472,9 @@ sub _unset_identity_insert {
   $self->_query_end($sql);
 }
 
+# for tests
+sub _can_insert_bulk { 1 }
+
 # XXX this should use the DBD::Sybase bulk API, where possible
 sub insert_bulk {
   my $self = shift;
@@ -520,7 +528,7 @@ sub _update_blobs {
 
   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
@@ -555,12 +563,11 @@ sub _insert_blobs {
   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};
@@ -572,15 +579,11 @@ sub _insert_blobs {
     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";
+
+      $self->throw_exception(
+          "Could not find row in table '$table' for blob update:\n"
+        . $self->_pretty_print (\%where)
+      );
     }
 
     eval {
@@ -606,12 +609,12 @@ sub _insert_blobs {
     $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);
       }
     }
   }