Remove copyright headers from individual scripts
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / MySQL.pm
index 81b7d24..3160004 100644 (file)
@@ -1,23 +1,5 @@
 package SQL::Translator::Parser::MySQL;
 
-# -------------------------------------------------------------------
-# Copyright (C) 2002-2009 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
-# published by the Free Software Foundation; version 2.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307  USA
-# -------------------------------------------------------------------
-
 =head1 NAME
 
 SQL::Translator::Parser::MySQL - parser for MySQL
@@ -641,39 +623,41 @@ foreign_key_def_begin : /constraint/i /foreign key/i WORD
     /foreign key/i
     { $return = '' }
 
-primary_key_def : primary_key index_name(?) '(' name_with_opt_paren(s /,/) ')'
+primary_key_def : primary_key index_name_not_using(?) index_type(?) '(' name_with_opt_paren(s /,/) ')' index_type(?)
     { 
         $return       = { 
             supertype => 'constraint',
-            name      => $item{'index_name(?)'}[0],
+            name      => $item[2][0],
             type      => 'primary_key',
-            fields    => $item[4],
+            fields    => $item[5],
+            options   => $item[3][0] || $item[7][0],
         };
     }
 
-unique_key_def : UNIQUE KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
+unique_key_def : UNIQUE KEY(?) index_name_not_using(?) index_type(?) '(' name_with_opt_paren(s /,/) ')' index_type(?)
     { 
         $return       = { 
             supertype => 'constraint',
-            name      => $item{'index_name(?)'}[0],
+            name      => $item[3][0],
             type      => 'unique',
-            fields    => $item[5],
+            fields    => $item[6],
+            options   => $item[4][0] || $item[8][0],
         } 
     }
 
-normal_index : KEY index_name_not_using(?) index_type(?) '(' name_with_opt_paren(s /,/) ')'
+normal_index : KEY index_name_not_using(?) index_type(?) '(' name_with_opt_paren(s /,/) ')' index_type(?)
     { 
         $return       = { 
             supertype => 'index',
             type      => 'normal',
             name      => $item[2][0],
             fields    => $item[5],
-            options   => $item[3][0],
-        } 
+            options   => $item[3][0] || $item[7][0],
+        }
     }
 
 index_name_not_using : QUOTED_NAME
-    | /\b([^u][^s]?[^i]?[^n]?[^g]?\w*?)\b/ { $return = $1 }
+    | /(\b(?!using)\w+\b)/ { $return = ($1 =~ /^using/i) ? undef : $1 }
 
 index_type : /using (btree|hash|rtree)/i { $return = uc $1 }
 
@@ -940,14 +924,13 @@ sub parse {
             sql   => $result->{procedures}->{$proc_name}->{sql},
         );
     }
-
     my @views = sort { 
         $result->{views}->{ $a }->{'order'} 
         <=> 
         $result->{views}->{ $b }->{'order'}
     } keys %{ $result->{views} };
 
-    for my $view_name ( keys %{ $result->{'views'} } ) {
+    for my $view_name ( @views ) {
         $schema->add_view(
             name => $view_name,
             sql  => $result->{'views'}->{$view_name}->{sql},