Opened 6 years ago

Closed 6 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:


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.!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)

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

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:

    if( hDB && nSavedAllLayersCacheData == TRUE )
    { // mj10777: allways FALSE for HasSpatialite4Layout()
      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

Change History (1)

comment:1 by Even Rouault, 6 years ago

Resolution: fixed
Status: newclosed

In 37715:

SQLite: update layer statistics for Spatialite 4 DB (fixes #6838)

Note: See TracTickets for help on using tickets.