From: Ken Youens-Clark Date: Thu, 16 Mar 2006 19:24:02 +0000 (+0000) Subject: Added grammar for handling "unique" and "key" qualifiers to field definition. X-Git-Tag: v0.11008~457 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bd356af89894468c21b5613d117921a39cb89b09;p=dbsrgits%2FSQL-Translator.git Added grammar for handling "unique" and "key" qualifiers to field definition. --- diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 2450067..460fb65 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::MySQL; # ------------------------------------------------------------------- -# $Id: MySQL.pm,v 1.52 2006-02-22 22:54:12 kycl4rk Exp $ +# $Id: MySQL.pm,v 1.53 2006-03-16 19:24:02 kycl4rk Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -134,7 +134,7 @@ A subset of INSERT that we ignore: use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.52 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.53 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -397,6 +397,20 @@ field_qualifier : /on update/i CURRENT_TIMESTAMP } } +field_qualifier : /unique/i KEY(?) + { + $return = { + is_unique => 1, + } + } + +field_qualifier : KEY + { + $return = { + has_index => 1, + } + } + reference_definition : /references/i table_name parens_field_list(?) match_type(?) on_delete(?) on_update(?) { $return = { @@ -740,6 +754,22 @@ sub parse { } } + if ( $fdata->{'has_index'} ) { + $table->add_index( + name => '', + type => 'NORMAL', + fields => $fdata->{'name'}, + ) or die $table->error; + } + + if ( $fdata->{'is_unique'} ) { + $table->add_constraint( + name => '', + type => 'UNIQUE', + fields => $fdata->{'name'}, + ) or die $table->error; + } + if ( $field->data_type =~ /(set|enum)/i && !$field->size ) { my %extra = $field->extra; my $longest = 0;