check for "CURRENT_TIMESTAMP" only for "TIMESTAMP" columns in MySQL
Rafael Kitover [Sun, 17 Jan 2010 14:19:21 +0000 (14:19 +0000)]
lib/DBIx/Class/Schema/Loader/DBI/mysql.pm
t/11mysql_common.t

index c70ff8d..bc55273 100644 (file)
@@ -129,9 +129,9 @@ sub _extra_column_info {
     if ($info->{mysql_values}) {
         $extra_info{extra}{list} = $info->{mysql_values};
     }
-# XXX we need to distinguish between DEFAULT CURRENT_TIMESTAMP and DEFAULT 'foo'
-# somehow, but DBI column_info doesn't preserve quotes.
-    if ($info->{COLUMN_DEF} =~ /^CURRENT_TIMESTAMP\z/i) {
+    if (   $info->{COLUMN_DEF}      =~ /^CURRENT_TIMESTAMP\z/i
+        && $info->{mysql_type_name} =~ /^TIMESTAMP\z/i) {
+
         $extra_info{default_value} = \'CURRENT_TIMESTAMP';
     }
 
index 151009f..0da0e39 100644 (file)
@@ -32,8 +32,7 @@ my $tester = dbixcsl_common_tests->new(
             qq{
                 CREATE TABLE mysql_loader_test2 (
                   id INTEGER UNSIGNED NOT NULL PRIMARY KEY,
-                  somedate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-                  somestr VARCHAR(100) NOT NULL DEFAULT 'foo'
+                  somets TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
                 )
             },
         ],
@@ -54,7 +53,7 @@ my $tester = dbixcsl_common_tests->new(
                       'MySQL ENUM values');
 
             $rs = $schema->resultset($monikers->{mysql_loader_test2});
-            $column_info = $rs->result_source->column_info('somedate');
+            $column_info = $rs->result_source->column_info('somets');
             my $default  = $column_info->{default_value};
             ok ((ref($default) eq 'SCALAR'),
                 'CURRENT_TIMESTAMP default_value is a scalar ref');