From: Rafael Kitover Date: Mon, 10 May 2010 21:53:02 +0000 (-0400) Subject: add ->{original}{default_value} when rewriting to current_timestamp X-Git-Tag: 0.07000~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=701cd3e37c8b4119cf43454d22766c1196377a3c;p=dbsrgits%2FDBIx-Class-Schema-Loader.git add ->{original}{default_value} when rewriting to current_timestamp --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm index 0be5f1a..2d36a15 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm @@ -133,6 +133,9 @@ sub _columns_info_for { if ((eval { lc ${ $info->{default_value} } }||'') eq 'current timestamp') { ${ $info->{default_value} } = 'current_timestamp'; delete $info->{size}; + + my $orig_deflt = 'current timestamp'; + $info->{original}{default_value} = \$orig_deflt; } } diff --git a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm index ee6d18a..5cfeb26 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm @@ -278,6 +278,9 @@ wHERE table_name = @{[ $dbh->quote($table) ]} AND column_name = @{[ $dbh->quote( if ((eval { lc ${ $info->{default_value} } }||'') eq 'getdate()') { ${ $info->{default_value} } = 'current_timestamp'; + + my $getdate = 'getdate()'; + $info->{original}{default_value} = \$getdate; } } } diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm index 1bfb32b..2f26240 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm @@ -232,10 +232,11 @@ AND upper(trigger_type) LIKE '%BEFORE EACH ROW%' AND lower(triggering_event) LIK } if ((eval { lc(${ $info->{default_value} }) }||'') eq 'sysdate') { - $info->{original}{default_value} = $info->{default_value}; - my $current_timestamp = 'current_timestamp'; $info->{default_value} = \$current_timestamp; + + my $sysdate = 'sysdate'; + $info->{original}{default_value} = \$sysdate; } } diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index 52c7489..e92fbaf 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -231,6 +231,9 @@ EOF if ((eval { lc ${ $info->{default_value} } }||'') eq 'now()') { # do not use a ref to a constant, that breaks Data::Dump output ${$info->{default_value}} = 'current_timestamp'; + + my $now = 'now()'; + $info->{original}{default_value} = \$now; } } diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm index 00fa615..9f68103 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm @@ -107,6 +107,9 @@ EOF if ((eval { lc ${ $info->{default_value} } }||'') eq 'current timestamp') { ${ $info->{default_value} } = 'current_timestamp'; + + my $orig_deflt = 'current timestamp'; + $info->{original}{default_value} = \$orig_deflt; } } diff --git a/t/12pg_common.t b/t/12pg_common.t index 7d4f5ab..e70e914 100644 --- a/t/12pg_common.t +++ b/t/12pg_common.t @@ -95,8 +95,9 @@ my $tester = dbixcsl_common_tests->new( 'time with time zone' => { data_type => 'time with time zone' }, 'time(2) with time zone' => { data_type => 'time with time zone', size => 2 }, timestamp => { data_type => 'timestamp' }, - 'timestamp default current_timestamp' - => { data_type => 'timestamp', default_value => \'current_timestamp' }, + 'timestamp default now()' + => { data_type => 'timestamp', default_value => \'current_timestamp', + original => { default_value => \'now()' } }, 'timestamp(2)' => { data_type => 'timestamp', size => 2 }, 'timestamp without time zone' => { data_type => 'timestamp' }, 'timestamp(2) without time zone' => { data_type => 'timestamp', size => 2 }, diff --git a/t/13db2_common.t b/t/13db2_common.t index 4cbb7fd..6d41caa 100644 --- a/t/13db2_common.t +++ b/t/13db2_common.t @@ -14,7 +14,8 @@ my $tester = dbixcsl_common_tests->new( password => $password, null => '', data_types => { - 'timestamp DEFAULT CURRENT TIMESTAMP' => { data_type => 'timestamp', default_value => \'current_timestamp' } + 'timestamp DEFAULT CURRENT TIMESTAMP' => { data_type => 'timestamp', default_value => \'current_timestamp', + original => { default_value => \'current timestamp' } }, }, ); diff --git a/t/16mssql_common.t b/t/16mssql_common.t index 93c6e00..97ddc1c 100644 --- a/t/16mssql_common.t +++ b/t/16mssql_common.t @@ -69,7 +69,8 @@ my $tester = dbixcsl_common_tests->new( datetime => { data_type => 'datetime' }, # test rewriting getdate() to current_timestamp 'datetime default getdate()' - => { data_type => 'datetime', default_value => \'current_timestamp' }, + => { data_type => 'datetime', default_value => \'current_timestamp', + original => { default_value => \'getdate()' } }, smalldatetime => { data_type => 'smalldatetime' }, time => { data_type => 'time' }, 'time(0)'=> { data_type => 'time', size => 0 }, diff --git a/t/17sybase_asa_common.t b/t/17sybase_asa_common.t index 0b7a241..ef81520 100644 --- a/t/17sybase_asa_common.t +++ b/t/17sybase_asa_common.t @@ -94,7 +94,8 @@ my $tester = dbixcsl_common_tests->new( 'timestamp' => { data_type => 'timestamp' }, # rewrite 'current timestamp' as 'current_timestamp' 'timestamp default current timestamp' - => { data_type => 'timestamp', default_value => \'current_timestamp' }, + => { data_type => 'timestamp', default_value => \'current_timestamp', + original => { default_value => \'current timestamp' } }, 'time' => { data_type => 'time' }, # String Types @@ -138,3 +139,4 @@ if (not ($dbd_sqlanywhere_dsn || $odbc_dsn)) { else { $tester->run_tests(); } +# vim:et sts=4 sw=4 tw=0: