PostGIS functions are case-sensitive
Florian Ragwitz [Tue, 5 Apr 2011 15:26:49 +0000 (17:26 +0200)]
Use their proper names, not the lc()ed version.

lib/SQL/Translator/Producer/PostgreSQL.pm
t/63-spacial-pgsql.t

index 87fa694..02c9f11 100644 (file)
@@ -545,20 +545,20 @@ sub create_geometry_constraints{
        my @constraints;
        push @constraints, SQL::Translator::Schema::Constraint->new(
                                                        name       => "enforce_dims_".$field->name,
-                                                       expression => "(st_ndims($field) = ".$field->{extra}{dimensions}.")",
+                                                       expression => "(ST_NDims($field) = ".$field->{extra}{dimensions}.")",
                                                        table      => $field->table,
                                                        type       => CHECK_C,
                                                );
                                                
        push @constraints, SQL::Translator::Schema::Constraint->new(
                                                        name       => "enforce_srid_".$field->name,
-                                                       expression => "(st_srid($field) = ".$field->{extra}{srid}.")",
+                                                       expression => "(ST_SRID($field) = ".$field->{extra}{srid}.")",
                                                        table      => $field->table,
                                                        type       => CHECK_C,
                                                );
        push @constraints, SQL::Translator::Schema::Constraint->new(
                                                        name       => "enforce_geotype_".$field->name,
-                                                       expression => "(geometrytype($field) = '".$field->{extra}{geometry_type}."'::text OR $field IS NULL)",
+                                                       expression => "(GeometryType($field) = '".$field->{extra}{geometry_type}."'::text OR $field IS NULL)",
                                                        table      => $field->table,
                                                        type       => CHECK_C,
                                                );
index 0cbc8fe..fc4c418 100644 (file)
@@ -52,9 +52,9 @@ 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))
-ALTER TABLE mytable ADD CONSTRAINT enforce_geotype_myfield CHECK ((geometrytype(myfield) = 'POINT'::text OR myfield IS NULL))],
+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');
 
 my $field2 = SQL::Translator::Schema::Field->new( name      => 'myfield',
@@ -82,9 +82,9 @@ 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_geotype_myfield CHECK ((geometrytype(myfield) = 'POINT'::text OR myfield IS NULL))],
+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');
@@ -92,9 +92,9 @@ 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))
-ALTER TABLE mytable ADD CONSTRAINT enforce_geotype_field3 CHECK ((geometrytype(field3) = 'POINT'::text OR field3 IS NULL))],
+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);
@@ -124,9 +124,9 @@ is($create_table,qq[--
 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))
+  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))
 );
 INSERT INTO geometry_columns VALUES ('','myschema','mytable','field3','2','-1','POINT')],'Create table with geometry works.');