[Rt-commit] r4274 - in Jifty-DBI/trunk: . lib/Jifty/DBI/Handle

jesse at bestpractical.com jesse at bestpractical.com
Fri Dec 9 01:18:44 EST 2005


Author: jesse
Date: Fri Dec  9 01:18:44 2005
New Revision: 4274

Modified:
   Jifty-DBI/trunk/   (props changed)
   Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Sybase.pm
Log:
 r19846 at truegrounds:  jesse | 2005-12-09 01:04:39 -0500
  * Ported fixes from SB to Sybase handle


Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Sybase.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Sybase.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Sybase.pm	Fri Dec  9 01:18:44 2005
@@ -93,16 +93,24 @@
 =cut
 
 sub distinct_query {
-    my $self         = shift;
-    my $statementref = shift;
-    my $table        = shift;
-
-    # 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) ";
-
+     my $self = shift;
+     my $statementref = shift;
+    my $sb = shift;
+    my $table = $sb->table;
+
+    if ($sb->_order_clause =~ /(?<!main)\./) {
+        # Don't know how to do ORDER BY when the DISTINCT is in a subquery
+        warn "Query will contain duplicate rows; don't how how to ORDER BY across DISTINCT";
+        $$statementref = "SELECT main.* FROM $$statementref";
+    } else {
+       # Wrapper select query in a subselect as Sybase 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) ";
+    }
+    $$statementref .= $sb->_group_clause;
+    $$statementref .= $sb->_order_clause;
 }
+ 
 
 =head2 binary_safe_blobs
 


More information about the Rt-commit mailing list