Skip to content
Permalink
Browse files

[Oracle] Fix generated columns when evaluate default value is on

  • Loading branch information
troopa81 authored and nyalldawson committed Dec 21, 2020
1 parent 4eebcc7 commit 9569a630e4acdc7b823ce3d0db99f490c933b9fc
Showing with 29 additions and 0 deletions.
  1. +8 −0 src/providers/oracle/qgsoracleprovider.cpp
  2. +21 −0 tests/src/python/providertestbase.py
@@ -554,6 +554,7 @@ bool QgsOracleProvider::loadFields()
{
mAttributeFields.clear();
mDefaultValues.clear();
mAlwaysGenerated.clear();

QgsOracleConn *conn = connectionRO();
QSqlQuery qry( *conn );
@@ -1212,6 +1213,12 @@ QVariant QgsOracleProvider::defaultValue( int fieldId ) const
QString QgsOracleProvider::defaultValueClause( int fieldId ) const
{
QString defVal = mDefaultValues.value( fieldId, QString() ).toString();
bool isGenerated = mAlwaysGenerated.value( fieldId, false );

if ( isGenerated )
{
return defVal;
}

if ( !providerProperty( EvaluateDefaultValues, false ).toBool() && !defVal.isEmpty() )
{
@@ -1667,6 +1674,7 @@ bool QgsOracleProvider::deleteAttributes( const QgsAttributeIds &ids )
//delete the attribute from mAttributeFields
mAttributeFields.remove( id );
mDefaultValues.removeAt( id );
mAlwaysGenerated.removeAt( id );
}

if ( !conn->commit( db ) )
@@ -30,6 +30,8 @@
QgsTestUtils,
QgsFeatureSource,
QgsFieldConstraints,
QgsDataProvider,
QgsVectorLayerUtils,
NULL
)
from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant
@@ -1206,3 +1208,22 @@ def testGeneratedColumns(self):
feature = vl.getFeature(10)
self.assertTrue(feature.isValid())
self.assertEqual(feature.attribute(1), "test:10")

self.assertFalse(QgsVectorLayerUtils.fieldIsEditable(vl, 1, feature))
self.assertFalse(QgsVectorLayerUtils.fieldIsEditable(vl, 0, feature))

# Test insertion with default value evaluation on provider side to be sure
# it doesn't fail generated columns
vl.dataProvider().setProviderProperty(QgsDataProvider.EvaluateDefaultValues, True)

vl.startEditing()
feature = QgsVectorLayerUtils.createFeature(vl, QgsGeometry(), {0: 8})
vl.addFeature(feature)
self.assertTrue(feature.id() < 0)
# to be fixed
# self.assertEqual(QgsVectorLayerUtils.fieldIsEditable(vl, 1, feature), editable)
vl.commitChanges()

feature = vl.getFeature(8)
self.assertTrue(feature.isValid())
self.assertEqual(feature.attribute(1), "test:8")

0 comments on commit 9569a63

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