From: Jess Robinson Date: Fri, 9 Jun 2006 13:56:58 +0000 (+0000) Subject: Allow skipped insert statements and trigger bodies to contain quoted semi-colons X-Git-Tag: v0.11008~424 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9bf756df23f2ee53154ebc7e2362f1733eaf862f;p=dbsrgits%2FSQL-Translator.git Allow skipped insert statements and trigger bodies to contain quoted semi-colons --- diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 460fb65..20a75fa 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.53 2006-03-16 19:24:02 kycl4rk Exp $ +# $Id: MySQL.pm,v 1.54 2006-06-09 13:56:58 schiffbruechige 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.53 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.54 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -149,7 +149,7 @@ $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error $::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c. $::RD_HINT = 1; # Give out hints to help fix problems. -$GRAMMAR = q! +$GRAMMAR = << 'END_OF_GRAMMAR'; { my ( $database_name, %tables, $table_order, @table_comments ); @@ -190,7 +190,20 @@ drop : /drop/i TABLE /[^;]+/ ';' drop : /drop/i WORD(s) ';' { @table_comments = () } -insert : /insert/i /[^;]+/ ';' +string : + # MySQL strings, unlike common SQL strings, can be double-quoted or + # single-quoted, and you can escape the delmiters by doubling (but only the + # delimiter) or by backslashing. + + /'(\\.|''|[^\\\'])*'/ | + /"(\\.|""|[^\\\"])*"/ + # For reference, std sql str: /(?:(?:\')(?:[^\']*(?:(?:\'\')[^\']*)*)(?:\'))// + +nonstring : /[^;\'"]+/ + +statement_body : (string | nonstring)(s?) + +insert : /insert/i statement_body ';' alter : ALTER TABLE table_name alter_specification(s /,/) ';' { @@ -690,7 +703,7 @@ CURRENT_TIMESTAMP : /current_timestamp(\(\))?/i | /now\(\)/i { 'CURRENT_TIMESTAMP' } -!; +END_OF_GRAMMAR # ------------------------------------------------------------------- sub parse { diff --git a/lib/SQL/Translator/Parser/PostgreSQL.pm b/lib/SQL/Translator/Parser/PostgreSQL.pm index d1a168a..b666ea0 100644 --- a/lib/SQL/Translator/Parser/PostgreSQL.pm +++ b/lib/SQL/Translator/Parser/PostgreSQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::PostgreSQL; # ------------------------------------------------------------------- -# $Id: PostgreSQL.pm,v 1.46 2006-03-21 18:39:28 mwz444 Exp $ +# $Id: PostgreSQL.pm,v 1.47 2006-06-09 13:56:58 schiffbruechige Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -108,7 +108,7 @@ View table: use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.46 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.47 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -182,9 +182,16 @@ grant : /grant/i WORD(s /,/) /on/i TABLE(?) table_name /to/i name_with_opt_quote drop : /drop/i /[^;]*/ ';' -insert : /insert/i /[^;]*/ ';' +string : + /'(\\.|''|[^\\\'])*'/ -update : /update/i /[^;]*/ ';' +nonstring : /[^;\'"]+/ + +statement_body : (string | nonstring)(s?) + +insert : /insert/i statement_body ';' + +update : /update/i statement_body ';' # # Create table. diff --git a/lib/SQL/Translator/Parser/SQLite.pm b/lib/SQL/Translator/Parser/SQLite.pm index d03bc61..9e6a610 100644 --- a/lib/SQL/Translator/Parser/SQLite.pm +++ b/lib/SQL/Translator/Parser/SQLite.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::SQLite; # ------------------------------------------------------------------- -# $Id: SQLite.pm,v 1.9 2006-06-08 21:02:19 schiffbruechige Exp $ +# $Id: SQLite.pm,v 1.10 2006-06-09 13:56:58 schiffbruechige Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -152,7 +152,7 @@ like-op::= use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -456,7 +456,14 @@ for_each : /FOR EACH ROW/i | /FOR EACH STATEMENT/i when : WHEN expr { $item[2] } -trigger_step : /(select|delete|insert|update)/i /[^;]+/ SEMICOLON +string : + /'(\\.|''|[^\\\'])*'/ + +nonstring : /[^;\'"]+/ + +statement_body : (string | nonstring)(s?) + +trigger_step : /(select|delete|insert|update)/i statement_body SEMICOLON { $return = join( ' ', $item[1], $item[2] ) }