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

? sunnavy sunnavy at bestpractical.com
Mon May 30 13:42:44 EDT 2011


The branch, set-undef-fix has been updated
       via  2b613bb8fbd41ac1b7cb7760953d6a7e162382d1 (commit)
       via  86adcad23ceb5e57fd94fe457769f5836e859ad8 (commit)
       via  60def87e138f770a3563c7d953bb0b679ca10c14 (commit)
      from  bce622140b2e7d415f7beec37ecefb5f463bfa15 (commit)

Summary of changes:
 lib/DBIx/SearchBuilder/Record.pm |   15 ++++-
 t/02records_integers.t           |   16 +++-
 t/20set_edge_cases.t             |  141 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 167 insertions(+), 5 deletions(-)
 create mode 100644 t/20set_edge_cases.t

- Log -----------------------------------------------------------------
commit 60def87e138f770a3563c7d953bb0b679ca10c14
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 31 00:32:43 2011 +0800

    test warning when setting a feild from null to not-null

diff --git a/t/02records_integers.t b/t/02records_integers.t
index 5cf3e1c..d13e2ee 100644
--- a/t/02records_integers.t
+++ b/t/02records_integers.t
@@ -6,7 +6,7 @@ use Test::More;
 BEGIN { require "t/utils.pl" }
 our (@AvailableDrivers);
 
-use constant TESTS_PER_DRIVER => 36;
+use constant TESTS_PER_DRIVER => 37;
 
 my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -67,9 +67,17 @@ SKIP: {
         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');
+        {
+            my $warn;
+            local $SIG{__WARN__} = sub {
+                $warn++;
+                warn @_;
+            };
+            $status = $rec->SetOptional('');
+            ok( $status, "status ok" ) or diag $status->error_message;
+            is( $rec->Optional, 0, 'empty string should be threated as zero' );
+            ok( !$warn, 'no warning to set value from null to not-null' );
+        }
 
         $status = $rec->SetOptional;
         ok($status, "status ok") or diag $status->error_message;

commit 86adcad23ceb5e57fd94fe457769f5836e859ad8
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 31 01:33:51 2011 +0800

    return error directly if set undef to a NOT NULL field which lacks DEFAULT

diff --git a/lib/DBIx/SearchBuilder/Record.pm b/lib/DBIx/SearchBuilder/Record.pm
index 57bd3fa..26fa0b7 100755
--- a/lib/DBIx/SearchBuilder/Record.pm
+++ b/lib/DBIx/SearchBuilder/Record.pm
@@ -783,7 +783,20 @@ sub __Set {
     }
     else {
         if ( $self->_Accessible( $args{Column}, 'no_nulls' ) ) {
-            $args{'Value'} = $self->_Accessible( $args{Column}, 'default' );
+            my $default = $self->_Accessible( $args{Column}, 'default' );
+
+            if ( defined $default ) {
+                $args{'Value'} = $default;
+            }
+            else {
+                $ret->as_array( 0, 'Illegal value for ' . $args{'Column'} );
+                $ret->as_error(
+                    errno        => 3,
+                    do_backtrace => 0,
+                    message      => "Illegal value for " . $args{'Column'}
+                );
+                return ( $ret->return_value );
+            }
         }
     }
 

commit 2b613bb8fbd41ac1b7cb7760953d6a7e162382d1
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 31 01:39:08 2011 +0800

    20set_edge_cases for more edge case tests
    
    test of setting undef/empty string to a NOT NULL field without DEFAULT

diff --git a/t/20set_edge_cases.t b/t/20set_edge_cases.t
new file mode 100644
index 0000000..39476d0
--- /dev/null
+++ b/t/20set_edge_cases.t
@@ -0,0 +1,141 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Test::More;
+BEGIN { require "t/utils.pl" }
+our (@AvailableDrivers);
+
+use constant TESTS_PER_DRIVER => 20;
+
+my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
+plan tests => $total;
+
+foreach my $d (@AvailableDrivers) {
+  SKIP: {
+        unless ( has_schema( 'TestApp::Address', $d ) ) {
+            skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+        }
+        unless ( should_test($d) ) {
+            skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+        }
+
+        my $handle = get_handle($d);
+        connect_handle($handle);
+        isa_ok( $handle->dbh, 'DBI::db' );
+
+        my $ret = init_schema( 'TestApp::Address', $handle );
+        isa_ok( $ret, 'DBI::st',
+            "Inserted the schema. got a statement handle back" );
+
+        my $rec = TestApp::Address->new($handle);
+        my ($id) = $rec->Create( Name => 'foo', Number => 3 );
+        ok( $id,             "Created record " . $id );
+        ok( $rec->Load($id), "Loaded the record" );
+
+        is( $rec->Name,   'foo', "name is foo" );
+        is( $rec->Number, 3,     "number is 3" );
+
+        my ( $val, $msg ) = $rec->SetName('bar');
+        ok( $val, $msg );
+        is( $rec->Name, 'bar', "name is changed to bar" );
+
+        ( $val, $msg ) = $rec->SetName(undef);
+        ok( !$val, $msg );
+        is( $msg, 'Illegal value for Name', 'error message' );
+        is( $rec->Name, 'bar', 'name is still bar' );
+
+        ( $val, $msg ) = $rec->SetName('');
+        ok( $val, $msg );
+        is( $rec->Name, '', "name is changed to ''" );
+
+        ( $val, $msg ) = $rec->SetNumber(42);
+        ok( $val, $msg );
+        is( $rec->Number, 42, 'number is changed to 42' );
+
+        ( $val, $msg ) = $rec->SetNumber(undef);
+        ok( !$val, $msg );
+        is( $msg, 'Illegal value for Number', 'error message' );
+        is( $rec->Number, 42, 'number is still 42' );
+
+        ( $val, $msg ) = $rec->SetNumber('');
+        ok( $val, $msg );
+        is( $rec->Number, 0, 'empty string implies 0 for integer field' );
+
+        cleanup_schema( 'TestApp::Address', $handle );
+    }
+}
+
+1;
+
+package TestApp::Address;
+
+use base $ENV{SB_TEST_CACHABLE}
+  ? qw/DBIx::SearchBuilder::Record::Cachable/
+  : qw/DBIx::SearchBuilder::Record/;
+
+sub _Init {
+    my $self   = shift;
+    my $handle = shift;
+    $self->Table('Address');
+    $self->_Handle($handle);
+}
+
+sub _ClassAccessible {
+
+    {
+        id     => { read => 1, type  => 'int(11)', },
+        Name   => { read => 1, write => 1, type => 'varchar(14)', no_nulls => 1 },
+        Number => { read => 1, write => 1, type => 'int(8)', no_nulls => 1 },
+    };
+}
+
+sub schema_mysql {
+    <<EOF;
+CREATE TEMPORARY TABLE Address (
+        id integer AUTO_INCREMENT,
+        Name varchar(36) NOT NULL,
+        Number int(8) NOT NULL,
+  	PRIMARY KEY (id))
+EOF
+
+}
+
+sub schema_pg {
+    <<EOF;
+CREATE TEMPORARY TABLE Address (
+        id serial PRIMARY KEY,
+        Name varchar(36) NOT NULL,
+        Number integer NOT NULL
+)
+EOF
+
+}
+
+sub schema_sqlite {
+
+    <<EOF;
+CREATE TABLE Address (
+        id  integer primary key,
+        Name varchar(36) NOT NULL,
+        Number int(8) NOT NULL)
+EOF
+
+}
+
+sub schema_oracle {
+    [
+        "CREATE SEQUENCE Address_seq",
+        "CREATE TABLE Address (
+        id integer CONSTRAINT Address_Key PRIMARY KEY,
+        Name varchar(36) NOT NULL,
+        Number integer NOT NULL
+        )",
+    ];
+}
+
+sub cleanup_schema_oracle {
+    [ "DROP SEQUENCE Address_seq", "DROP TABLE Address", ];
+}
+
+1;

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



More information about the Bps-public-commit mailing list