Ticket #3502 (new defect)

Opened 3 years ago

Last modified 3 years ago

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

Reported by: 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

ticket3502.patch Download (1.1 KB) - added by rouault 3 years ago.

Change History

Changed 3 years ago by rouault

Changed 3 years ago by rouault

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
Note: See TracTickets for help on using tickets.