[Bps-public-commit] dbix-searchbuilder branch multiple-functions-in-order-by updated. 1.71-2-gfd68bae

BPS Git Server git at git.bestpractical.com
Mon Feb 14 20:53:56 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "dbix-searchbuilder".

The branch, multiple-functions-in-order-by has been updated
       via  fd68bae5de6ce91ae2476ebe425420c20de96a62 (commit)
      from  6faa39d9353fcf4b53aed66acb7334dab0cb17a9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit fd68bae5de6ce91ae2476ebe425420c20de96a62
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Feb 15 04:28:41 2022 +0800

    Test nested functions for external fields in OrderBy

diff --git a/t/02order_outer.t b/t/02order_outer.t
index 14a39fe..c91c7f3 100644
--- a/t/02order_outer.t
+++ b/t/02order_outer.t
@@ -7,7 +7,7 @@ use Test::More;
 BEGIN { require "./t/utils.pl" }
 our (@AvailableDrivers);
 
-use constant TESTS_PER_DRIVER => 98;
+use constant TESTS_PER_DRIVER => 104;
 
 my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -57,39 +57,44 @@ diag "generate data" if $ENV{TEST_VERBOSE};
 
 # ASC order
 foreach my $direction ( qw(ASC DESC) ) {
-    my $objs = TestApp::Objects->new($handle);
-    $objs->UnLimit;
-    my $tags_alias = $objs->Join(
-        TYPE   => 'LEFT',
-        ALIAS1 => 'main',
-        FIELD1 => 'id',
-        TABLE2 => 'Tags',
-        FIELD2 => 'Object',
-    );
-    ok($tags_alias, "joined tags table");
-    $objs->OrderBy( ALIAS => $tags_alias, FIELD => 'Name', ORDER => $direction );
-
-    ok($objs->First, 'ok, we have at least one result');
-    $objs->GotoFirstItem;
-
-    my ($order_ok, $last) = (1, $direction eq 'ASC'? '-': 'zzzz');
-    while ( my $obj = $objs->Next ) {
-        my $tmp;
-        if ( $direction eq 'ASC' ) {
-            $tmp = (substr($last, 0, 1) cmp substr($obj->Name, 0, 1));
-        } else {
-            $tmp = -(substr($last, -1, 1) cmp substr($obj->Name, -1, 1));
-        }
-        if ( $tmp > 0 ) {
-            $order_ok = 0; last;
-        }
-        $last = $obj->Name;
-    }
-    ok($order_ok, "$direction order is correct") or do {
-        diag "Wrong $direction query: ". $objs->BuildSelectQuery;
+    for my $field ( 'Name',
+        $d eq 'Oracle' ? 'TO_CHAR(Name)' : $d eq 'mysql' ? 'BINARY(Name)' : 'CAST(Name AS TEXT)' )
+    {
+        my $objs = TestApp::Objects->new($handle);
+        $objs->UnLimit;
+        my $tags_alias = $objs->Join(
+            TYPE   => 'LEFT',
+            ALIAS1 => 'main',
+            FIELD1 => 'id',
+            TABLE2 => 'Tags',
+            FIELD2 => 'Object',
+        );
+        ok($tags_alias, "joined tags table");
+        # Generated SQL is MIN(Name) or nested functions like MIN(CAST(Name AS TEXT))
+        $objs->OrderBy( ALIAS => $tags_alias, FIELD => $field, ORDER => $direction );
+
+        ok($objs->First, 'ok, we have at least one result');
         $objs->GotoFirstItem;
+
+        my ($order_ok, $last) = (1, $direction eq 'ASC'? '-': 'zzzz');
         while ( my $obj = $objs->Next ) {
-            diag($obj->id .":". $obj->Name);
+            my $tmp;
+            if ( $direction eq 'ASC' ) {
+                $tmp = (substr($last, 0, 1) cmp substr($obj->Name, 0, 1));
+            } else {
+                $tmp = -(substr($last, -1, 1) cmp substr($obj->Name, -1, 1));
+            }
+            if ( $tmp > 0 ) {
+                $order_ok = 0; last;
+            }
+            $last = $obj->Name;
+        }
+        ok($order_ok, "$direction order is correct") or do {
+            diag "Wrong $direction query: ". $objs->BuildSelectQuery;
+            $objs->GotoFirstItem;
+            while ( my $obj = $objs->Next ) {
+                diag($obj->id .":". $obj->Name);
+            }
         }
     }
 }

-----------------------------------------------------------------------

Summary of changes:
 t/02order_outer.t | 69 +++++++++++++++++++++++++++++--------------------------
 1 file changed, 37 insertions(+), 32 deletions(-)


hooks/post-receive
-- 
dbix-searchbuilder


More information about the Bps-public-commit mailing list