Skip to content
Permalink
Browse files

[oracle] Treat DATE field types as datetime values

Fixes #28559
  • Loading branch information
nyalldawson committed May 14, 2020
1 parent 425cbf2 commit 3fae26fe98a32e6f921448512f47ad24abd8cc1e
Showing with 6 additions and 10 deletions.
  1. +0 −7 src/providers/oracle/qgsoracleprovider.cpp
  2. +6 −3 tests/src/python/test_provider_oracle.py
@@ -756,13 +756,6 @@ bool QgsOracleProvider::loadFields()
continue;

QVariant::Type type = field.type();

if ( types.value( field.name() ) == "DATE" )
{
// date types are incorrectly detected as datetime
type = QVariant::Date;
}

QgsField newField( field.name(), type, types.value( field.name() ), field.length(), field.precision(), comments.value( field.name() ) );

QgsFieldConstraints constraints;
@@ -99,6 +99,9 @@ def getSource(self):
def treat_time_as_string(self):
return True

def treat_date_as_datetime(self):
return True

def getEditableLayer(self):
return self.getSource()

@@ -190,15 +193,15 @@ def testDateTimeTypes(self):

fields = vl.dataProvider().fields()
self.assertEqual(fields.at(fields.indexFromName(
'date_field')).type(), QVariant.Date)
'date_field')).type(), QVariant.DateTime)
self.assertEqual(fields.at(fields.indexFromName(
'datetime_field')).type(), QVariant.DateTime)

f = next(vl.getFeatures(QgsFeatureRequest()))

date_idx = vl.fields().lookupField('date_field')
self.assertIsInstance(f.attributes()[date_idx], QDate)
self.assertEqual(f.attributes()[date_idx], QDate(2004, 3, 4))
self.assertIsInstance(f.attributes()[date_idx], QDateTime)
self.assertEqual(f.attributes()[date_idx], QDateTime(2004, 3, 4, 0, 0, 0))
datetime_idx = vl.fields().lookupField('datetime_field')
self.assertIsInstance(f.attributes()[datetime_idx], QDateTime)
self.assertEqual(f.attributes()[datetime_idx], QDateTime(

0 comments on commit 3fae26f

Please sign in to comment.
You can’t perform that action at this time.