[Bps-public-commit] dbix-searchbuilder branch, set-undef-fix, updated. 1.59-35-g0d52848

? sunnavy sunnavy at bestpractical.com
Sun May 29 21:30:47 EDT 2011


The branch, set-undef-fix has been updated
       via  0d52848f68e91ab0384caf978d91ecac15f3051e (commit)
       via  6c889a10ba103446c0cf8762837445028cc63f6c (commit)
      from  1d11119e313570731c98a530207335c355b1ffe4 (commit)

Summary of changes:
 lib/DBIx/SearchBuilder/Record.pm |   14 +++++++++++---
 t/02records_integers.t           |   17 +++++++----------
 2 files changed, 18 insertions(+), 13 deletions(-)

- Log -----------------------------------------------------------------
commit 6c889a10ba103446c0cf8762837445028cc63f6c
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon May 30 09:07:30 2011 +0800

    tiny tweak: avoid calling ->__Value again and again

diff --git a/lib/DBIx/SearchBuilder/Record.pm b/lib/DBIx/SearchBuilder/Record.pm
index cfde333..aa6f276 100755
--- a/lib/DBIx/SearchBuilder/Record.pm
+++ b/lib/DBIx/SearchBuilder/Record.pm
@@ -782,10 +782,13 @@ sub __Set {
         }
     }
 
+    my $current_value = $self->__Value($column);
+
     if (
-        ( !defined $self->__Value($column) && !defined $args{'Value'} )
-        || ( defined $self->__Value($column) && defined $args{'Value'}
-            && ( $args{'Value'} eq $self->__Value($column) ) )
+        ( !defined $args{'Value'} && !defined $current_value )
+        || (   defined $args{'Value'}
+            && defined $current_value
+            && ( $args{'Value'} eq $current_value ) )
       )
     {
         $ret->as_array( 0, "That is already the current value" );

commit 0d52848f68e91ab0384caf978d91ecac15f3051e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon May 30 09:27:11 2011 +0800

    fallback to default value if we are setting undef to a not-null field

diff --git a/lib/DBIx/SearchBuilder/Record.pm b/lib/DBIx/SearchBuilder/Record.pm
index aa6f276..57bd3fa 100755
--- a/lib/DBIx/SearchBuilder/Record.pm
+++ b/lib/DBIx/SearchBuilder/Record.pm
@@ -781,6 +781,11 @@ sub __Set {
             $args{'Value'} = 0;
         }
     }
+    else {
+        if ( $self->_Accessible( $args{Column}, 'no_nulls' ) ) {
+            $args{'Value'} = $self->_Accessible( $args{Column}, 'default' );
+        }
+    }
 
     my $current_value = $self->__Value($column);
 
diff --git a/t/02records_integers.t b/t/02records_integers.t
index 28d61cd..c886adf 100644
--- a/t/02records_integers.t
+++ b/t/02records_integers.t
@@ -80,20 +80,17 @@ SKIP: {
         ok($status, "status ok") or diag $status->error_message;
         is($rec->Mandatory, 2, 'set optional field to 2');
 
+        $status = $rec->SetMandatory( undef );
+        ok($status, "status ok") or diag $status->error_message;
+        is($rec->Mandatory, 1, 'fallback to default');
+
         $status = $rec->SetMandatory( '' );
         ok($status, "status ok") or diag $status->error_message;
         is($rec->Mandatory, 0, 'empty string should be threated as zero');
 
-        TODO: {
-            local $TODO = 'fallback to default value'
-                .' if field is NOT NULL and we try set it to NULL';
-            $status = $rec->SetMandatory( undef );
-            ok($status, "status ok") or diag $status->error_message;
-            is($rec->Mandatory, 1, 'fallback to default');
-            $status = $rec->SetMandatory;
-            ok($status, "status ok") or diag $status->error_message;
-            is($rec->Mandatory, 1, 'no value on set also fallback');
-        }
+        $status = $rec->SetMandatory;
+        ok($status, "status ok") or diag $status->error_message;
+        is($rec->Mandatory, 1, 'no value on set also fallback');
     }
 
     cleanup_schema( 'TestApp::Address', $handle );

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



More information about the Bps-public-commit mailing list