如果未将几何列指定为小写,则在使用RecoverGeometryColumn函数创建空间表并恢复几何时,最终会出现“违反几何约束[geom-type或SRID not allowed]”错误。< / p>
我做错了什么或者我错过了某些文档吗?
答案 0 :(得分:5)
举个例子:
创建一个具有空间列的表
CREATE TABLE "test1" (
"PK_UID" INTEGER PRIMARY KEY AUTOINCREMENT,
"Geometry" MULTIPOLYGON)
恢复几何
SELECT RecoverGeometryColumn('test1', 'Geometry', 2, 'MULTIPOLYGON',2);
查看已创建的触发器
select * from sqlite_master where type='trigger' and lower(tbl_name)='test1'
结果:
CREATE TRIGGER "ggi_test1_Geometry" BEFORE INSERT ON "test1"
FOR EACH ROW BEGIN
SELECT RAISE(ROLLBACK, 'test1.Geometry violates Geometry constraint [geom-type or SRID not allowed]')
WHERE (SELECT type FROM geometry_columns
WHERE f_table_name = 'test1' AND f_geometry_column = 'Geometry'
AND GeometryConstraints(NEW."Geometry", type, srid, 'XY') = 1) IS NULL;
END
CREATE TRIGGER "ggu_test1_Geometry" BEFORE UPDATE ON "test1"
FOR EACH ROW BEGIN
SELECT RAISE(ROLLBACK, 'test1.Geometry violates Geometry constraint [geom-type or SRID not allowed]')
WHERE (SELECT type FROM geometry_columns
WHERE f_table_name = 'test1' AND f_geometry_column = 'Geometry'
AND GeometryConstraints(NEW."Geometry", type, srid, 'XY') = 1) IS NULL;
END
与geometry_columns表中的内容进行比较
select * from geometry_columns
结果:
f_table_name f_geometry_column类型coord_dimension srid spaitial_index_enabled
test1 geometry MULTIPOLYGON XY 2 0
结论: 请注意,geometry_columns表将f_geometry_column指定为“geometry”,但触发器正在查找“Geometry”。这会导致'几何约束[不允许使用geom-type或SRID]问题。因此,修复方法是将空间列名称保持为小写。