From: Dagfinn Ilmari Mannsåker Date: Wed, 9 Sep 2015 14:02:20 +0000 (+0100) Subject: Fix missing semicolons between PostGIS statements X-Git-Tag: v0.11022~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6440741a562ff8bb42c79282d30f3562c4336578;p=dbsrgits%2FSQL-Translator.git Fix missing semicolons between PostGIS statements --- diff --git a/Changes b/Changes index 7bb8415..08bae1b 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,7 @@ Changes for SQL::Translator * Fix parsing of MySQL column comments (RT#83380) * Fix multi-line comments in YAML, JSON and PostgreSQL producers * Fix identifier quoting in PostgreSQL diff producer + * Fix missing semicolons between PostGIS statements 0.11021 2015-01-29 diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index b490682..83b7111 100644 --- a/lib/SQL/Translator/Producer/PostgreSQL.pm +++ b/lib/SQL/Translator/Producer/PostgreSQL.pm @@ -334,9 +334,8 @@ sub create_table # Geometry # if (my @geometry_columns = grep { is_geometry($_) } $table->get_fields) { - $create_statement .= ";"; - $create_statement .= join("\n", '', map{ drop_geometry_column($_) } @geometry_columns) if $options->{add_drop_table}; - $create_statement .= join("\n", '', map{ add_geometry_column($_) } @geometry_columns); + $create_statement .= join(";\n", '', map{ drop_geometry_column($_) } @geometry_columns) if $options->{add_drop_table}; + $create_statement .= join(";\n", '', map{ add_geometry_column($_) } @geometry_columns); } return $create_statement, \@fks; @@ -830,8 +829,8 @@ sub add_field my $out = sprintf('ALTER TABLE %s ADD COLUMN %s', _generator($options)->quote($new_field->table->name), create_field($new_field, $options)); - $out .= "\n".add_geometry_column($new_field) - . "\n".add_geometry_constraints($new_field) + $out .= ";\n".add_geometry_column($new_field) + . ";\n".add_geometry_constraints($new_field) if is_geometry($new_field); return $out; @@ -846,7 +845,7 @@ sub drop_field my $out = sprintf('ALTER TABLE %s DROP COLUMN %s', $generator->quote($old_field->table->name), $generator->quote($old_field->name)); - $out .= "\n".drop_geometry_column($old_field) + $out .= ";\n".drop_geometry_column($old_field) if is_geometry($old_field); return $out; } @@ -880,14 +879,14 @@ sub drop_geometry_column { sub add_geometry_constraints { my ($field, $options) = @_; - return join("\n", map { alter_create_constraint($_) } + return join(";\n", map { alter_create_constraint($_) } create_geometry_constraints($field)); } sub drop_geometry_constraints { my ($field, $options) = @_; - return join("\n", map { alter_drop_constraint($_) } + return join(";\n", map { alter_drop_constraint($_) } create_geometry_constraints($field)); } @@ -898,7 +897,7 @@ sub alter_table { my $out = sprintf('ALTER TABLE %s %s', $generator->quote($to_table->name), $options->{alter_table_action}); - $out .= "\n".$options->{geometry_changes} if $options->{geometry_changes}; + $out .= ";\n".$options->{geometry_changes} if $options->{geometry_changes}; return $out; } @@ -912,7 +911,7 @@ sub rename_table { add_geometry_column($_, { table => $new_table }), } grep { is_geometry($_) } $old_table->get_fields; - $options->{geometry_changes} = join ("\n",@geometry_changes) if @geometry_changes; + $options->{geometry_changes} = join (";\n",@geometry_changes) if @geometry_changes; return alter_table($old_table, $options); } @@ -983,7 +982,7 @@ sub drop_table { my @geometry_drops = map { drop_geometry_column($_); } grep { is_geometry($_) } $table->get_fields; - $out .= join("\n", '', @geometry_drops) if @geometry_drops; + $out .= join(";\n", '', @geometry_drops) if @geometry_drops; return $out; } diff --git a/t/63-spacial-pgsql.t b/t/63-spacial-pgsql.t index 652893f..b6ee7c4 100644 --- a/t/63-spacial-pgsql.t +++ b/t/63-spacial-pgsql.t @@ -52,8 +52,8 @@ is($field1_geocol, "INSERT INTO geometry_columns VALUES ('','myschema','mytable' my $field1_geocon = SQL::Translator::Producer::PostgreSQL::add_geometry_constraints($field1); -is($field1_geocon, qq[ALTER TABLE mytable ADD CONSTRAINT enforce_dims_myfield CHECK ((ST_NDims(myfield) = 2)) -ALTER TABLE mytable ADD CONSTRAINT enforce_srid_myfield CHECK ((ST_SRID(myfield) = -1)) +is($field1_geocon, qq[ALTER TABLE mytable ADD CONSTRAINT enforce_dims_myfield CHECK ((ST_NDims(myfield) = 2)); +ALTER TABLE mytable ADD CONSTRAINT enforce_srid_myfield CHECK ((ST_SRID(myfield) = -1)); ALTER TABLE mytable ADD CONSTRAINT enforce_geotype_myfield CHECK ((GeometryType(myfield) = 'POINT'::text OR myfield IS NULL))], 'Add geometry constraints works'); @@ -70,8 +70,8 @@ my $field2 = SQL::Translator::Schema::Field->new( name => 'myfield', my $alter_field = SQL::Translator::Producer::PostgreSQL::alter_field($field1, $field2); is($alter_field, qq[DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'mytable' AND f_geometry_column = 'myfield'; -ALTER TABLE mytable DROP CONSTRAINT enforce_dims_myfield -ALTER TABLE mytable DROP CONSTRAINT enforce_srid_myfield +ALTER TABLE mytable DROP CONSTRAINT enforce_dims_myfield; +ALTER TABLE mytable DROP CONSTRAINT enforce_srid_myfield; ALTER TABLE mytable DROP CONSTRAINT enforce_geotype_myfield; ALTER TABLE mytable ALTER COLUMN myfield SET NOT NULL; ALTER TABLE mytable ALTER COLUMN myfield TYPE character varying(25)], @@ -82,23 +82,23 @@ my $alter_field2 = SQL::Translator::Producer::PostgreSQL::alter_field($field2, is($alter_field2, qq[ALTER TABLE mytable ALTER COLUMN myfield DROP NOT NULL; ALTER TABLE mytable ALTER COLUMN myfield TYPE geometry; INSERT INTO geometry_columns VALUES ('','myschema','mytable','myfield','2','-1','POINT'); -ALTER TABLE mytable ADD CONSTRAINT enforce_dims_myfield CHECK ((ST_NDims(myfield) = 2)) -ALTER TABLE mytable ADD CONSTRAINT enforce_srid_myfield CHECK ((ST_SRID(myfield) = -1)) +ALTER TABLE mytable ADD CONSTRAINT enforce_dims_myfield CHECK ((ST_NDims(myfield) = 2)); +ALTER TABLE mytable ADD CONSTRAINT enforce_srid_myfield CHECK ((ST_SRID(myfield) = -1)); ALTER TABLE mytable ADD CONSTRAINT enforce_geotype_myfield CHECK ((GeometryType(myfield) = 'POINT'::text OR myfield IS NULL))], 'Alter field non geometry to geometry works'); $field1->name('field3'); my $add_field = SQL::Translator::Producer::PostgreSQL::add_field($field1); -is($add_field, qq[ALTER TABLE mytable ADD COLUMN field3 geometry -INSERT INTO geometry_columns VALUES ('','myschema','mytable','field3','2','-1','POINT') -ALTER TABLE mytable ADD CONSTRAINT enforce_dims_field3 CHECK ((ST_NDims(field3) = 2)) -ALTER TABLE mytable ADD CONSTRAINT enforce_srid_field3 CHECK ((ST_SRID(field3) = -1)) +is($add_field, qq[ALTER TABLE mytable ADD COLUMN field3 geometry; +INSERT INTO geometry_columns VALUES ('','myschema','mytable','field3','2','-1','POINT'); +ALTER TABLE mytable ADD CONSTRAINT enforce_dims_field3 CHECK ((ST_NDims(field3) = 2)); +ALTER TABLE mytable ADD CONSTRAINT enforce_srid_field3 CHECK ((ST_SRID(field3) = -1)); ALTER TABLE mytable ADD CONSTRAINT enforce_geotype_field3 CHECK ((GeometryType(field3) = 'POINT'::text OR field3 IS NULL))], 'Add geometry field works'); my $drop_field = SQL::Translator::Producer::PostgreSQL::drop_field($field1); -is($drop_field, qq[ALTER TABLE mytable DROP COLUMN field3 +is($drop_field, qq[ALTER TABLE mytable DROP COLUMN field3; DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'mytable' AND f_geometry_column = 'field3'], 'Drop geometry field works'); $table->add_field($field1); @@ -131,12 +131,12 @@ CREATE TABLE mytable ( INSERT INTO geometry_columns VALUES ('','myschema','mytable','field3','2','-1','POINT')],'Create table with geometry works.'); my $rename_table = SQL::Translator::Producer::PostgreSQL::rename_table($table, "table2"); -is($rename_table,qq[ALTER TABLE mytable RENAME TO table2 -DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'mytable' AND f_geometry_column = 'field3' +is($rename_table,qq[ALTER TABLE mytable RENAME TO table2; +DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'mytable' AND f_geometry_column = 'field3'; INSERT INTO geometry_columns VALUES ('','myschema','table2','field3','2','-1','POINT')],'Rename table with geometry works.'); $table->name("table2"); my $drop_table = SQL::Translator::Producer::PostgreSQL::drop_table($table); -is($drop_table, qq[DROP TABLE table2 CASCADE +is($drop_table, qq[DROP TABLE table2 CASCADE; DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'table2' AND f_geometry_column = 'field3'], 'Drop table with geometry works.');