Opened 7 years ago
Closed 7 years ago
#6838 closed defect (fixed)
OGRSQLiteDataSource::SaveStatistics does not call UpdateLayerStatistics for Spatialite 4 Db's
Reported by: | mj10777 | Owned by: | warmerdam |
---|---|---|---|
Priority: | high | Milestone: | 2.2.0 |
Component: | OGR_SF | Version: | svn-trunk |
Severity: | major | Keywords: | |
Cc: |
Description
In the Geopaparazzi forum it has been reported that spatialite 4 Databases created in QGIS with the 'Save as' function as 'Spatialite [OGR]' does not update the 'vector_layers_statistics' TABLE correctly.
https://groups.google.com/forum/#!topic/geopaparazzi-users/DeJzGqg26NU
This function (in QGIS) is delt with in 'QgsVectorFileWriter::writeAsVectorFormat'
OGR runs OGRSQLiteTableLayer::RunDeferredCreationIfNecessary is called
- when the first feature is added (in QgsVectorFileWriter::writeFeature)
- the TABLE will be created
- UpdateLayerStatistics is called on the empty table
When all the features have been added
- OGR calls OGRSQLiteDataSource::SaveStatistics()
- for each layer SaveStatistics() is called
- which does nothing since HasSpatialite4Layout() is TRUE and returns -1
- for each layer SaveStatistics() is called
At this point an UpdateLayerStatistics is needed, since the table is now filled
- vector_layers_statistics.row_count remains 0 and the extent values NULL
I attempted a to workout a solution for this:
- in OGRSQLiteDataSource::SaveStatistics()
if( hDB && nSavedAllLayersCacheData == TRUE ) { // mj10777: allways FALSE for HasSpatialite4Layout() ... } else { if (HasSpatialite4Layout()) { char* pszErrMsg = NULL; int rc = SQLITE_OK; rc = sqlite3_exec( hDB, "SELECT UpdateLayerStatistics()", NULL, NULL, &pszErrMsg ); if( rc != SQLITE_OK ) { CPLError( CE_Failure, CPLE_AppDefined, "Unable to call %s: %s", "UpdateLayerStatistics()", pszErrMsg ); sqlite3_free( pszErrMsg ); } } }
But although 'UpdateLayerStatistics()' is correctly called
- the vector_layers_statistics entry remains unchanged
- cause unknown
Geopaparazzi will check if vector_layers_statistics.row_count is NULL
- and call 'UpdateLayerStatistics()' to repair it
- but when row_count == 0, it is considered empty and thus not loaded
In 37715: