Fix string quoting in PostGIS statements
Dagfinn Ilmari Mannsåker [Wed, 9 Sep 2015 11:52:29 +0000 (12:52 +0100)]
Changes
lib/SQL/Translator/Producer/PostgreSQL.pm

diff --git a/Changes b/Changes
index 08bae1b..95b422f 100644 (file)
--- a/Changes
+++ b/Changes
@@ -17,6 +17,7 @@ Changes for SQL::Translator
  * Fix multi-line comments in YAML, JSON and PostgreSQL producers
  * Fix identifier quoting in PostgreSQL diff producer
  * Fix missing semicolons between PostGIS statements
+ * Fix string quoting in PostGIS statements
 
 0.11021 2015-01-29
 
index 83b7111..89b9c1b 100644 (file)
@@ -854,25 +854,29 @@ sub add_geometry_column {
     my ($field, $options) = @_;
 
     return sprintf(
-        "INSERT INTO geometry_columns VALUES ('%s','%s','%s','%s','%s','%s','%s')",
-        '',
-        $field->table->schema->name,
-        $options->{table} ? $options->{table} : $field->table->name,
-        $field->name,
-        $field->extra->{dimensions},
-        $field->extra->{srid},
-        $field->extra->{geometry_type},
+        "INSERT INTO geometry_columns VALUES (%s,%s,%s,%s,%s,%s,%s)",
+        map(__PACKAGE__->_quote_string($_),
+            '',
+            $field->table->schema->name,
+            $options->{table} ? $options->{table} : $field->table->name,
+            $field->name,
+            $field->extra->{dimensions},
+            $field->extra->{srid},
+            $field->extra->{geometry_type},
+        ),
     );
 }
 
 sub drop_geometry_column {
-    my $field = shift;
+    my ($field) = @_;
 
     return sprintf(
-        "DELETE FROM geometry_columns WHERE f_table_schema = '%s' AND f_table_name = '%s' AND f_geometry_column = '%s'",
-        $field->table->schema->name,
-        $field->table->name,
-        $field->name,
+        "DELETE FROM geometry_columns WHERE f_table_schema = %s AND f_table_name = %s AND f_geometry_column = %s",
+        map(__PACKAGE__->_quote_string($_),
+            $field->table->schema->name,
+            $field->table->name,
+            $field->name,
+        ),
     );
 }