I want to extract all attributes from a non geomety layer in QGIS with Python, but there is only the function
uniqueValues(fieldIndex)
More specific: I have a postgresql table which is loaded into QGIS with "Add PostGIS layers". Then I need all attributes from two columns in a dictionary (key: column1, value: column2). Here is my code so far:
dictAttr = {}
feature = QgsFeature()
layer.dataProvider().select(layer.dataProvider().attributeIndexes())
while layer.dataProvider().nextFeature(feature):
attributes = feature.attributeMap()
dictAttr[attributes[FIELD_INDEX1].toString()] = attributes[FIELD_INDEX2].toString()
return dictAttr
Problem: layer is not a geometry table, so it has no features and the while loop is never entered. And I can't use uniqueValues() because I need every attribute. Do you know any way to solve this? This can't be so hard...