From: Wallace Reis Date: Wed, 23 Jul 2014 22:56:28 +0000 (-0300) Subject: Produce DDL for MySQL table field with ref in 'ON UPDATE' X-Git-Tag: v0.11019~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1fb4f40fa5d6b158b7241b01c41be3e2c1d8edad;p=dbsrgits%2FSQL-Translator.git Produce DDL for MySQL table field with ref in 'ON UPDATE' --- diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index 356f4b6..6ebaf9d 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -606,7 +606,12 @@ sub create_field } for my $qual ( 'character set', 'collate', 'on update' ) { my $val = $extra{ $qual } || $extra{ uc $qual } or next; - $field_def .= " $qual $val"; + if ( ref $val ) { + $field_def .= " $qual ${$val}"; + } + else { + $field_def .= " $qual $val"; + } } # Null? diff --git a/t/38-mysql-producer.t b/t/38-mysql-producer.t index 57b04d1..0e3f9c6 100644 --- a/t/38-mysql-producer.t +++ b/t/38-mysql-producer.t @@ -67,6 +67,20 @@ schema: mysql_charset: utf8 mysql_collate: utf8_general_ci order: 4 + timestamp: + data_type: timestamp + default_value: !!perl/ref + =: CURRENT_TIMESTAMP + extra: + on update: !!perl/ref + =: CURRENT_TIMESTAMP + is_nullable: 1 + is_primary_key: 0 + is_unique: 0 + name: timestamp + order: 5 + size: + - 0 constraints: - type: UNIQUE fields: @@ -191,6 +205,7 @@ my @stmts = ( `name` varchar(32) NULL, `swedish_name` varchar(32) character set swe7 NULL, `description` text character set utf8 collate utf8_general_ci NULL, + `timestamp` timestamp on update CURRENT_TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE `idx_unique_name` (`name`) ) ENGINE=InnoDB DEFAULT CHARACTER SET latin1 COLLATE latin1_danish_ci",