package SQL::Translator::Parser::MySQL;
# -------------------------------------------------------------------
-# $Id: MySQL.pm,v 1.39 2003-09-08 15:09:19 kycl4rk Exp $
+# $Id: MySQL.pm,v 1.44 2004-03-01 17:39:22 kycl4rk Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
-# 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.39 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.44 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
}
}
- for my $opt ( @{ $item{'table_option(s?)'} } ) {
- if ( my ( $key, $val ) = each %$opt ) {
- $tables{ $table_name }{'table_options'}{ $key } = $val;
- }
+ if ( my @options = @{ $item{'table_option(s?)'} } ) {
+ $tables{ $table_name }{'table_options'} = \@options;
}
1;
create_definition : constraint
| index
| field
+ | comment
| <error>
comment : /^\s*(?:#|-{2}).*\n/
{
my $comment = $item[1];
- $comment =~ s/^\s*(#|-{2})\s*//;
+ $comment =~ s/^\s*(#|--)\s*//;
$comment =~ s/\s*$//;
$return = $comment;
push @table_comments, $comment;
field_comment : /^\s*(?:#|-{2}).*\n/
{
my $comment = $item[1];
- $comment =~ s/^\s*(#|-{2})\s*//;
+ $comment =~ s/^\s*(#|--)\s*//;
$comment =~ s/\s*$//;
$return = $comment;
}
}
}
-match_type : /match full/i { 'match_full' }
+match_type : /match full/i { 'full' }
|
- /match partial/i { 'match_partial' }
+ /match partial/i { 'partial' }
on_delete_do : /on delete/i reference_option
{ $item[2] }
field_name : NAME
-index_name : WORD
+index_name : NAME
data_type : WORD parens_value_list(s?) type_qualifier(s?)
{
unsigned : /unsigned/i { $return = 0 }
-default_val : /default/i /(?:')?[\w\d:.-]*(?:')?/
- {
- $item[2] =~ s/'//g;
+#default_val : /default/i /(?:')?[\s\w\d:.-]*(?:')?/
+# {
+# $item[2] =~ s/'//g;
+# $return = $item[2];
+# }
+
+default_val : /default/i /'(?:.*?\\')*.*?'|(?:')?[\w\d:.-]*(?:')?/
+ {
+ $item[2] =~ s/^\s*'|'\s*$//g;
$return = $item[2];
}
| foreign_key_def
| <error>
-foreign_key_def : opt_constraint(?) /foreign key/i parens_field_list reference_definition
+foreign_key_def : foreign_key_def_begin parens_field_list reference_definition
{
$return = {
supertype => 'constraint',
type => 'foreign_key',
- name => $item[1][0],
- fields => $item[3],
+ name => $item[1],
+ fields => $item[2],
%{ $item{'reference_definition'} },
}
}
-opt_constraint : /constraint/i NAME
- { $item[2] }
+foreign_key_def_begin : /constraint/i /foreign key/i
+ { $return = '' }
+ |
+ /constraint/i WORD /foreign key/i
+ { $return = $item[2] }
+ |
+ /foreign key/i
+ { $return = '' }
primary_key_def : primary_key index_name(?) '(' name_with_opt_paren(s /,/) ')'
{
KEY : /key/i | /index/i
-table_option : /[^\s;]*/
+table_option : WORD /\s*=\s*/ WORD
{
- $return = { split /=/, $item[1] }
+ $return = { $item[1] => $item[3] };
}
CREATE : /create/i
) or die $table->error;
}
+ if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
+ $table->options( \@options ) or die $table->error;
+ }
+
for my $cdata ( @{ $tdata->{'constraints'} || [] } ) {
my $constraint = $table->add_constraint(
name => $cdata->{'name'},