Bug report #7664

Cannot create new Spatialite layer

Added by rcline - over 6 years ago. Updated about 6 years ago.

Status:Closed
Priority:Severe/Regression
Assignee:-
Category:Data Provider/SpatiaLite
Affected QGIS version:master Regression?:No
Operating System:OS X Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:16583

Description

When trying to create a new Spatialite layer from the Layer menu, I get the following error when clicking the OK button:
__ is an invalid layer and cannot be loaded. This works in QGIS 1.8.

Using latest nightly build for Lion and Mountain Lion from http://qgis.dakotacarto.com with SpatiaLite v. 4.0.

spatialite4_browser-panel.png (17.6 KB) Larry Shaffer, 2013-05-21 02:51 PM

spatialite4_db-manager.png (140 KB) Larry Shaffer, 2013-05-21 02:51 PM

spatialite4_qgis-browser.png (75.3 KB) Larry Shaffer, 2013-05-21 02:51 PM

Associated revisions

Revision cafc3677
Added by Jürgen Fischer about 6 years ago

spatialite provider: accept empty tables from spatialite 4 (fixes #7664)

History

#1 Updated by rcline - over 6 years ago

Looking at the debug information, I get the following when creating a new layer:

Debug: src/providers/spatialite/qgsspatialiteprovider.cpp: 4049: (openDb) New sqlite connection for /Users/rcline/Desktop/SSURGO/testV4_01.sqlite
Debug: src/providers/spatialite/qgsspatialiteprovider.cpp: 4070: (openDb) Connection to the database was successful
Debug: src/providers/spatialite/qgsspatialiteprovider.cpp: 523: (QgsSpatiaLiteProvider) Invalid SpatiaLite layer

The Spatialite database and the table are correctly created. Also, "Add Spatialite Layer" from the layer menu fails with the same error when trying to open an empty table. However, if I use the DB Manager SQL window to insert a record with geometry into the table, then I can add the layer.

In qgsspatialiteprovider.cpp, line 519 tests if the layer has an extent and a feature count:


    if ( !getTableSummaryAbstractInterface( lyr ) )     // gets the extent and feature count

Since New Layer creates an empty table, it appears to fail this test. With this test added for SpatiaLite ver. 4, there is no way to load an empty tabel for editing. This would explain why QGIS 1.9 worked when built with SpatiaLite 3.0.1.

#2 Updated by Larry Shaffer over 6 years ago

There seems to be no issue with doing a Save as... operation on a vector layer in the legend and producing a Spatialite 4.0 database. So it does seem like it is just empty databases that are causing the issue noted here.

The same Spatialite 4.0 database can be added when using the 'Add Spatialite Layer...' menu action or the Browser panel. But in the Browser panel it also has a duplicate entry that shows as a raster layer, which fails to load. (See spatialite4_browser-panel.png. Not sure if the duplicate tree entry in the Browser is intended and would work if the db had rasters in it, but the db does not.)

Also, when viewed in the DB Manager, it does not recognize the feature table as having geometry, just as a regular table (see spatialite4_db-manager.png). The same db is correctly recognized and a preview created in the standalone QGIS Browser app (see spatialite4_qgis-browser.png).

#3 Updated by Jürgen Fischer about 6 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF