- Ross Smith II <rossta@users.sf.net>
- Ryan D Johnson <ryan@innerfence.com>
- Sam Angiuoli <angiuoli@users.sourceforge.net>
+- Stephen Clouse <stephenclouse@gmail.com>
- Wallace Reis <wreis@cpan.org>
- Ying Zhang <zyolive@yahoo.com>
* Fix Producer::MySQL wrapping extra ()s around VIEW SELECT-ors (RT#56419)
* Fix Field::default_value to behave like a real accessor (allow undef as
an unsetting argument)
+* Fix Mysql/Pg/SQLite/MSSQL producers to properly *not* quote numeric default
+ values (RT#57059)
* Producer::Oracle tests now use Test::Differences
* Prettify output of SQLite producer (less bogus newlines)
* Augment SQLite and Pg producers to accept a perl-formatted (%d.%03d%03d)
{ $return = 'null' }
| /default/i /'[^']*'/
{ $item[2]=~ s/'//g; $return = $item[2] }
+ | /default/i WORD
+ { $return = $item[2] }
auto_inc : /identity/i { 1 }
use strict;
use vars qw($VERSION);
+use Scalar::Util ();
$VERSION = '1.59';
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) {
}
}
+ 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'";
}
# Null?
$field_def .= ' NOT NULL' unless $field->is_nullable;
- # Default? XXX Need better quoting!
- my $default = $field->default_value;
- if ( defined $default ) {
- SQL::Translator::Producer->_apply_default_value(
- \$field_def,
- $default,
- [
- 'NULL' => \'NULL',
- ],
- );
- }
+ # Default?
+ SQL::Translator::Producer->_apply_default_value(
+ $field,
+ \$field_def,
+ [
+ 'NULL' => \'NULL',
+ ],
+ );
if ( my $comments = $field->comments ) {
$field_def .= qq[ comment '$comments'];
#
# Default value
#
- my $default = $field->default_value;
- if ( defined $default ) {
- SQL::Translator::Producer->_apply_default_value(
- \$field_def,
- $default,
- [
- 'NULL' => \'NULL',
- 'now()' => 'now()',
- 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
- ],
- );
- }
+ SQL::Translator::Producer->_apply_default_value(
+ $field,
+ \$field_def,
+ [
+ 'NULL' => \'NULL',
+ 'now()' => 'now()',
+ 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
+ ],
+ );
#
# Not null constraint
#
# Default value
#
- my $default = $field->default_value;
- if ( defined $default ) {
- SQL::Translator::Producer->_apply_default_value(
- \$field_def,
- $default,
- [
- 'NULL' => \'NULL',
- ],
- );
- }
+ SQL::Translator::Producer->_apply_default_value(
+ $field,
+ \$field_def,
+ [
+ 'NULL' => \'NULL',
+ ],
+ );
push @field_defs, $field_def;
}
# Null?
$field_def .= ' NOT NULL' unless $field->is_nullable;
- # Default? XXX Need better quoting!
- my $default = $field->default_value;
- if (defined $default) {
- SQL::Translator::Producer->_apply_default_value(
- \$field_def,
- $default,
- [
- 'NULL' => \'NULL',
- 'now()' => 'now()',
- 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
- ],
- );
- }
+ # Default?
+ SQL::Translator::Producer->_apply_default_value(
+ $field,
+ \$field_def,
+ [
+ 'NULL' => \'NULL',
+ 'now()' => 'now()',
+ 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
+ ],
+ );
return $field_def;
ALTER TABLE new_name ADD COLUMN new_field integer;
-ALTER TABLE person ADD COLUMN is_rock_star tinyint(4) DEFAULT '1';
+ALTER TABLE person ADD COLUMN is_rock_star tinyint(4) DEFAULT 1;
ALTER TABLE person CHANGE COLUMN person_id person_id integer(11) NOT NULL auto_increment;
ALTER TABLE person CHANGE COLUMN name name varchar(20) NOT NULL;
-ALTER TABLE person CHANGE COLUMN age age integer(11) DEFAULT '18';
+ALTER TABLE person CHANGE COLUMN age age integer(11) DEFAULT 18;
-ALTER TABLE person CHANGE COLUMN iq iq integer(11) DEFAULT '0';
+ALTER TABLE person CHANGE COLUMN iq iq integer(11) DEFAULT 0;
ALTER TABLE person CHANGE COLUMN description physical_description text;
ADD COLUMN new_field integer;
ALTER TABLE person DROP INDEX UC_age_name,
- ADD COLUMN is_rock_star tinyint(4) DEFAULT '1',
+ ADD COLUMN is_rock_star tinyint(4) DEFAULT 1,
CHANGE COLUMN person_id person_id integer(11) NOT NULL auto_increment,
CHANGE COLUMN name name varchar(20) NOT NULL,
- CHANGE COLUMN age age integer(11) DEFAULT '18',
- CHANGE COLUMN iq iq integer(11) DEFAULT '0',
+ CHANGE COLUMN age age integer(11) DEFAULT 18,
+ CHANGE COLUMN iq iq integer(11) DEFAULT 0,
CHANGE COLUMN description physical_description text,
ADD UNIQUE UC_person_id (person_id),
ADD UNIQUE UC_age_name (age, name),
ALTER TABLE person DROP INDEX UC_age_name,
DROP INDEX u_name,
- ADD COLUMN is_rock_star tinyint(4) DEFAULT '1',
+ ADD COLUMN is_rock_star tinyint(4) DEFAULT 1,
CHANGE COLUMN person_id person_id integer(11) NOT NULL auto_increment,
CHANGE COLUMN name name varchar(20) NOT NULL,
- CHANGE COLUMN age age integer(11) DEFAULT '18',
- CHANGE COLUMN iq iq integer(11) DEFAULT '0',
+ CHANGE COLUMN age age integer(11) DEFAULT 18,
+ CHANGE COLUMN iq iq integer(11) DEFAULT 0,
CHANGE COLUMN description physical_description text,
ADD UNIQUE INDEX unique_name (name),
ADD UNIQUE UC_person_id (person_id),
ALTER TABLE new_name ADD COLUMN new_field integer;
-ALTER TABLE person ADD COLUMN is_rock_star smallint DEFAULT '1';
+ALTER TABLE person ADD COLUMN is_rock_star smallint DEFAULT 1;
ALTER TABLE person ALTER COLUMN person_id TYPE serial;
ALTER TABLE new_name ADD COLUMN new_field integer;
-ALTER TABLE person ADD COLUMN is_rock_star smallint DEFAULT '1';
+ALTER TABLE person ADD COLUMN is_rock_star smallint DEFAULT 1;
ALTER TABLE person ALTER COLUMN person_id TYPE serial;
ALTER TABLE new_name ADD COLUMN new_field int;
-ALTER TABLE person ADD COLUMN is_rock_star tinyint(4) DEFAULT '1';
+ALTER TABLE person ADD COLUMN is_rock_star tinyint(4) DEFAULT 1;
-- SQL::Translator::Producer::SQLite cant alter_field;
CREATE TEMPORARY TABLE person_temp_alter (
person_id INTEGER PRIMARY KEY NOT NULL,
name varchar(20) NOT NULL,
- age int(11) DEFAULT '18',
+ age int(11) DEFAULT 18,
weight double(11,2),
- iq int(11) DEFAULT '0',
- is_rock_star tinyint(4) DEFAULT '1',
+ iq int(11) DEFAULT 0,
+ is_rock_star tinyint(4) DEFAULT 1,
physical_description text
);
CREATE TABLE person (
person_id INTEGER PRIMARY KEY NOT NULL,
name varchar(20) NOT NULL,
- age int(11) DEFAULT '18',
+ age int(11) DEFAULT 18,
weight double(11,2),
- iq int(11) DEFAULT '0',
- is_rock_star tinyint(4) DEFAULT '1',
+ iq int(11) DEFAULT 0,
+ is_rock_star tinyint(4) DEFAULT 1,
physical_description text
);
"explicitemptystring" character varying DEFAULT '',
-- Hello emptytagdef
"emptytagdef" character varying DEFAULT '',
- "another_id" integer DEFAULT '2',
+ "another_id" integer DEFAULT 2,
"timest" timestamp,
PRIMARY KEY ("id"),
CONSTRAINT "emailuniqueindex" UNIQUE ("email"),
explicitemptystring varchar DEFAULT '',
-- Hello emptytagdef
emptytagdef varchar DEFAULT '',
- another_id int(10) DEFAULT '2',
+ another_id int(10) DEFAULT 2,
timest timestamp
);
explicitemptystring varchar DEFAULT \'\',
-- Hello emptytagdef
emptytagdef varchar DEFAULT \'\',
- another_id int(10) DEFAULT \'2\',
+ another_id int(10) DEFAULT 2,
timest timestamp
)',
'CREATE INDEX titleindex ON Basic (title)',