2

I am at the moment working on a lift for an QGIS 2 plugin to work with QGIS 3.

The plugin specifies a QgsDataSourceUri and uses it in an QgsVectorLayer. In the specific table, laying in an Oracle database, there is a column which is not named 'date' but a german name. The type of that column is DATE type, therefore containing year, month, day, hour, minute and second.

In QGIS 2.10 this column was automatically converted to an QDateTime object by the constructor. In QGIS 3.4.2 however this column is converted to QDate, losing the hours, minutes and seconds by that.

In the documentation I cannot find any explanation on how to specify the way a column is converted to prevent that data loss.

Am I missing an configuration option that achieves to specify the conversion of a column?

The loading procedure looks like this:

def fetch_layer(self):        
    uri = QgsDataSourceURI()
    uri.setConnection(self.host, self.port, self.db_name, self.usr, self.pswd)
    uri.setDataSource(self.schema, self.table, "SHAPE", "username=\'{}\'".format(self.usr))
    layer = QgsVectorLayer(uri.uri(), self.layername, "oracle")
    print(f"This should not be QDate : {type(next(layer.getFeatures()).attribute(self.date_attr))}")

For the case that this is indeed a bug, I created also a bug report at QGIS Tickts

  • 1
    You don't seem to have a question in your Question. – Vince Dec 6 '18 at 12:07
  • Uhh, you are right. The question is, basically 'Am I missing something?'. But that should be written. – F. Meckel Dec 6 '18 at 12:25

Your Answer

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

Browse other questions tagged or ask your own question.