X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer.pm;h=9119da62fd026f13de157af25b896d0d1a8aa188;hb=2c098ea52043fbe391283b71c1f4a74e65a29ed0;hp=a7081c0d23cacfb797d80e457f472bf75828e4b7;hpb=821a0fde221f5accf93e3f65efa77b5a6733cb5e;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Producer.pm b/lib/SQL/Translator/Producer.pm index a7081c0..9119da6 100644 --- a/lib/SQL/Translator/Producer.pm +++ b/lib/SQL/Translator/Producer.pm @@ -1,8 +1,6 @@ package SQL::Translator::Producer; # ------------------------------------------------------------------- -# $Id$ -# ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # # This program is free software; you can redistribute it and/or @@ -22,7 +20,8 @@ package SQL::Translator::Producer; use strict; use vars qw($VERSION); -$VERSION = sprintf "%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/; +use Scalar::Util (); +$VERSION = '1.59'; sub produce { "" } @@ -34,7 +33,9 @@ sub produce { "" } ## They are special per Producer, and provide support for the old 'now()' ## default value exceptions sub _apply_default_value { - my (undef, $field_ref, $default, $exceptions) = @_; + my (undef, $field, $field_ref, $exceptions) = @_; + my $default = $field->default_value; + return if !defined $default; if ($exceptions and ! ref $default) { for (my $i = 0; $i < @$exceptions; $i += 2) { @@ -49,8 +50,14 @@ sub _apply_default_value { } } + my $type = lc $field->data_type; + my $is_numeric_datatype = ($type =~ /^(?:(?:big|medium|small|tiny)?int(?:eger)?|decimal|double|float|num(?:ber|eric)?|real)$/); + if (ref $default) { $$field_ref .= " DEFAULT $$default"; + } elsif ($is_numeric_datatype && Scalar::Util::looks_like_number ($default) ) { + # we need to check the data itself in addition to the datatype, for basic safety + $$field_ref .= " DEFAULT $default"; } else { $$field_ref .= " DEFAULT '$default'"; } @@ -102,6 +109,8 @@ by the parser. It is expected to return a string. =item drop_field($table, $old_field) +=back + =head1 AUTHORS Darren Chamberlain Edarren@cpan.orgE,