Remove copyright headers from individual scripts
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer.pm
index c80d804..8680f42 100644 (file)
@@ -1,25 +1,8 @@
 package SQL::Translator::Producer;
 
-# -------------------------------------------------------------------
-# Copyright (C) 2002-4 SQLFairy Authors
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; version 2.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307  USA
-# -------------------------------------------------------------------
-
 use strict;
 use vars qw($VERSION);
+use Scalar::Util ();
 $VERSION = '1.59';
 
 sub produce { "" }
@@ -32,7 +15,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) {
@@ -47,8 +32,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'";
   }
@@ -100,6 +91,8 @@ by the parser.  It is expected to return a string.
 
 =item drop_field($table, $old_field)
 
+=back
+
 =head1 AUTHORS
 
 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,