Patch from rbo to support multiple database events per trigger
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / MySQL.pm
index 967176a..a8793f6 100644 (file)
@@ -134,6 +134,17 @@ A subset of INSERT that we ignore:
 
   INSERT anything
 
+=head1 ARGUMENTS
+
+This parser takes a single optional parser_arg C<mysql_parser_version>, which
+provides the desired version for the target database. Any statement in the processed
+dump file, that is commented with a version higher than the one supplied, will be stripped.
+
+Valid version specifiers for C<mysql_parser_version> are listed L<here|SQL::Translator::Utils/parse_mysql_version>
+
+More information about the MySQL comment-syntax: L<http://dev.mysql.com/doc/refman/5.0/en/comments.html>
+
+
 =cut
 
 use strict;
@@ -148,6 +159,8 @@ use Storable qw(dclone);
 use DBI qw(:sql_types);
 use base qw(Exporter);
 
+use SQL::Translator::Utils qw/parse_mysql_version/;
+
 our %type_mapping = (
 );
 
@@ -300,7 +313,7 @@ create : CREATE UNIQUE(?) /(index|key)/i index_name /on/i table_name '(' field_n
         push @{ $tables{ $item{'table_name'} }{'indices'} },
             {
                 name   => $item[4],
-                type   => $item[2] ? 'unique' : 'normal',
+                type   => $item[2][0] ? 'unique' : 'normal',
                 fields => $item[8],
             }
         ;
@@ -521,6 +534,7 @@ reference_option: /restrict/i |
 
 index : normal_index
     | fulltext_index
+    | spatial_index
     | <error>
 
 table_name   : NAME
@@ -667,10 +681,20 @@ fulltext_index : /fulltext/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/)
         } 
     }
 
+spatial_index : /spatial/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
+    { 
+        $return       = { 
+            supertype => 'index',
+            type      => 'spatial',
+            name      => $item{'index_name(?)'}[0],
+            fields    => $item[5],
+        } 
+    }
+
 name_with_opt_paren : NAME parens_value_list(s?)
     { $item[2][0] ? "$item[1]($item[2][0][0])" : $item[1] }
 
-UNIQUE : /unique/i { 1 }
+UNIQUE : /unique/i
 
 KEY : /key/i | /index/i
 
@@ -714,7 +738,7 @@ COMMA : ','
 
 BACKTICK : '`'
 
-NAME    : BACKTICK /\w+/ BACKTICK
+NAME    : BACKTICK /[^`]+/ BACKTICK
     { $item[2] }
     | /\w+/
     { $item[1] }
@@ -751,7 +775,9 @@ sub parse {
     }
     
     # Preprocess for MySQL-specific and not-before-version comments from mysqldump
-    my $parser_version = $translator->parser_args->{mysql_parser_version} || DEFAULT_PARSER_VERSION;
+    my $parser_version = 
+        parse_mysql_version ($translator->parser_args->{mysql_parser_version}, 'mysql') 
+        || DEFAULT_PARSER_VERSION;
     while ( $data =~ s#/\*!(\d{5})?(.*?)\*/#($1 && $1 > $parser_version ? '' : $2)#es ) {}
 
     my $result = $parser->startrule($data);