X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSQLMaker.pm;h=14fbb291ddf1c6cd90bd05ebab093075884963ed;hb=d71502b;hp=cfb3e4cc70248f3f0046325468bd3d88ae319f3a;hpb=7558b2281b1be380c67129e904b3b7b6409489a7;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/SQLMaker.pm b/lib/DBIx/Class/SQLMaker.pm index cfb3e4c..14fbb29 100644 --- a/lib/DBIx/Class/SQLMaker.pm +++ b/lib/DBIx/Class/SQLMaker.pm @@ -40,7 +40,6 @@ use mro 'c3'; use Sub::Name 'subname'; use DBIx::Class::Carp; -use DBIx::Class::Exception; use namespace::clean; __PACKAGE__->mk_group_accessors (simple => qw/quote_char name_sep limit_dialect/); @@ -86,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] ) @@ -320,6 +323,18 @@ sub _order_by { } } +sub _split_order_chunk { + my ($self, $chunk) = @_; + + # strip off sort modifiers, but always succeed, so $1 gets reset + $chunk =~ s/ (?: \s+ (ASC|DESC) )? \s* $//ix; + + return ( + $chunk, + ( $1 and uc($1) eq 'DESC' ) ? 1 : 0, + ); +} + sub _table { # optimized due to hotttnesss # my ($self, $from) = @_; @@ -352,7 +367,6 @@ sub _generate_join_clause { sub _recurse_from { my $self = shift; - return join (' ', $self->_gen_from_blocks(@_) ); } @@ -455,6 +469,55 @@ sub _join_condition { return $self->_recurse_where($cond); } +# This is hideously ugly, but SQLA does not understand multicol IN expressions +# FIXME TEMPORARY - DQ should have native syntax for this +# moved here to raise API questions +# +# !!! EXPERIMENTAL API !!! WILL CHANGE !!! +sub _where_op_multicolumn_in { + my ($self, $lhs, $rhs) = @_; + + if (! ref $lhs or ref $lhs eq 'ARRAY') { + my (@sql, @bind); + for (ref $lhs ? @$lhs : $lhs) { + if (! ref $_) { + push @sql, $self->_quote($_); + } + elsif (ref $_ eq 'SCALAR') { + push @sql, $$_; + } + elsif (ref $_ eq 'REF' and ref $$_ eq 'ARRAY') { + my ($s, @b) = @$$_; + push @sql, $s; + push @bind, @b; + } + else { + $self->throw_exception("ARRAY of @{[ ref $_ ]}es unsupported for multicolumn IN lhs..."); + } + } + $lhs = \[ join(', ', @sql), @bind]; + } + elsif (ref $lhs eq 'SCALAR') { + $lhs = \[ $$lhs ]; + } + elsif (ref $lhs eq 'REF' and ref $$lhs eq 'ARRAY' ) { + # noop + } + else { + $self->throw_exception( ref($lhs) . "es unsupported for multicolumn IN lhs..."); + } + + # is this proper...? + $rhs = \[ $self->_recurse_where($rhs) ]; + + for ($lhs, $rhs) { + $$_->[0] = "( $$_->[0] )" + unless $$_->[0] =~ /^ \s* \( .* \) \s* ^/xs; + } + + \[ join( ' IN ', shift @$$lhs, shift @$$rhs ), @$$lhs, @$$rhs ]; +} + 1; =head1 AUTHORS