Skip to content
Permalink
Browse files

[Oracle] Don't reset srid to -1 when there is no geometry

  • Loading branch information
troopa81 authored and nyalldawson committed Feb 19, 2021
1 parent 9b6c0dd commit 209fad550502ec318c35506a5a7b3c7fcf2e1a32
@@ -628,7 +628,7 @@ void QgsOracleConn::retrieveLayerTypes( QgsOracleLayerProperty &layerProperty, b
if ( !onlyExistingTypes )
{
layerProperty.types << QgsWkbTypes::Unknown;
layerProperty.srids << ( srids.size() == 1 ? *srids.constBegin() : 0 );
layerProperty.srids << ( detectedSrid > 0 ? detectedSrid : ( srids.size() == 1 ? *srids.constBegin() : 0 ) );
}
}

@@ -2704,7 +2704,6 @@ bool QgsOracleProvider::getGeometryDetails()
}

detectedType = QgsWkbTypes::Unknown;
detectedSrid = -1;
}
else
{
@@ -2721,15 +2720,13 @@ bool QgsOracleProvider::getGeometryDetails()
{
// we need to filter
detectedType = QgsWkbTypes::Unknown;
detectedSrid = -1;
}
}
else
{
// geometry type undetermined or not unrequested
QgsMessageLog::logMessage( tr( "Feature type or srid for %1 of %2 could not be determined or was not requested." ).arg( mGeometryColumn ).arg( mQuery ) );
detectedType = QgsWkbTypes::Unknown;
detectedSrid = -1;
}
}
}
@@ -845,10 +845,32 @@ def testCreateEmptyLayer(self):
self.assertEqual(query.value(1), 4326)
query.finish()

vl = QgsVectorLayer(
self.dbconn + ' sslmode=disable table="QGIS"."EMPTY_LAYER" sql=',
'test', 'oracle')
# no feature, so we cannot guess the geometry type, so the layer is not valid
# but srid is set for provider in case you want to add a feature even if the layer is invalid!
# layer sourceCrs is empty because the layer is not considered spatial (not know geometry type)
vl = QgsVectorLayer(self.dbconn + ' sslmode=disable table="QGIS"."EMPTY_LAYER" (GEOM) sql=', 'test', 'oracle')
self.assertFalse(vl.isValid())
self.assertEqual(vl.dataProvider().sourceCrs().authid(), "EPSG:4326")

# so we set the geometry type
vl = QgsVectorLayer(self.dbconn + ' sslmode=disable type=POINT table="QGIS"."EMPTY_LAYER" (GEOM) sql=', 'test', 'oracle')
self.assertTrue(vl.isValid())
self.assertEqual(vl.sourceCrs().authid(), "EPSG:4326")

f = QgsFeature(vl.fields())
f.setGeometry(QgsGeometry.fromWkt('POINT (43.5 1.42)'))
vl.dataProvider().addFeatures([f])

query = QSqlQuery(self.conn)
self.assertTrue(query.exec_('SELECT "l"."GEOM"."SDO_SRID" from "QGIS"."EMPTY_LAYER" "l"'))
self.assertTrue(query.next())
self.assertEqual(query.value(0), 4326)
query.finish()

# now we can autodetect geom type and srid
vl = QgsVectorLayer(self.dbconn + ' sslmode=disable table="QGIS"."EMPTY_LAYER" (GEOM) sql=', 'test', 'oracle')
self.assertTrue(vl.isValid())
self.assertEqual(vl.sourceCrs().authid(), "EPSG:4326")

def testCreateAspatialLayer(self):
"""

0 comments on commit 209fad5

Please sign in to comment.