2

I have a problem to iterating over a oracle VectorLayer without geometry in QGIS 2.6.

self.uri = QgsDataSourceURI()
self.uri.setConnection("localhost", "port", "xe", "name", "password")
self.uri.setDataSource("", str(tableName), None, "")
oraclelayer = QgsVectorLayer(self.uri.uri(), str(tableName), "oracle")
# check valid
if oraclelayer.isValid():
    QtGui.QMessageBox.information(None, "OK", "The layer is OK!")

attrs = []

# check feature count
oraclelayer.selectAll()
QtGui.QMessageBox.information(None,"featurenumber",str(oraclelayer.selectedFeatureCount()))

# from http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/vector.html#iterating-over-vector-layer
iter = oraclelayer.getFeatures()
for feature in iter:
    attrs.append(feature.attributes())
    QtGui.QMessageBox.information(None, "feature", str(attrs[feature]))
QtGui.QMessageBox.information(None, "Datainformation", str(attrs[0]))     

The oraclelayer is Valid. selectedFeatureCount returned the correct number.

After the messagebox "featurenumber" QGIS returned an exception for the messagebox "Datainformation": list index out of range

3

The problem is solved!

I used the module PyQt4.QtSql. Now I can connect to the database and with SELECT, find my attributes.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.