]> granicus.if.org Git - postgis/commitdiff
add unit tests for numeric overflow. ticket #3100
authorBborie Park <bkpark at ucdavis.edu>
Sat, 2 May 2015 20:27:49 +0000 (20:27 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Sat, 2 May 2015 20:27:49 +0000 (20:27 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13468 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rtpostgis.sql.in
raster/test/regress/tickets.sql
raster/test/regress/tickets_expected

index 1286c94b912cd2fb2c7467ef90934f387f21736e..bf3d574214f588283c64b396ab30a7d7f1882bb7 100644 (file)
@@ -7011,7 +7011,7 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_scale(rastschema name, rasttab
                        || ' ADD CONSTRAINT ' || quote_ident(cn)
                        || ' CHECK (round(st_scale' || $4 || '('
                        || quote_ident($3)
-                       || ')::numeric, 10) = round(' || attr || '::numeric, 10))';
+                       || ')::numeric, 10) = round(' || text(attr) || '::numeric, 10))';
                RETURN _add_raster_constraint(cn, sql);
        END;
        $$ LANGUAGE 'plpgsql' VOLATILE STRICT
index 398c61ce0569e76ba5d55671c2247f3b4ef6d491..cba9b72aac0b0a48ed8c70ef489a7920738615d7 100644 (file)
@@ -1,12 +1,21 @@
--- #1485
+/******************************************************************************
+ #1485
+******************************************************************************/
+
 SELECT '#1485', count(*) FROM geometry_columns
 WHERE f_table_name = 'raster_columns';
 
--- #2532
+/******************************************************************************
+ #2532
+******************************************************************************/
+
 SELECT '#2532.1', NULL::raster @ null::geometry;
 SELECT '#2532.2', NULL::geometry @ null::raster;
 
--- #2911
+/******************************************************************************
+ #2911
+******************************************************************************/
+
 WITH data AS ( SELECT '#2911' l, ST_Metadata(ST_Rescale(
  ST_AddBand(
   ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0),
@@ -16,3 +25,90 @@ WITH data AS ( SELECT '#2911' l, ST_Metadata(ST_Rescale(
  -2.0
  )) m
 ) SELECT l, (m).* FROM data;
+
+/******************************************************************************
+ #3006
+******************************************************************************/
+
+SET client_min_messages TO ERROR;
+
+DROP TABLE IF EXISTS test_raster_scale_regular;
+DROP TABLE IF EXISTS test_raster_scale_big;
+DROP TABLE IF EXISTS test_raster_scale_small;
+
+CREATE TABLE test_raster_scale_regular (
+  rid integer,
+       rast raster
+);
+
+CREATE TABLE test_raster_scale_big (
+  rid integer,
+       rast raster
+);
+
+CREATE TABLE test_raster_scale_small (
+       rid integer,
+       rast raster
+);
+
+CREATE OR REPLACE FUNCTION make_test_raster(
+  table_suffix text,
+       rid integer,
+  scale_x double precision,
+  scale_y double precision DEFAULT 1.0
+)
+RETURNS void
+AS $$
+DECLARE
+       rast raster;
+       width integer := 2;
+       height integer := 2;
+       ul_x double precision := 0;
+       ul_y double precision := 0;
+       skew_x double precision := 0;
+       skew_y double precision := 0;
+       initvalue double precision := 1;
+       nodataval double precision := 0;
+BEGIN
+       rast := ST_MakeEmptyRaster(width, height, ul_x, ul_y, scale_x, scale_y, skew_x, skew_y, 0);
+       rast := ST_AddBand(rast, 1, '8BUI', initvalue, nodataval);
+
+       EXECUTE format('INSERT INTO test_raster_scale_%s VALUES (%L, %L)', table_suffix, rid, rast);
+       RETURN;
+END;
+$$ LANGUAGE 'plpgsql';
+
+SELECT make_test_raster('regular', 0, 1);
+SELECT make_test_raster('regular', 1, 1.0000001);
+SELECT make_test_raster('regular', 2, 0.9999999);
+SELECT AddRasterConstraints('test_raster_scale_regular'::name, 'rast'::name, 'scale_x', 'scale_y');
+SELECT r_table_name, r_raster_column, scale_x, scale_y FROM raster_columns
+  WHERE  r_raster_column = 'rast' AND r_table_name = 'test_raster_scale_regular';
+
+-- Issues enforce_scaley_rast constraint violation
+SELECT make_test_raster('regular', 3, 1.001, 0.9999999);
+
+SELECT make_test_raster('big', 0, -1234567890123456789.0);
+SELECT AddRasterConstraints('test_raster_scale_big'::name, 'rast'::name, 'scale_x', 'scale_y');
+SELECT r_table_name, r_raster_column, scale_x, scale_y FROM raster_columns
+  WHERE  r_raster_column = 'rast' AND r_table_name = 'test_raster_scale_big';
+
+-- Issues enforce_scalex_rast constraint violation
+SELECT make_test_raster('big', 1, -12345678901234567890.0);
+
+SELECT make_test_raster('small', 0, 0.00001);
+SELECT make_test_raster('small', 1, 0.000011);
+SELECT make_test_raster('small', 2, 0.00000999);
+SELECT AddRasterConstraints('test_raster_scale_small'::name, 'rast'::name, 'scale_x', 'scale_y');
+SELECT r_table_name, r_raster_column, scale_x, scale_y FROM raster_columns
+  WHERE  r_raster_column = 'rast' AND r_table_name = 'test_raster_scale_small';
+
+-- Issues enforce_scaley_rast constraint violation
+SELECT make_test_raster('small', 3, 0.00001, 1.00001);
+
+DROP FUNCTION make_test_raster(text, integer, double precision, double precision);
+DROP TABLE IF EXISTS test_raster_scale_regular;
+DROP TABLE IF EXISTS test_raster_scale_big;
+DROP TABLE IF EXISTS test_raster_scale_small;
+
+SET client_min_messages TO DEFAULT;
index e00841ebf12f3961a470a225ddd863d76d54e3be..f758838d7670dbac131ee0b477018cfee8203bf5 100644 (file)
@@ -3,3 +3,12 @@
 #2532.2|
 NOTICE:  Raster has default geotransform. Adjusting metadata for use of GDAL Warp API
 #2911|0|0|5|5|2|-2|0|0|0|1
+t
+test_raster_scale_regular|rast||1
+ERROR:  new row for relation "test_raster_scale_regular" violates check constraint "enforce_scaley_rast"
+t
+test_raster_scale_big|rast|-1.23456789012346e+18|1
+ERROR:  new row for relation "test_raster_scale_big" violates check constraint "enforce_scalex_rast"
+t
+test_raster_scale_small|rast||1
+ERROR:  new row for relation "test_raster_scale_small" violates check constraint "enforce_scaley_rast"