package SQL::Translator::Parser::PostgreSQL;
# -------------------------------------------------------------------
-# $Id: PostgreSQL.pm,v 1.34 2003-12-10 23:09:19 kycl4rk Exp $
+# $Id: PostgreSQL.pm,v 1.38 2004-03-01 17:39:22 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.34 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.38 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
1;
}
-create : /create/i unique(?) /(index|key)/i index_name /on/i table_name using_method(?) '(' field_name(s /,/) ')' where_predicate(?) ';'
+create : CREATE unique(?) /(index|key)/i index_name /on/i table_name using_method(?) '(' field_name(s /,/) ')' where_predicate(?) ';'
{
push @{ $tables{ $item{'table_name'} }{'indices'} },
{
}
#
-# Create anything else (e.g., domain, function, etc.)
+# Create anything else (e.g., domain, etc.)
#
-create : /create/i WORD /[^;]+/ ';'
+create : CREATE WORD /[^;]+/ ';'
{ @table_comments = (); }
using_method : /using/i WORD { $item[2] }
| 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
key_delete : /on delete/i key_mutation
{
- $return => {
+ $return = {
type => 'delete',
action => $item[2],
};
key_update : /on update/i key_mutation
{
- $return => {
+ $return = {
type => 'update',
action => $item[2],
};
# End basically useless stuff. - ky
#
-create_table : /create/i TABLE
+create_table : CREATE TABLE
-create_index : /create/i /index/i
+create_index : CREATE /index/i
default_val : DEFAULT /(\d+|'[^']*'|\w+\(.*?\))|\w+/
{
ALTER : /alter/i
+CREATE : /create/i
+
ONLY : /only/i
DEFAULT : /default/i
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'};