From: Dagfinn Ilmari Mannsåker Date: Sun, 14 Dec 2014 19:57:38 +0000 (+0000) Subject: Fix quoting of trigger name and table in Producer::PostgreSQL X-Git-Tag: v0.11021~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c9c8f3e19f6af2ce0fe5cacd55b87b1d88c6e5eb;p=dbsrgits%2FSQL-Translator.git Fix quoting of trigger name and table in Producer::PostgreSQL --- diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index 4df18bf..c45229a 100644 --- a/lib/SQL/Translator/Producer/PostgreSQL.pm +++ b/lib/SQL/Translator/Producer/PostgreSQL.pm @@ -213,6 +213,7 @@ sub produce { for my $trigger ( $schema->get_triggers ) { push @table_defs, create_trigger( $trigger, { add_drop_trigger => $add_drop_table, + generator => $generator, no_comments => $no_comments, }); } @@ -633,10 +634,11 @@ sub create_constraint sub create_trigger { my ($trigger,$options) = @_; + my $generator = _generator($options); my @statements; - push @statements, sprintf( 'DROP TRIGGER IF EXISTS %s', $trigger->name ) + push @statements, sprintf( 'DROP TRIGGER IF EXISTS %s', $generator->quote($trigger->name) ) if $options->{add_drop_trigger}; my $scope = $trigger->scope || ''; @@ -644,10 +646,10 @@ sub create_trigger { push @statements, sprintf( 'CREATE TRIGGER %s %s %s ON %s%s %s', - $trigger->name, + $generator->quote($trigger->name), $trigger->perform_action_when, join( ' OR ', @{ $trigger->database_events } ), - $trigger->on_table, + $generator->quote($trigger->on_table), $scope, $trigger->action, ); diff --git a/t/46xml-to-pg.t b/t/46xml-to-pg.t index 61a354d..8d8f8a6 100644 --- a/t/46xml-to-pg.t +++ b/t/46xml-to-pg.t @@ -64,13 +64,13 @@ CREATE VIEW "email_list" ( "email" ) AS SELECT email FROM Basic WHERE (email IS NOT NULL) ; -DROP TRIGGER IF EXISTS foo_trigger; +DROP TRIGGER IF EXISTS "foo_trigger"; -CREATE TRIGGER foo_trigger after insert ON Basic update modified=timestamp();; +CREATE TRIGGER "foo_trigger" after insert ON "Basic" update modified=timestamp();; -DROP TRIGGER IF EXISTS bar_trigger; +DROP TRIGGER IF EXISTS "bar_trigger"; -CREATE TRIGGER bar_trigger before insert OR update ON Basic update modified2=timestamp();; +CREATE TRIGGER "bar_trigger" before insert OR update ON "Basic" update modified2=timestamp();; ALTER TABLE "Basic" ADD FOREIGN KEY ("another_id") REFERENCES "Another" ("id") DEFERRABLE; diff --git a/t/data/roundtrip.xml b/t/data/roundtrip.xml index 7262ad5..28d39ff 100644 --- a/t/data/roundtrip.xml +++ b/t/data/roundtrip.xml @@ -119,6 +119,12 @@ Created on Fri Aug 15 15:08:18 2003 update modified2=timestamp(); + + select timestamp(); +