Skip to content

Commit

Permalink
Merge pull request #40107 from rduivenvoorde/39855_diminfo_param_take2
Browse files Browse the repository at this point in the history
Fix for diminfo as string in Oracle mdsys metadata query
  • Loading branch information
m-kuhn committed Nov 20, 2020
2 parents 78825cf + ed53ea5 commit ca637cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/providers/oracle/qgsoracleprovider.cpp
Expand Up @@ -3093,8 +3093,8 @@ QgsVectorLayerExporter::ExportError QgsOracleProvider::createEmptyLayer(
}
}

if ( !exec( qry, QString( "INSERT INTO mdsys.user_sdo_geom_metadata(table_name,column_name,srid,diminfo) VALUES (?,?,?,?)" ),
QVariantList() << tableName.toUpper() << geometryColumn.toUpper() << srid << diminfo ) )
if ( !exec( qry, QStringLiteral( "INSERT INTO mdsys.user_sdo_geom_metadata(table_name,column_name,srid,diminfo) VALUES (?,?,?,%1)" ).arg( diminfo ),
QVariantList() << tableName.toUpper() << geometryColumn.toUpper() << srid ) )
{
throw OracleException( tr( "Could not insert metadata." ), qry );
}
Expand Down
20 changes: 19 additions & 1 deletion tests/src/python/test_provider_oracle.py
Expand Up @@ -24,7 +24,10 @@
QgsFeature,
QgsGeometry,
QgsWkbTypes,
QgsDataProvider
QgsDataProvider,
QgsVectorLayerExporter,
QgsFields,
QgsCoordinateReferenceSystem
)

from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant
Expand Down Expand Up @@ -819,6 +822,21 @@ def testEvaluateDefaultValues(self):
attributes = [feat.attributes() for feat in vl.getFeatures()]
self.assertEqual(attributes, [[1, 'qgis'], [2, 'test'], [3, 'qgis'], [4, 'test']])

def testCreateEmptyLayer(self):
uri = self.dbconn + "srid=4326 type=POINT table=\"EMPTY_LAYER\" (GEOM)"
exporter = QgsVectorLayerExporter(uri=uri, provider='oracle', fields=QgsFields(), geometryType=QgsWkbTypes.Point, crs=QgsCoordinateReferenceSystem(4326), overwrite=True)
self.assertEqual(exporter.errorCount(), 0)
self.assertEqual(exporter.errorCode(), 0)
# check IF there is an empty table (will throw error if the EMPTY_LAYER table does not excist)
self.execSQLCommand('SELECT count(*) FROM "QGIS"."EMPTY_LAYER"')
vl = QgsVectorLayer(
self.dbconn + ' sslmode=disable table="QGIS"."EMPTY_LAYER" sql=',
'test', 'oracle')
self.assertTrue(vl.isValid())
# cleanup
self.execSQLCommand('DROP TABLE "QGIS"."EMPTY_LAYER"')
self.execSQLCommand("DELETE FROM user_sdo_geom_metadata where TABLE_NAME='EMPTY_LAYER'")


if __name__ == '__main__':
unittest.main()

0 comments on commit ca637cf

Please sign in to comment.