squash
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / SQLMaker.pm
index 0db6ef2..556c54f 100644 (file)
@@ -224,6 +224,36 @@ sub insert {
   next::method(@_);
 }
 
+sub _insert_ARRAYREFREF {
+  my ($self, $data) = @_;
+
+  my ($cols, $subquery) = @$data;
+  if (not $subuery) {
+    # if somehow someone is calling this with the original SQLA api,
+    # pass it along
+    return next::method($self, $cols);
+  }
+
+  my $subsql, @subbind = @$subquery;
+
+  my @fields = sort @$cols;
+
+  my ($sql, @bind) = $self->_insert_values($data);
+
+  $_ = $self->_quote($_) foreach @$fields;
+  $sql = "( ".join(", ", sort @$fields).") ".$sql;
+
+  return ($sql, @bind);
+
+  # when passing ARRAYREFREF with [cols], SQLA drops INTO $table (cols)
+  # we inject the returned sql here
+  #$_ = $self->_quote($_) foreach @fields;
+  #  $sql = "( ".join(", ", @fields).") ".$sql;
+    my $sql = sprintf(
+      'INSERT INTO %s( %s ) VALUES', $_[0]->_quote($_[1])
+    );
+}
+
 sub _recurse_fields {
   my ($self, $fields) = @_;
   my $ref = ref $fields;