From: Allen Day Date: Thu, 17 Apr 2003 19:42:33 +0000 (+0000) Subject: workaround to get auto_increment working from PG "serial" datatype. i didn't do... X-Git-Tag: v0.02~188 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0a7fc6058c58b73312f62d64060bec8d84c64dc3;p=dbsrgits%2FSQL-Translator.git workaround to get auto_increment working from PG "serial" datatype. i didn't do this right, someone fix it :| also added a fix to MySQL producer to not put () enclosed attributes if values don't exist. ie, don't put int() if there is not a length defined for int. --- diff --git a/lib/SQL/Translator/Parser/PostgreSQL.pm b/lib/SQL/Translator/Parser/PostgreSQL.pm index ccc6710..bd9601b 100644 --- a/lib/SQL/Translator/Parser/PostgreSQL.pm +++ b/lib/SQL/Translator/Parser/PostgreSQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::PostgreSQL; # ------------------------------------------------------------------- -# $Id: PostgreSQL.pm,v 1.10 2003-04-02 01:46:16 kycl4rk Exp $ +# $Id: PostgreSQL.pm,v 1.11 2003-04-17 19:42:33 allenday Exp $ # ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark , # Allen Day , @@ -107,7 +107,7 @@ Alter table: use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.11 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -276,7 +276,7 @@ field : comment(s?) field_name data_type field_meta(s?) comment(s?) my @comments = ( @{ $item[1] }, @{ $item[5] } ); - $return = { + $return = { type => 'field', name => $item{'field_name'}, data_type => $item{'data_type'}{'type'}, @@ -377,7 +377,7 @@ data_type : pg_data_type parens_value_list(?) } pg_data_type : - /(bigint|int8|bigserial|serial8)/ { $return = [ 'integer', 8 ] } + /(bigint|int8|bigserial|serial8)/ { $return = [ 'integer(8) auto_increment'] } | /(smallint|int2)/ { $return = [ 'integer', 2 ] } | @@ -387,9 +387,9 @@ pg_data_type : | /(real|float4)/ { $return = [ 'real', 4 ] } | - /serial4?/ { $return = [ 'serial', 4 ] } + /serial4?/ { $return = [ 'integer(4) auto_increment'] } | - /bigserial/ { $return = [ 'serial', 8 ] } + /bigserial/ { $return = [ 'integer(8) auto_increment'] } | /(bit varying|varbit)/ { $return = 'varbit' } | @@ -596,7 +596,7 @@ sub parse { =head1 AUTHORS Ken Y. Clark Ekclark@cpan.orgE, -Allen Day . +Allen Day . =head1 SEE ALSO diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index 549378b..bdda0cb 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer::MySQL; # ------------------------------------------------------------------- -# $Id: MySQL.pm,v 1.13 2003-04-17 13:42:45 dlc Exp $ +# $Id: MySQL.pm,v 1.14 2003-04-17 19:42:33 allenday Exp $ # ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark , # darren chamberlain , @@ -24,7 +24,7 @@ package SQL::Translator::Producer::MySQL; use strict; use vars qw[ $VERSION $DEBUG ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -113,9 +113,9 @@ sub produce { $data_type = $translate{ $data_type }; } - push @fdata, sprintf "%s%s", + push @fdata, sprintf "%s%s", $data_type, - ( @values ) + defined( $values[0] ) ? '(' . join( ', ', @values ) . ')' : '';