Opened 14 years ago

Closed 10 years ago

#3502 closed defect (wontfix)

[PATCH] Spatialite: work around crash when creating a spatialindex on a layer without SRS

Reported by: Even Rouault Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords: sqlite spatialite
Cc:

Description

spatialite-2.3.1 and recent trunk crashes when calling SELECT CreateSpatialIndex('layer_name', 'GEOMETRY') where layer_name is a layer created without any SRS. Thus the current code doesn't fill the srid column in the geometry_columns table. But the CreateSpatialIndex() function in spatialite code supposes the content is not NULL and crashes. I reported this to Alessandro Furieri but haven't received any answer back.

Anyway, the workaround is simple. Just insert srid=-1 when no srid is available. But I'm still reluctant to commit the patch as the srid in geometry_columns should match a srid in spatial_ref_sys (foreign key). The triggers to check the condition during the insertion is not created by spatialite, so this actually works

Attachments (1)

ticket3502.patch (1.1 KB ) - added by Even Rouault 14 years ago.

Download all attachments as: .zip

Change History (4)

by Even Rouault, 14 years ago

Attachment: ticket3502.patch added

comment:1 by Even Rouault, 14 years ago

Got an answer from Alessandro :

I think the OGR driver is not at all 'smart', when
it directly performs an INSERT INTO geometry_columns 

The expected way to perform such an operation is using 
AddGeometryColumn(): this function will perform any 
expected check, eventually returning an appropriate
error code if some argument is wrong/unacceptable. 

Anyway, your debugging is absolutely correct: we can 
simply ignore a NULL SRID in updateGeometryConstraints()
without any further adverse consequence.
I've checked this: you can safely use CreateSpatialIndex()

Please note: you cannot INSERT any row into a table/geom
declaring a NULL SRID: this is because the trigger will
always raise an exception for *two* good reasons:
1) there is no matching SRID into SPATIAL_REF_SYS
2) there is no way to build a binary Geometry declaring
   a NULL SRID [the SRID is an INT defaulting to -1 if 
   undeclared]

But when you finally set a valid SRID (I mean, one already
declared into SPATIAL_REF_SYS) into GEOMETRY_COLUMNS then
anything immediately starts working as expected :-) 

---------
if you wish to perform any further testing/debugging
I've already committed this change into SVN rev.71

comment:2 by Jukka Rahkonen, 10 years ago

Current Spatialite version is 4.1.1 and the way to handle the metadata of geometry columns has changed and GDAL plays well with it. If this issue affecting Spatialite v. 2.3.1 was not corrected I would say that it won't fix ever.

comment:3 by Even Rouault, 10 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.