Bug report #9202
Can't write from python in integer fields of sqlite (not spatial) tables
|Affected QGIS version:||2.0.1||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||17830|
I'm using the python console to automatice a process that includes copy values from a dbf layer to a sqlite (non spatial) table. All works nice except when i need to write a value in a integer field of the sqlite table. The value of the integer fiels is always NULL in the target table, the rest of the values are correctly written.
Integer fields in the properties of the table are represented as qlonglong and i think that the python encapsulation of these fields is failing, because when i try to write to a integer field of a sqlite (spatial) layer it works correctly, and in this case the type of the field appears as int in the properties
I attach a zip with a sscce, that contains a sqlite file created with this commands:
spatialite -bail test_qlonglong.sqlite "SELECT InitSpatialMetaData();" spatialite -bail test_qlonglong.sqlite "CREATE TABLE spatial (gid INTEGER PRIMARY KEY, intfield INTEGER); SELECT addgeometrycolumn('spatial', 'geom', 4326, 'POINT', 2);" spatialite -bail test_qlonglong.sqlite "CREATE TABLE non_spatial (gid INTEGER PRIMARY KEY, intfield INTEGER);"
and a script.py file that shows how in spatial layers integer values are correctly written and in non spatial not, with this content:
spatial = [x for x in iface.legendInterface().layers() if x.name() == 'spatial'] spatial.dataProvider().clearErrors() spatialFields = spatial.dataProvider().fields() feat = QgsFeature() feat.setFields(spatialFields) feat.setAttribute('intfield', 10) (res, foo) = spatial.dataProvider().addFeatures([feat]) if not res: print "Error writing spatial layer" non_spatial = [x for x in iface.legendInterface().layers() if x.name() == 'non_spatial'] non_spatial.dataProvider().clearErrors() non_spatialFields = non_spatial.dataProvider().fields() feat = QgsFeature() feat.setFields(non_spatialFields) feat.setAttribute('intfield', 10) (res, foo) = non_spatial.dataProvider().addFeatures([feat]) if not res: print "Error writing non spatial layer"
I'm using Ubuntu 13.04 32bits, with qgis 2.01 installed from the ppa ubuntugis-unstable
#1 Updated by Matthias Kuhn almost 9 years ago
- Status changed from Open to Feedback
Just tested here (64bit Fedora)
- spatial layer: has no
intfieldattribute and therefore the code fails for this
- non spatial layer: 2.0.1 problem reproducible
- non spatial layer: master problem solved
So it seems this has been fixed already.
#2 Updated by Francisco Puga almost 9 years ago
- File screenshot_issue9202.png added
I build qgis from source, commit 221263db95fc on Dec 8, and i'm still having this issue. Maybe a 32bit problem?
I attach a screenshot that show how the value is correctly written in the spatial table and NULL is written to non_spatial table.