Bug report #7664
Cannot create new Spatialite layer
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.
Associated revisions
spatialite provider: accept empty tables from spatialite 4 (fixes #7664)
History
#1 Updated by rcline - over 11 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 11 years ago
- File spatialite4_qgis-browser.png added
- File spatialite4_db-manager.png added
- File spatialite4_browser-panel.png added
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 over 11 years ago
- Status changed from Open to Closed
Fixed in changeset cafc3677fdcd4fa999e6b0b609beaaa68d41e8e9.