From: Dagfinn Ilmari Mannsåker Date: Sun, 29 Jun 2014 17:36:33 +0000 (+0100) Subject: Escape the closing quote character when quoting indentifiers X-Git-Tag: v0.11021~16^2~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0c425150cb5850c2c6e0fb272f4769831b485cbc;p=dbsrgits%2FSQL-Translator.git Escape the closing quote character when quoting indentifiers --- diff --git a/lib/SQL/Translator/Generator/DDL/PostgreSQL.pm b/lib/SQL/Translator/Generator/DDL/PostgreSQL.pm index b3cc1b8..cdf5049 100644 --- a/lib/SQL/Translator/Generator/DDL/PostgreSQL.pm +++ b/lib/SQL/Translator/Generator/DDL/PostgreSQL.pm @@ -12,7 +12,11 @@ I =cut use Moo; -has quote_chars => (is => 'rw', default => sub { +[qw(" ")] } ); +has quote_chars => ( + is => 'rw', + default => sub { +[qw(" ")] }, + trigger => sub { $_[0]->clear_escape_char }, +); with 'SQL::Translator::Generator::Role::Quote'; diff --git a/lib/SQL/Translator/Generator/Role/Quote.pm b/lib/SQL/Translator/Generator/Role/Quote.pm index 56a02f2..33725c3 100644 --- a/lib/SQL/Translator/Generator/Role/Quote.pm +++ b/lib/SQL/Translator/Generator/Role/Quote.pm @@ -15,6 +15,13 @@ I requires qw(quote_chars name_sep); +has escape_char => ( + is => 'ro', + lazy => 1, + clearer => 1, + default => sub { $_[0]->quote_chars->[-1] }, +); + sub quote { my ($self, $label) = @_; @@ -34,8 +41,10 @@ sub quote { } my $sep = $self->name_sep || ''; + my $esc = $self->escape_char; + # parts containing * are naturally unquoted - join $sep, map "$l$_$r", ( $sep ? split (/\Q$sep\E/, $label ) : $label ) + join $sep, map { (my $n = $_) =~ s/\Q$r/$esc$r/g; "$l$n$r" } ( $sep ? split (/\Q$sep\E/, $label ) : $label ) } 1; diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index 9b8adbc..34a9be8 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -787,7 +787,9 @@ sub mk_name { sub quote { my ($name, $q) = @_; - $q && $name ? "$quote_char$name$quote_char" : $name; + return $name unless $q && $name; + $name =~ s/\Q$quote_char/$quote_char$quote_char/g; + return "$quote_char$name$quote_char"; }