From: Jess Robinson Date: Fri, 18 Aug 2006 11:00:24 +0000 (+0000) Subject: Assume scalar refs need fetching in PK::Auto (to allow \'DEFAULT' X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=260129d83a3f9906ad0ab75b728c7ca5b6ea2fd1;p=dbsrgits%2FDBIx-Class-Historic.git Assume scalar refs need fetching in PK::Auto (to allow \'DEFAULT' Add RowNumberOver for limits with DB2 --- diff --git a/lib/DBIx/Class/PK/Auto.pm b/lib/DBIx/Class/PK/Auto.pm index d8a6e16..41c14a6 100644 --- a/lib/DBIx/Class/PK/Auto.pm +++ b/lib/DBIx/Class/PK/Auto.pm @@ -42,7 +42,8 @@ sub insert { my ($self, @rest) = @_; my $ret = $self->next::method(@rest); - my ($pri, $too_many) = grep { !defined $self->get_column($_) } $self->primary_columns; + my ($pri, $too_many) = grep { !defined $self->get_column($_) || + ref($self->get_column($_)) eq 'SCALAR'} $self->primary_columns; return $ret unless defined $pri; # if all primaries are already populated, skip auto-inc $self->throw_exception( "More than one possible key found for auto-inc on ".ref $self ) if defined $too_many; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 59f0357..6cfc4b8 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -29,10 +29,36 @@ sub new { $self; } +sub _RowNumberOver { + my ($self, $sql, $order, $rows, $offset ) = @_; + + $offset += 1; + my $last = $rows + $offset; + my ( $order_by ) = $self->_order_by( $order ); + + $sql = <<""; +SELECT * FROM +( + SELECT Q1.*, ROW_NUMBER() OVER( ) AS ROW_NUM FROM ( + $sql + $order_by + ) Q1 +) Q2 +WHERE ROW_NUM BETWEEN $offset AND $last + + return $sql; +} + + # While we're at it, this should make LIMIT queries more efficient, # without digging into things too deeply sub _find_syntax { my ($self, $syntax) = @_; + my $dbhname = eval { $syntax->{Driver}->{Name}} || ''; + if(ref($self) && $dbhname && $dbhname eq 'DB2') { + return 'RowNumberOver'; + } + $self->{_cached_syntax} ||= $self->SUPER::_find_syntax($syntax); } @@ -1042,8 +1068,8 @@ L. =cut sub deploy { - my ($self, $schema, $type, $sqltargs) = @_; - foreach my $statement ( $self->deployment_statements($schema, $type, undef, undef, { no_comments => 1, %{ $sqltargs || {} } } ) ) { + my ($self, $schema, $type, $sqltargs, $dir) = @_; + foreach my $statement ( $self->deployment_statements($schema, $type, undef, $dir, { no_comments => 1, %{ $sqltargs || {} } } ) ) { for ( split(";\n", $statement)) { next if($_ =~ /^--/); next if(!$_);