add datetime_undef_if_invalid=0 loader option for MySQL
Rafael Kitover [Mon, 17 Jan 2011 09:26:36 +0000 (04:26 -0500)]
Changes
lib/DBIx/Class/Schema/Loader/Base.pm
lib/DBIx/Class/Schema/Loader/DBI.pm
lib/DBIx/Class/Schema/Loader/DBI/mysql.pm

diff --git a/Changes b/Changes
index 5d656ba..23585d9 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,7 +1,8 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
         - add datetime_undef_if_invalid => 1 for MySQL datetime data types
-          (RT#64820)
+          (RT#64820) This behavior can be turned off by passing
+          datetime_undef_if_invalid=0 as a loader option
         - added column_accessor_map option
         - Preserve relationship names when redumping and another FK is added
           (RT#62424)
index 84cffc0..66847c3 100644 (file)
@@ -86,6 +86,7 @@ __PACKAGE__->mk_group_accessors('simple', qw/
                                 preserve_case
                                 col_collision_map
                                 real_dump_directory
+                                datetime_undef_if_invalid
 /);
 
 =head1 NAME
@@ -459,6 +460,15 @@ columns with the DATE/DATETIME/TIMESTAMP data_types.
 Sets the locale attribute for L<DBIx::Class::InflateColumn::DateTime> for all
 columns with the DATE/DATETIME/TIMESTAMP data_types.
 
+=head2 datetime_undef_if_invalid
+
+Pass a C<0> for this option when using MySQL if you B<DON'T> want C<<
+datetime_undef_if_invalid => 1 >> in your column info for DATE, DATETIME and
+TIMESTAMP columns.
+
+The default is recommended to deal with data such as C<00/00/00> which
+sometimes ends up in such columns in MySQL.
+
 =head2 config_file
 
 File in Perl format, which should return a HASH reference, from which to read
index 8946c99..099254e 100644 (file)
@@ -328,7 +328,7 @@ sub _columns_info_for {
 
     for my $i (0 .. $#columns) {
         my $column_info = {};
-        $column_info->{data_type} = lc $sth->{TYPE}->[$i];
+        $column_info->{data_type} = lc $sth->{TYPE}[$i];
 
         my $size = $sth->{PRECISION}[$i];
 
@@ -339,7 +339,7 @@ sub _columns_info_for {
             $column_info->{size} = $size;
         }
 
-        $column_info->{is_nullable} = $sth->{NULLABLE}->[$i] ? 1 : 0;
+        $column_info->{is_nullable} = $sth->{NULLABLE}[$i] ? 1 : 0;
 
         if ($column_info->{data_type} =~ m/^(.*?)\((.*?)\)$/) {
             $column_info->{data_type} = $1;
index 83a9387..95e5e14 100644 (file)
@@ -177,7 +177,9 @@ EOF
             }
         }
         elsif ($info->{data_type} =~ /^(?:date(?:time)?|timestamp)\z/) {
-            $info->{datetime_undef_if_invalid} = 1;
+            if (not (defined $self->datetime_undef_if_invalid && $self->datetime_undef_if_invalid == 0)) {
+                $info->{datetime_undef_if_invalid} = 1;
+            }
         }
 
         # Sometimes apparently there's a bug where default_value gets set to ''