[Bps-public-commit] dbix-searchbuilder branch, same-column-twice, created. 1.59-32-g5bdddea

Ruslan Zakirov ruz at bestpractical.com
Fri May 27 18:26:14 EDT 2011


The branch, same-column-twice has been created
        at  5bdddea48ec055d83d614a7a0057fd94230b14c5 (commit)

- Log -----------------------------------------------------------------
commit 36a30ccb020bd5868b1a9b8b08ff95eca7f89583
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 28 02:25:07 2011 +0400

    don't fetch columns with duplicate aliases

diff --git a/lib/DBIx/SearchBuilder.pm b/lib/DBIx/SearchBuilder.pm
index d0080ec..534cea0 100755
--- a/lib/DBIx/SearchBuilder.pm
+++ b/lib/DBIx/SearchBuilder.pm
@@ -1605,6 +1605,14 @@ sub Column {
         && (!$args{'TABLE'} || $args{'TABLE'} eq $self->Table )
     ) {
         $column = $args{FIELD};
+
+        # make sure we don't fetch columns with duplicate aliases
+        if ( $self->{columns} ) {
+            my $suffix = " AS \L$column";
+            if ( grep index($_, $suffix, -length $suffix) >= 0, @{ $self->{columns} } ) {
+                $column .= scalar @{ $self->{columns} };
+            }
+        }
     }
     else {
         $column = "col" . @{ $self->{columns} ||= [] };

commit 5bdddea48ec055d83d614a7a0057fd94230b14c5
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 28 02:25:31 2011 +0400

    tests for ->Column method

diff --git a/t/01searches.t b/t/01searches.t
index 285035d..e7940d9 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 => 105;
+use constant TESTS_PER_DRIVER => 114;
 
 my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -287,6 +287,34 @@ SKIP: {
         is( $u->Login, 'glasser', "glasser is third in the list");
     }
 
+# Let's play with Column
+    $users_obj = TestApp::Users->new( $handle );
+    $users_obj->UnLimit;
+    {
+        is( $users_obj->Column(FIELD => 'id'), 'id' );
+        isnt( my $id_alias = $users_obj->Column(FIELD => 'id'), 'id' );
+        my $u = $users_obj->Next;
+        is ( $u->_Value($id_alias), $u->id, "fetched id twice" );
+    }
+
+    $users_obj = TestApp::Users->new( $handle );
+    $users_obj->UnLimit;
+    {
+        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" );
+    }
+
+    $users_obj = TestApp::Users->new( $handle );
+    $users_obj->UnLimit;
+    {
+        is( $users_obj->Column(FIELD => 'id'), 'id' );
+        isnt( my $id_alias = $users_obj->Column(FUNCTION => 'id + 1'), 'id' );
+        my $u = $users_obj->Next;
+        is ( $u->_Value($id_alias), $u->id + 1, "fetched id and function based on id" );
+    }
+
 	cleanup_schema( 'TestApp', $handle );
 }} # SKIP, foreach blocks
 

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



More information about the Bps-public-commit mailing list