[Bps-public-commit] dbix-searchbuilder branch, question-mark-only-function, created. 1.59-35-gca59ce0

Ruslan Zakirov ruz at bestpractical.com
Sat May 28 14:07:32 EDT 2011


The branch, question-mark-only-function has been created
        at  ca59ce06feeb445671cf7a500cf008e8384b44f4 (commit)

- Log -----------------------------------------------------------------
commit ca59ce06feeb445671cf7a500cf008e8384b44f4
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 28 12:05:59 2011 +0400

    split /\?/, '?' results in empty set, use =~ s/...

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index 534cea0..c22a84a 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -1579,8 +1579,8 @@ sub Column {
             $name = "COUNT(DISTINCT $name)";
         }
         # If we want to substitute 
-        elsif ($func =~ /\?/) {
-            $name = join($name,split(/\?/,$func));
+        elsif ($func =~ s/\?/$name/g) {
+            $name = $func;
         }
         # If we want to call a simple function on the column
         elsif ($func !~ /\(/)  {
diff --git a/t/01searches.t b/t/01searches.t
index e7940d9..9fdfc45 100644
--- a/t/01searches.t
+++ b/t/01searches.t
@@ -7,7 +7,7 @@ use Test::More;
 BEGIN { require "t/utils.pl" }
 our (@AvailableDrivers);
 
-use constant TESTS_PER_DRIVER => 114;
+use constant TESTS_PER_DRIVER => 117;
 
 my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -303,7 +303,8 @@ SKIP: {
         is( $users_obj->Column(FIELD => 'id'), 'id' );
         isnt( my $id_alias = $users_obj->Column(FIELD => 'id', FUNCTION => '? + 1'), 'id' );
         my $u = $users_obj->Next;
-        is ( $u->_Value($id_alias), $u->id + 1, "fetched id and function based on id" );
+        is ( $u->_Value($id_alias), $u->id + 1, "fetched id and function based on id" )
+            or diag "wrong SQL: ". $users_obj->BuildSelectQuery;
     }
 
     $users_obj = TestApp::Users->new( $handle );
@@ -315,6 +316,15 @@ SKIP: {
         is ( $u->_Value($id_alias), $u->id + 1, "fetched id and function based on id" );
     }
 
+    $users_obj = TestApp::Users->new( $handle );
+    $users_obj->UnLimit;
+    {
+        is( $users_obj->Column(FIELD => 'id'), 'id' );
+        isnt( my $id_alias = $users_obj->Column(FUNCTION => '?', FIELD => 'id'), 'id' );
+        my $u = $users_obj->Next;
+        is ( $u->_Value($id_alias), $u->id, "fetched with '?' function" );
+    }
+
 	cleanup_schema( 'TestApp', $handle );
 }} # SKIP, foreach blocks
 

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



More information about the Bps-public-commit mailing list