package SQL::Translator::Parser::PostgreSQL;
# -------------------------------------------------------------------
-# $Id: PostgreSQL.pm,v 1.36 2004-02-04 17:32:22 dlc Exp $
+# $Id: PostgreSQL.pm,v 1.39 2004-08-11 22:00:39 kycl4rk Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
-# Allen Day <allenday@users.sourceforge.net>,
-# darren chamberlain <darren@cpan.org>,
-# Chris Mungall <cjm@fruitfly.org>
+# 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
use strict;
use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.36 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.39 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
| table_constraint
| <error>
-table_comment : comment
- {
- my $comment = $item[1];
+comment : /^\s*(?:#|-{2})(.*)\n/
+ {
+ my $comment = $item[1];
+ $comment =~ s/^\s*(#|-*)\s*//;
+ $comment =~ s/\s*$//;
$return = $comment;
push @table_comments, $comment;
}
-comment : /^\s*(?:#|-{2}).*\n/
-
comment_on_table : /comment/i /on/i /table/i table_name /is/i comment_phrase ';'
{
push @{ $tables{ $item{'table_name'} }{'comments'} }, $item{'comment_phrase'};
$return = $val;
}
-field : comment(s?) field_name data_type field_meta(s?) comment(s?)
+field : field_comment(s?) field_name data_type field_meta(s?) field_comment(s?)
{
my ( $default, @constraints, $is_pk );
my $is_nullable = 1;
}
| <error>
+field_comment : /^\s*(?:#|-{2})(.*)\n/
+ {
+ my $comment = $item[1];
+ $comment =~ s/^\s*(#|-*)\s*//;
+ $comment =~ s/\s*$//;
+ $return = $comment;
+ }
+
field_meta : default_val
| column_constraint
#
# We can deduce some sizes from the data type's name.
#
- $data_type->{'size'} ||= $item[2][0];
+ if ( my $size = $item[2][0] ) {
+ $data_type->{'size'} = $size;
+ }
$return = $data_type;
}
name => $tdata->{'table_name'},
) or die "Couldn't create table '$table_name': " . $schema->error;
+ $table->comments( $tdata->{'comments'} );
+
my @fields = sort {
$tdata->{'fields'}->{ $a }->{'order'}
<=>
default_value => $fdata->{'default'},
is_auto_increment => $fdata->{'is_auto_increment'},
is_nullable => $fdata->{'is_nullable'},
+ comments => $fdata->{'comments'},
) or die $table->error;
$table->primary_key( $field->name ) if $fdata->{'is_primary_key'};