From: Rafael Kitover Date: Mon, 17 Jan 2011 09:26:36 +0000 (-0500) Subject: add datetime_undef_if_invalid=0 loader option for MySQL X-Git-Tag: 0.07003~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=57a9fc92e7f892fa0bf37a537ec835000d087c85;p=dbsrgits%2FDBIx-Class-Schema-Loader.git add datetime_undef_if_invalid=0 loader option for MySQL --- diff --git a/Changes b/Changes index 5d656ba..23585d9 100644 --- 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) diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 84cffc0..66847c3 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -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 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 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 diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index 8946c99..099254e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -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; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index 83a9387..95e5e14 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -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 ''