+* Correct postgis geography type insertion and linebreak fix for multiple geometry/geography columns
+
# ----------------------------------------------------------
# 0.11007 2010-11-30
# ----------------------------------------------------------
sub is_geometry
{
my $field = shift;
- return 1 if $field->data_type eq 'geometry' || $field->data_type eq 'geography';
+ return 1 if $field->data_type eq 'geometry';
+}
+
+sub is_geography
+{
+ my $field = shift;
+ return 1 if $field->data_type eq 'geography';
}
sub create_table
#
if(grep { is_geometry($_) } $table->get_fields){
$create_statement .= ";";
- $create_statement .= "\n".join("\n", map { drop_geometry_column($_) if is_geometry($_); } $table->get_fields) if $options->{add_drop_table};
- $create_statement .= "\n".join("\n", map { add_geometry_column($_) if is_geometry($_);} $table->get_fields);
+ my @geometry_columns;
+ foreach my $col ($table->get_fields) { push(@geometry_columns,$col) if is_geometry($col); }
+ $create_statement .= "\n".join("\n", map{ drop_geometry_column($_) } @geometry_columns) if $options->{add_drop_table};
+ $create_statement .= "\n".join("\n", map{ add_geometry_column($_) } @geometry_columns);
}
return $create_statement, \@fks;
$data_type .= '(' . join( ',', @size ) . ')';
}
+ #
+ # Geography
+ #
+ if($data_type eq 'geography'){
+ $data_type .= '('.$field->{extra}{geography_type}.','. $field->{extra}{srid} .')'
+ }
+
return $data_type;
}
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);
+
+my $field4 = SQL::Translator::Schema::Field->new( name => 'field4',
+ table => $table,
+ data_type => 'geography',
+ extra => {
+ geography_type => 'POINT',
+ srid => -1
+ },
+ default_value => undef,
+ is_auto_increment => 0,
+ is_nullable => 1,
+ is_foreign_key => 0,
+ is_unique => 0 );
+$table->add_field($field4);
+
my ($create_table,$fks) = SQL::Translator::Producer::PostgreSQL::create_table($table);
is($create_table,qq[--
-- Table: mytable
--
CREATE TABLE mytable (
field3 geometry,
+ field4 geography(POINT,-1),
CONSTRAINT "enforce_dims_field3" CHECK ((st_ndims(field3) = 2)),
CONSTRAINT "enforce_srid_field3" CHECK ((st_srid(field3) = -1)),
CONSTRAINT "enforce_geotype_field3" CHECK ((geometrytype(field3) = 'POINT'::text OR field3 IS NULL))
my $drop_table = SQL::Translator::Producer::PostgreSQL::drop_table($table);
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.');
+