X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI.pm;h=c485257f811c9cd121a585896762a667e8ce58a9;hb=f7a90adc1a7f6ecbb940947deb461f0e91a993eb;hp=84dc7b887a9eafd1b4ed793827bc459af36f2c71;hpb=2cc3a7be389cb22aacc99425cf7ed3493b4ebf2a;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 84dc7b8..c485257 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -39,6 +39,8 @@ sub _find_syntax { sub select { my ($self, $table, $fields, $where, $order, @rest) = @_; $table = $self->_quote($table) unless ref($table); + local $self->{rownum_hack_count} = 1 + if (defined $rest[0] && $self->{limit_dialect} eq 'RowNum'); @rest = (-1) unless defined $rest[0]; die "LIMIT 0 Does Not Compute" if $rest[0] == 0; # and anyway, SQL::Abstract::Limit will cause a barf if we don't first @@ -86,7 +88,12 @@ sub _recurse_fields { return $$fields if $ref eq 'SCALAR'; if ($ref eq 'ARRAY') { - return join(', ', map { $self->_recurse_fields($_) } @$fields); + return join(', ', map { + $self->_recurse_fields($_) + .(exists $self->{rownum_hack_count} + ? ' AS col'.$self->{rownum_hack_count}++ + : '') + } @$fields); } elsif ($ref eq 'HASH') { foreach my $func (keys %$fields) { return $self->_sqlcase($func) @@ -113,8 +120,16 @@ sub _order_by { if (defined $_[0]->{order_by}) { $ret .= $self->SUPER::_order_by($_[0]->{order_by}); } - } elsif(ref $_[0] eq 'SCALAR') { + } elsif (ref $_[0] eq 'SCALAR') { $ret = $self->_sqlcase(' order by ').${ $_[0] }; + } elsif (ref $_[0] eq 'ARRAY' && @{$_[0]}) { + my @order = @{+shift}; + $ret = $self->_sqlcase(' order by ') + .join(', ', map { + my $r = $self->_order_by($_, @_); + $r =~ s/^ ?ORDER BY //i; + $r; + } @order); } else { $ret = $self->SUPER::_order_by(@_); } @@ -215,14 +230,6 @@ sub _quote { 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(@_); -} - sub limit_dialect { my $self = shift; $self->{limit_dialect} = shift if @_; @@ -410,6 +417,9 @@ This method is deprecated in favor of setting via L. Causes SQL trace information to be emitted on the C object. (or C if C has not specifically been set). +This is the equivalent to setting L in your +shell environment. + =head2 debugfh Set or retrieve the filehandle used for trace/debug output. This should be @@ -1036,13 +1046,14 @@ L. sub deploy { my ($self, $schema, $type, $sqltargs) = @_; - foreach my $statement ( $self->deployment_statements($schema, $type, undef, undef, $sqltargs) ) { + foreach my $statement ( $self->deployment_statements($schema, $type, undef, undef, { no_comments => 1, %$sqltargs }) ) { for ( split(";\n", $statement)) { next if($_ =~ /^--/); next if(!$_); # next if($_ =~ /^DROP/m); next if($_ =~ /^BEGIN TRANSACTION/m); next if($_ =~ /^COMMIT/m); + next if $_ =~ /^\s+$/; # skip whitespace only $self->debugobj->query_start($_) if $self->debug; $self->dbh->do($_) or warn "SQL was:\n $_"; $self->debugobj->query_end($_) if $self->debug;