From: Ben Faga Date: Mon, 4 Jun 2007 04:01:14 +0000 (+0000) Subject: Committing patches sent by Florian Helmberger. Here are his remarks: X-Git-Tag: v0.11008~360 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7ed7402c72e81504c8acd4f1bba4837dc69390f0;p=dbsrgits%2FSQL-Translator.git Committing patches sent by Florian Helmberger. Here are his remarks: Here are two patches for a few bugs in the PostgreSQL parser and producer. The patch for lib/SQL/Translator/Parser/DBI/PostgreSQL.pm fixes a simple typo which resulted in the complete absence of the field types and corrects the way is_nullable is set so the producer now correctly flags NOT NULL fields. The patch for lib/SQL/Translator/Producer/PostgreSQL.pm adds missing newlines to the last line of the 'Table:' and 'Comments:' headers. Also it fixes an 'use of uninizialised value' warning in 359. Before the patch the output for command sqlt --from DBI --dsn dbi:Pg:dbname=testdb --to PostgreSQL \ --db-user postgres looked like: ==== -- -- Table: mailaliases --CREATE TABLE "mailaliases" ( "aliasname" (204), "aliasto" (204), "domain" (132), "id" , "isdefault" , "datecreate" , Constraint "foo" UNIQUE ("isdefault") ); ==== After the patch it looks like: ==== -- -- Table: mailaliases -- CREATE TABLE "mailaliases" ( "aliasname" character varying(204), "aliasto" character varying(204), "domain" character varying(132), "id" int4 NOT NULL, "isdefault" int4, "datecreate" text, Constraint "foo" UNIQUE ("isdefault") ); ==== --- diff --git a/lib/SQL/Translator/Parser/DBI/PostgreSQL.pm b/lib/SQL/Translator/Parser/DBI/PostgreSQL.pm index 142b9b1..77cc727 100644 --- a/lib/SQL/Translator/Parser/DBI/PostgreSQL.pm +++ b/lib/SQL/Translator/Parser/DBI/PostgreSQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::DBI::PostgreSQL; # ------------------------------------------------------------------- -# $Id: PostgreSQL.pm,v 1.9 2005-10-07 16:26:41 scottcain Exp $ +# $Id: PostgreSQL.pm,v 1.10 2007-06-04 04:01:14 mwz444 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -40,7 +40,7 @@ use Data::Dumper; use SQL::Translator::Schema::Constants; use vars qw[ $DEBUG $VERSION @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; # ------------------------------------------------------------------- @@ -94,12 +94,12 @@ sub parse { my $col = $table->add_field( name => $$columnhash{'attname'}, default_value => $$columnhash{'adsrc'}, - data_type => $$columnhash{'typename'}, + data_type => $$columnhash{'typname'}, order => $$columnhash{'attnum'}, ) || die $table->error; $col->{size} = [$$columnhash{'length'}] if $$columnhash{'length'}>0; - $col->{is_nullable} = 1 unless $$columnhash{'attnotnull'}; + $col->{is_nullable} = $$columnhash{'attnotnull'} ? 0 : 1; } $index_select->execute($table_oid); diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index 10976e8..d4415ab 100644 --- a/lib/SQL/Translator/Producer/PostgreSQL.pm +++ b/lib/SQL/Translator/Producer/PostgreSQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer::PostgreSQL; # ------------------------------------------------------------------- -# $Id: PostgreSQL.pm,v 1.28 2006-11-20 23:56:14 schiffbruechige Exp $ +# $Id: PostgreSQL.pm,v 1.29 2007-06-04 04:01:14 mwz444 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -39,7 +39,7 @@ producer. use strict; use warnings; use vars qw[ $DEBUG $WARN $VERSION ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.28 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.29 $ =~ /(\d+)\.(\d+)/; $DEBUG = 1 unless defined $DEBUG; use SQL::Translator::Schema::Constants; @@ -324,12 +324,12 @@ sub create_table # print STDERR "$table_name table_name\n"; my ( @comments, @field_defs, @sequence_defs, @constraint_defs, @fks ); - push @comments, "--\n-- Table: $table_name_ur\n--" unless $no_comments; + push @comments, "--\n-- Table: $table_name_ur\n--\n" unless $no_comments; if ( $table->comments and !$no_comments ){ my $c = "-- Comments: \n-- "; $c .= join "\n-- ", $table->comments; - $c .= "\n--"; + $c .= "\n--\n"; push @comments, $c; } @@ -356,7 +356,7 @@ sub create_table quote_table_names => $qt, table_name => $table_name, }); - push @index_defs, $idef; + $idef and push @index_defs, $idef; push @constraint_defs, @$constraints; }