[Bps-public-commit] dbix-searchbuilder branch truncate-then-compare created. 1.71-13-g253f48f

BPS Git Server git at git.bestpractical.com
Fri Oct 21 20:04:05 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, truncate-then-compare has been created
        at  253f48f26a4a8e1772d3f338a2d95f3f692baa76 (commit)

- Log -----------------------------------------------------------------
commit 253f48f26a4a8e1772d3f338a2d95f3f692baa76
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Oct 21 15:56:25 2022 -0400

    Truncate values before checking for changes
    
    Previously values were truncated after being compared
    to the current value, so a value longer than the column
    size will always appear different from the current value
    even if the same value is provided multiple times.
    
    Truncate first so the check will compare the current value
    with the version of the new value that will actually be put
    in the database.

diff --git a/lib/DBIx/SearchBuilder/Record.pm b/lib/DBIx/SearchBuilder/Record.pm
index d5e6f2f..02058be 100755
--- a/lib/DBIx/SearchBuilder/Record.pm
+++ b/lib/DBIx/SearchBuilder/Record.pm
@@ -811,6 +811,9 @@ sub __Set {
         }
     }
 
+    # First, we truncate the value, if we need to.
+    $args{'Value'} = $self->TruncateValue( $args{'Column'}, $args{'Value'} );
+
     my $current_value = $self->__Value($column);
 
     if (
@@ -829,15 +832,6 @@ sub __Set {
         return ( $ret->return_value );
     }
 
-
-
-    # First, we truncate the value, if we need to.
-    #
-    
-
-    $args{'Value'} = $self->TruncateValue ( $args{'Column'}, $args{'Value'});
-
-
     my $method = "Validate" . $args{'Column'};
     unless ( $self->$method( $args{'Value'} ) ) {
         $ret->as_array( 0, 'Illegal value for ' . $args{'Column'} );

commit 08ea6340ee256167a48ed1fe797fc4d1b10573e4
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Oct 21 15:52:08 2022 -0400

    Add test showing long values get re-added on update
    
    Values are currently truncated to fit in the defined field
    length after the comparison to check if the new value is
    the same as the current value. So if you submit a value
    bigger than the column size repeatedly, the field will
    update each time rather than correctly detecting it
    as the same value.

diff --git a/t/01records.t b/t/01records.t
index d701e94..0aef260 100644
--- a/t/01records.t
+++ b/t/01records.t
@@ -7,7 +7,7 @@ use Test::More;
 BEGIN { require "./t/utils.pl" }
 our (@AvailableDrivers);
 
-use constant TESTS_PER_DRIVER => 66;
+use constant TESTS_PER_DRIVER => 69;
 
 my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -93,6 +93,13 @@ SKIP: {
 	$val = $rec->TruncateValue(Phone => '12345678901234567890');
 	is($val, '123456789012345678', 'truncate by length attribute');
 
+# Confirm we truncate before comparing values and
+# don't try to update again with the same value
+
+    ($val,$msg) = $rec->SetName('1234567890123456789012345678901234567890');
+    ok(!$val, $msg);
+    is($msg, 'That is already the current value', 'No update for same value');
+    is($rec->Name, '12345678901234', "Value is the same");
 
 # Test unicode truncation:
 	my $univalue = "這是個測試";

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


hooks/post-receive
-- 
dbix-searchbuilder


More information about the Bps-public-commit mailing list