From: Matt S Trout Date: Sun, 12 Feb 2006 13:43:20 +0000 (+0000) Subject: add horrific fix to make Oracle's retarded limit syntax work X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f66596f958ad37be9be25133fc8d28fbcea272f8;p=dbsrgits%2FDBIx-Class-Historic.git add horrific fix to make Oracle's retarded limit syntax work --- diff --git a/Changes b/Changes index 54e8e00..922ef98 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class + - add horrific fix to make Oracle's retarded limit syntax work + 0.05003 2006-02-08 17:50:20 - add component_class accessors and use them for *_class - small fixes to Serialize and ResultSetManager diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 4a72a95..e42b013 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -134,6 +134,14 @@ 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(@_); +} + # Accessor for setting limit dialect. This is useful # for JDBC-bridge among others where the remote SQL-dialect cannot # be determined by the name of the driver alone. diff --git a/t/41orrible.t b/t/41orrible.t new file mode 100644 index 0000000..bd391da --- /dev/null +++ b/t/41orrible.t @@ -0,0 +1,25 @@ +use strict; +use warnings; + +use Test::More; +use DBIx::Class::Storage::DBI; + +plan tests => 1; + +my $sa = new DBIC::SQL::Abstract; + +$sa->limit_dialect('RowNum'); + +is($sa->select('rubbish', + [ 'foo.id', 'bar.id' ], + undef, undef, 1, 3), + 'SELECT * FROM +( + SELECT A.*, ROWNUM r FROM + ( + SELECT foo.id AS col1, bar.id AS col2 FROM rubbish + ) A + WHERE ROWNUM < 5 +) B +WHERE r >= 4 +', 'Munged stuff to make Oracle not explode');