add horrific fix to make Oracle's retarded limit syntax work
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI.pm
index cb1dbd7..e42b013 100644 (file)
@@ -130,9 +130,18 @@ sub _join_condition {
 sub _quote {
   my ($self, $label) = @_;
   return '' unless defined $label;
+  return $label unless $self->{quote_char};
   return $self->SUPER::_quote($label);
 }
 
+sub _RowNum {
+   my $self = shift;
+   my $c;
+   $_[0] =~ s/SELECT (.*?) FROM/
+     'SELECT '.join(', ', map { $_.' AS col'.++$c } split(', ', $1)).' FROM'/e;
+   $self->SUPER::_RowNum(@_);
+}
+
 # Accessor for setting limit dialect. This is useful
 # for JDBC-bridge among others where the remote SQL-dialect cannot
 # be determined by the name of the driver alone.
@@ -222,7 +231,11 @@ sub debugcb {
 sub disconnect {
   my ($self) = @_;
 
-  $self->_dbh->disconnect if $self->_dbh;
+  if( $self->connected ) {
+    $self->_dbh->rollback unless $self->_dbh->{AutoCommit};
+    $self->_dbh->disconnect;
+    $self->_dbh(undef);
+  }
 }
 
 sub connected {
@@ -318,7 +331,10 @@ sub _execute {
   my ($self, $op, $extra_bind, $ident, @args) = @_;
   my ($sql, @bind) = $self->sql_maker->$op($ident, @args);
   unshift(@bind, @$extra_bind) if $extra_bind;
-  $self->debugfh->print("$sql: @bind\n") if $self->debug;
+  if ($self->debug) {
+      my @debug_bind = map { defined $_ ? $_ : 'NULL' } @bind;
+      $self->debugfh->print("$sql: @debug_bind\n");
+  }
   my $sth = $self->sth($sql,$op);
   @bind = map { ref $_ ? ''.$_ : $_ } @bind; # stringify args
   my $rv;
@@ -417,6 +433,8 @@ sub columns_info_for {
     return \%result;
 }
 
+sub DESTROY { shift->disconnect }
+
 1;
 
 =head1 ENVIRONMENT VARIABLES