[Bps-public-commit] dbix-searchbuilder branch, set-undef-fix, created. 1.59-33-g1d11119
? sunnavy
sunnavy at bestpractical.com
Thu May 26 00:18:42 EDT 2011
The branch, set-undef-fix has been created
at 1d11119e313570731c98a530207335c355b1ffe4 (commit)
- Log -----------------------------------------------------------------
commit aa5adf48bbdbe7d49ba0ea91cf993700655f63ca
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu May 26 11:23:48 2011 +0800
allow undef set
diff --git a/lib/DBIx/SearchBuilder/Record.pm b/lib/DBIx/SearchBuilder/Record.pm
index 5bd4cf3..4fea057 100755
--- a/lib/DBIx/SearchBuilder/Record.pm
+++ b/lib/DBIx/SearchBuilder/Record.pm
@@ -782,17 +782,11 @@ sub __Set {
}
}
- unless ( defined $args{'Value'} ) {
- $ret->as_array( 0, "No value passed to _Set" );
- $ret->as_error(
- errno => 2,
- do_backtrace => 0,
- message => "No value passed to _Set"
- );
- return ( $ret->return_value );
- }
- elsif ( ( defined $self->__Value($column) )
- and ( $args{'Value'} eq $self->__Value($column) ) )
+ if (
+ ( !defined $self->__Value($column) && !defined $args{'Value'} )
+ || ( defined $self->__Value($column) && defined $args{'Value'}
+ && ( $args{'Value'} eq $self->__Value($column) ) )
+ )
{
$ret->as_array( 0, "That is already the current value" );
$ret->as_error(
commit 322b1779b25aa57a8b19a11582756d92b6196574
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu May 26 11:58:33 2011 +0800
update test as we can set null now
diff --git a/t/01records.t b/t/01records.t
index 1730645..a1f1366 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 => 67;
+use constant TESTS_PER_DRIVER => 66;
my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
plan tests => $total;
@@ -194,11 +194,9 @@ SKIP: {
isa_ok( $val, 'Class::ReturnValue', "couldn't set invalid value, error returned");
is( ($val->as_array)[1], 'Illegal value for Name', "correct error message" );
is( $rec->Name, 'Obra', "old value is still there");
-# XXX TODO FIXME: this test cover current implementation that is broken //RUZ
- $val = $rec->SetName( );
- isa_ok( $val, 'Class::ReturnValue', "couldn't set empty/undef value, error returned");
- is( ($val->as_array)[1], "No value passed to _Set", "correct error message" );
- is( $rec->Name, 'Obra', "old value is still there");
+ ( $val, $msg ) = $rec->SetName();
+ ok( $val, $msg );
+ is( $rec->Name, undef, "no value means null");
# deletes
$newrec = TestApp::Address->new($handle);
@@ -231,6 +229,7 @@ sub _Init {
sub ValidateName
{
my ($self, $value) = @_;
+ return 1 unless defined $value;
return 0 if $value =~ /invalid/i;
return 1;
}
diff --git a/t/02records_integers.t b/t/02records_integers.t
index a93a329..28d61cd 100644
--- a/t/02records_integers.t
+++ b/t/02records_integers.t
@@ -63,19 +63,17 @@ SKIP: {
ok($status, "status ok") or diag $status->error_message;
is($rec->Optional, 1, 'set optional field to 1');
+ $status = $rec->SetOptional( undef );
+ ok($status, "status ok") or diag $status->error_message;
+ is($rec->Optional, undef, 'undef equal to NULL');
+
$status = $rec->SetOptional( '' );
ok($status, "status ok") or diag $status->error_message;
is($rec->Optional, 0, 'empty string should be threated as zero');
- TODO: {
- local $TODO = 'we have no way to set NULL value';
- $status = $rec->SetOptional( undef );
- ok($status, "status ok") or diag $status->error_message;
- is($rec->Optional, undef, 'undef equal to NULL');
- $status = $rec->SetOptional;
- ok($status, "status ok") or diag $status->error_message;
- is($rec->Optional, undef, 'no value is NULL too');
- }
+ $status = $rec->SetOptional;
+ ok($status, "status ok") or diag $status->error_message;
+ is($rec->Optional, undef, 'no value is NULL too');
# set operations on mandatory field
$status = $rec->SetMandatory( 2 );
commit 1d11119e313570731c98a530207335c355b1ffe4
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu May 26 11:59:12 2011 +0800
warning fix
diff --git a/lib/DBIx/SearchBuilder/Record.pm b/lib/DBIx/SearchBuilder/Record.pm
index 4fea057..cfde333 100755
--- a/lib/DBIx/SearchBuilder/Record.pm
+++ b/lib/DBIx/SearchBuilder/Record.pm
@@ -838,8 +838,10 @@ sub __Set {
my $val = $self->_Handle->UpdateRecordValue(%args);
unless ($val) {
- my $message =
- $args{'Column'} . " could not be set to " . $args{'Value'} . "." ;
+ my $message =
+ $args{'Column'}
+ . " could not be set to "
+ . ( defined $args{'Value'} ? $args{'Value'} : 'undef' ) . ".";
$ret->as_array( 0, $message);
$ret->as_error(
errno => 4,
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list