Remove obsolete Oracle _insert_returning method
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / SQLMaker / Oracle.pm
index b2a2c1f..715083a 100644 (file)
@@ -1,26 +1,34 @@
 package # Hide from PAUSE
   DBIx::Class::SQLMaker::Oracle;
 
-use warnings;
-use strict;
+use Module::Runtime ();
+use Moo;
+use namespace::clean;
 
-use base qw( DBIx::Class::SQLMaker );
-use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
+extends 'DBIx::Class::SQLMaker';
 
-sub new {
-  my $self = shift;
-  my %opts = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
-  push @{$opts{special_ops}}, {
-    regex => qr/^prior$/i,
-    handler => '_where_field_PRIOR',
-  };
+BEGIN {
+  use DBIx::Class::Optional::Dependencies;
+  die('The following extra modules are required for Oracle-based Storages ' . DBIx::Class::Optional::Dependencies->req_missing_for ('id_shortener') . "\n" )
+    unless DBIx::Class::Optional::Dependencies->req_ok_for ('id_shortener');
+}
 
-  $self->SUPER::new (\%opts);
+sub _build_converter_class {
+  Module::Runtime::use_module('DBIx::Class::SQLMaker::Converter::Oracle');
 }
 
+around _build_renderer_roles => sub {
+  my ($orig, $self) = (shift, shift);
+  (
+    'Data::Query::Renderer::SQL::Extension::ConnectBy',
+    'Data::Query::Renderer::SQL::Dialect::ReturnInto',
+    $self->$orig(@_),
+  );
+};
+
 sub _assemble_binds {
   my $self = shift;
-  return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/from where oracle_connect_by having order/);
+  return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/pre_select select from where oracle_connect_by group having order limit/);
 }
 
 
@@ -31,7 +39,7 @@ sub _parse_rs_attrs {
     my ($cb_sql, @cb_bind) = $self->_connect_by($rs_attrs);
     push @{$self->{oracle_connect_by_bind}}, @cb_bind;
 
-    my $sql = $self->SUPER::_parse_rs_attrs(@_);
+    my $sql = $self->next::method(@_);
 
     return "$cb_sql $sql";
 }
@@ -70,13 +78,13 @@ sub _order_siblings_by {
 
     my ( @sql, @bind );
     for my $c ( $self->_order_by_chunks($arg) ) {
-        $self->_SWITCH_refkind(
-            $c,
-            {
-                SCALAR   => sub { push @sql, $c },
-                ARRAYREF => sub { push @sql, shift @$c; push @bind, @$c },
-            }
-        );
+        if (ref $c) {
+            push @sql, shift @$c;
+            push @bind, @$c;
+        }
+        else {
+            push @sql, $c;
+        }
     }
 
     my $sql =
@@ -102,6 +110,19 @@ sub _where_field_PRIOR {
   return ($sql, @bind);
 }
 
+# use this codepath to hook all identifiers and mangle them if necessary
+# this is invoked regardless of quoting being on or off
+sub _quote {
+  my ($self, $label) = @_;
+
+  return '' unless defined $label;
+  return ${$label} if ref($label) eq 'SCALAR';
+
+  $label =~ s/ ( [^\.]{31,} ) /$self->_shorten_identifier($1)/gxe;
+
+  $self->next::method($label);
+}
+
 # this takes an identifier and shortens it if necessary
 # optionally keywords can be passed as an arrayref to generate useful
 # identifiers
@@ -118,7 +139,7 @@ sub _shorten_identifier {
   return $to_shorten
     if length($to_shorten) <= $max_len;
 
-  croak 'keywords needs to be an arrayref'
+  $self->throw_exception("'keywords' needs to be an arrayref")
     if defined $keywords && ref $keywords ne 'ARRAY';
 
   # if no keywords are passed use the identifier as one
@@ -183,48 +204,4 @@ sub _unqualify_colname {
   return $self->_shorten_identifier($self->next::method($fqcn));
 }
 
-#
-# Oracle has a different INSERT...RETURNING syntax
-#
-
-sub _insert_returning {
-  my ($self, $options) = @_;
-
-  my $f = $options->{returning};
-
-  my ($f_list, @f_names) = $self->_SWITCH_refkind($f, {
-    ARRAYREF => sub {
-      (join ', ', map { $self->_quote($_) } @$f),
-      @$f
-    },
-    SCALAR => sub {
-      $self->_quote($f),
-      $f,
-    },
-    SCALARREF => sub {
-      $$f,
-      $$f,
-    },
-  });
-
-  my $rc_ref = $options->{returning_container}
-    or croak ('No returning container supplied for IR values');
-
-  @$rc_ref = (undef) x @f_names;
-
-  return (
-    ( join (' ',
-      $self->_sqlcase(' returning'),
-      $f_list,
-      $self->_sqlcase('into'),
-      join (', ', ('?') x @f_names ),
-    )),
-    map {
-      $self->{bindtype} eq 'columns'
-        ? [ $f_names[$_] => \$rc_ref->[$_] ]
-        : \$rc_ref->[$_]
-    } (0 .. $#f_names),
-  );
-}
-
 1;