Factor out IDENTITY_INSERT for Sybase ASE and MSSQL into a component
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Informix.pm
index 314f4c1..db953d4 100644 (file)
@@ -3,9 +3,19 @@ use strict;
 use warnings;
 
 use base qw/DBIx::Class::Storage::DBI/;
-
 use mro 'c3';
 
+use Scope::Guard ();
+use Context::Preserve 'preserve_context';
+use namespace::clean;
+
+__PACKAGE__->sql_limit_dialect ('SkipFirst');
+__PACKAGE__->sql_quote_char ('"');
+__PACKAGE__->datetime_parser_type (
+  'DBIx::Class::Storage::DBI::Informix::DateTime::Format'
+);
+
+
 __PACKAGE__->mk_group_accessors('simple' => '__last_insert_id');
 
 =head1 NAME
@@ -24,9 +34,10 @@ sub _execute {
   my $self = shift;
   my ($op) = @_;
   my ($rv, $sth, @rest) = $self->next::method(@_);
-  if ($op eq 'insert') {
-    $self->__last_insert_id($sth->{ix_sqlerrd}[1]);
-  }
+
+  $self->__last_insert_id($sth->{ix_sqlerrd}[1])
+    if $self->_perform_autoinc_retrieval;
+
   return (wantarray ? ($rv, $sth, @rest) : $rv);
 }
 
@@ -34,29 +45,33 @@ sub last_insert_id {
   shift->__last_insert_id;
 }
 
-sub _sql_maker_opts {
-  my ( $self, $opts ) = @_;
-
-  if ( $opts ) {
-    $self->{_sql_maker_opts} = { %$opts };
-  }
+sub _exec_svp_begin {
+    my ($self, $name) = @_;
 
-  return { limit_dialect => 'SkipFirst', %{$self->{_sql_maker_opts}||{}} };
+    $self->_dbh->do("SAVEPOINT $name");
 }
 
-sub _svp_begin {
+# can't release savepoints
+sub _exec_svp_release { 1 }
+
+sub _exec_svp_rollback {
     my ($self, $name) = @_;
 
-    $self->_get_dbh->do("SAVEPOINT $name");
+    $self->_dbh->do("ROLLBACK TO SAVEPOINT $name")
 }
 
-# can't release savepoints
-sub _svp_release { 1 }
+sub with_deferred_fk_checks {
+  my ($self, $sub) = @_;
 
-sub _svp_rollback {
-    my ($self, $name) = @_;
+  my $txn_scope_guard = $self->txn_scope_guard;
+
+  $self->_do_query('SET CONSTRAINTS ALL DEFERRED');
 
-    $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
+  my $sg = Scope::Guard->new(sub {
+    $self->_do_query('SET CONSTRAINTS ALL IMMEDIATE');
+  });
+
+  return preserve_context { $sub->() } after => sub { $txn_scope_guard->commit };
 }
 
 =head2 connect_call_datetime_setup
@@ -107,10 +122,6 @@ sub connect_call_datetime_setup {
   $ENV{GL_DATETIME} = "%Y-%m-%d %H:%M:%S%F5";
 }
 
-sub datetime_parser_type {
-  'DBIx::Class::Storage::DBI::Informix::DateTime::Format'
-}
-
 package # hide from PAUSE
   DBIx::Class::Storage::DBI::Informix::DateTime::Format;