From: Rafael Kitover Date: Tue, 24 Nov 2009 12:57:25 +0000 (+0000) Subject: fix MSSQL default detection to work with numeric/integer columns X-Git-Tag: 0.04999_11~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f625792d3d7d77d23ca7db1fcc320bd977ad389;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix MSSQL default detection to work with numeric/integer columns --- diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 659391b..3ffa38d 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -416,6 +416,8 @@ TSUNODA Kazuya Robert Bohne +ribasushi: Peter Rabbitson + ... and lots of other folks. If we forgot you, please write the current maintainer or RT. diff --git a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm index 82f7af7..fc93a1c 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm @@ -143,9 +143,10 @@ sub _extra_column_info { # strip parens $default =~ s/^\( (.*) \)\z/$1/x; - # literal or function? + # Literal strings are in ''s, numbers are in ()s, everything else is a + # function. $extra_info{default_value} = - $default =~ /^' (.*) '\z/x ? $1 : \$default; + $default =~ /^['(] (.*) [)']\z/x ? $1 : \$default; } return \%extra_info; diff --git a/t/lib/dbixcsl_mssql_extra_tests.pm b/t/lib/dbixcsl_mssql_extra_tests.pm index 4319db8..ea38461 100644 --- a/t/lib/dbixcsl_mssql_extra_tests.pm +++ b/t/lib/dbixcsl_mssql_extra_tests.pm @@ -21,12 +21,14 @@ sub extra { +{ CREATE TABLE ${vendor}_loader_test2 ( id INT IDENTITY NOT NULL PRIMARY KEY, dat VARCHAR(100) DEFAULT 'foo', + num NUMERIC DEFAULT 10.89, + anint INT DEFAULT 6, ts DATETIME DEFAULT getdate() ) }, ], drop => [ "[${vendor}_loader_test1.dot]", "${vendor}_loader_test2" ], - count => 11, + count => 13, run => sub { my ($schema, $monikers, $classes) = @_; @@ -53,7 +55,14 @@ sub extra { +{ my $rsrc = $rs->result_source; is eval { $rsrc->column_info('dat')->{default_value} }, 'foo', - 'correct default_value for column with literal default'; + 'correct default_value for column with literal string default'; + + is eval { $rsrc->column_info('anint')->{default_value} }, 6, + 'correct default_value for column with literal integer default'; + + cmp_ok eval { $rsrc->column_info('num')->{default_value} }, + '==', 10.89, + 'correct default_value for column with literal numeric default'; ok((my $function_default = eval { $rsrc->column_info('ts')->{default_value} }),