Bug report #21670

DB Manager - load sql query as layer with primary key

Added by Patrice V over 5 years ago. Updated over 5 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Python bindings / sipify
Affected QGIS version:3.7(master) Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:duplicate
Crashes QGIS or corrupts data:No Copied to github as #:29486

Description

Hi,
I use Win7 and Qgis 3.4 (or 3.6, the same bug appends)
I use DB manager for loading a layer in qgis.
If I do in the request dialog :
  • "SELECT * FROM spatialite_table"
  • or "SELECT * FROM spatialite_view"
    It's ok.

Then I check "Load as a new layer", And I check "primary key column" with the column I want for the primary key.
It seems ok, the layer is loaded in qgis, and in properties/source there is
dbname='path_to_spatialite_file' key='column_with_pk_i_want' table="spatialite_table" (geom) sql=

But When I do with pyqgis :
print([fet.id() for fet in the_qgis_layer.getFeatures()])
it's printing the first column value of the spatialite_table, and not the 'column_with_pk_i_want' column value...
It was working well in qgis 2.18.

Thanks in advance,
Regards,


Related issues

Duplicates QGIS Application - Bug report #21397: Assigning a primary key in QgsDataSourceUri doesn't work Open 2019-02-26

History

#1 Updated by Alessandro Pasotti over 5 years ago

  • Duplicates Bug report #21397: Assigning a primary key in QgsDataSourceUri doesn't work added

#2 Updated by Patrice V over 5 years ago

another note : it seems to be specific to spatialite db. I tried with a postgis db and behaviour is normal...

#3 Updated by Giovanni Manghi over 5 years ago

  • Category changed from DB Manager to Python bindings / sipify

#4 Updated by Giovanni Manghi over 5 years ago

  • Resolution set to duplicate
  • Status changed from Open to Closed

Also available in: Atom PDF