squash
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / SQLMaker.pm
index cac1db0..556c54f 100644 (file)
@@ -85,6 +85,10 @@ BEGIN {
 # as the value to abuse with MSSQL ordered subqueries)
 sub __max_int () { 0x7FFFFFFF };
 
+# we ne longer need to check this - DBIC has ways of dealing with it
+# specifically ::Storage::DBI::_resolve_bindattrs()
+sub _assert_bindval_matches_bindtype () { 1 };
+
 # poor man's de-qualifier
 sub _quote {
   $_[0]->next::method( ( $_[0]{_dequalify_idents} and ! ref $_[1] )
@@ -220,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;
@@ -274,7 +308,7 @@ sub _recurse_fields {
 # What we have been doing forever is hijacking the $order arg of
 # SQLA::select to pass in arbitrary pieces of data (first the group_by,
 # then pretty much the entire resultset attr-hash, as more and more
-# things in the SQLA space need to have mopre info about the $rs they
+# things in the SQLA space need to have more info about the $rs they
 # create SQL for. The alternative would be to keep expanding the
 # signature of _select with more and more positional parameters, which
 # is just gross. All hail SQLA2!
@@ -284,7 +318,7 @@ sub _parse_rs_attrs {
   my $sql = '';
 
   if ($arg->{group_by}) {
-    # horible horrible, waiting for refactor
+    # horrible horrible, waiting for refactor
     local $self->{select_bind};
     if (my $g = $self->_recurse_fields($arg->{group_by}) ) {
       $sql .= $self->_sqlcase(' group by ') . $g;