[Rt-commit] r4275 - in Jifty-DBI/trunk: . lib/Jifty/DBI/Handle
jesse at bestpractical.com
jesse at bestpractical.com
Fri Dec 9 01:18:50 EST 2005
Author: jesse
Date: Fri Dec 9 01:18:50 2005
New Revision: 4275
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Oracle.pm
Log:
r19847 at truegrounds: jesse | 2005-12-09 01:05:33 -0500
* Ported fixes from SB to Orace handle
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Oracle.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Oracle.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Oracle.pm Fri Dec 9 01:18:50 2005
@@ -243,17 +243,30 @@
=cut
-sub distinct_query {
- my $self = shift;
+
+ sub distinct_query {
+ my $self = shift;
my $statementref = shift;
- my $table = shift;
+ my $sb = shift;
+ my $table = $sb->Table;
- # Wrapper select query in a subselect as Oracle doesn't allow
- # DISTINCT against CLOB/BLOB column types.
- $$statementref
- = "SELECT main.* FROM ( SELECT DISTINCT main.id FROM $$statementref ) distinctquery, $table main WHERE (main.id = distinctquery.id) ";
-
-}
+ # Wrapp select query in a subselect as Oracle doesn't allow
+ # DISTINCT against CLOB/BLOB column types.
+ if ($sb->_order_clause =~ /(?<!main)\./) {
+ # If we are ordering by something not in 'main', we need to GROUP
+ # BY and adjust the ORDER_BY accordingly
+ local $sb->{group_by} = [@{$sb->{group_by} || []}, {column => 'id'}];
+ local $sb->{order_by} = [map {($_->{alias} and $_->{alias} ne "main") ? {%{$_}, column => "min(".$_->{column}.")"}: $_} @{$sb->{order_by}}];
+ my $group = $sb->_group_clause;
+ my $order = $sb->_order_clause;
+ $$statementref = "SELECT main.* FROM ( SELECT main.id FROM $$statementref $group $order ) distinctquery, $table main WHERE (main.id = distinctquery.id)";
+ } else {
+ $$statementref = "SELECT main.* FROM ( SELECT DISTINCT main.id FROM $$statementref ) distinctquery, $table main WHERE (main.id = distinctquery.id) ";
+ $$statementref .= $sb->_group_clause;
+ $$statementref .= $sb->_order_clause;
+ }
+ }
+
=head2 binary_safe_blobs
More information about the Rt-commit
mailing list