Skip to content

Commit

Permalink
Fix Oracle crazyness
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 10, 2022
1 parent 724f82e commit 148848e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
33 changes: 30 additions & 3 deletions tests/src/python/stylestoragebase.py
Expand Up @@ -51,6 +51,16 @@ def layerUri(self, conn, schema_name, table_name):

return conn.tableUri(schema_name, table_name)

def schemaName(self):
"""Providers may override (Oracle?)"""

return 'test_styles_schema'

def tableName(self):
"""Providers may override (Oracle?)"""

return 'test_styles_table'

def testMultipleStyles(self):

md = QgsProviderRegistry.instance().providerMetadata(self.providerKey)
Expand All @@ -65,7 +75,7 @@ def testMultipleStyles(self):
and capabilities & QgsAbstractDatabaseProviderConnection.Schemas
and capabilities & QgsAbstractDatabaseProviderConnection.DropSchema):

schema = 'testStyles'
schema = self.schemaName()
# Start clean
if schema in conn.schemas():
conn.dropSchema(schema, True)
Expand All @@ -75,15 +85,32 @@ def testMultipleStyles(self):
schemas = conn.schemas()
self.assertTrue(schema in schemas)

elif (capabilities & QgsAbstractDatabaseProviderConnection.Schemas):
schema = self.schemaName()

try:
conn.dropVectorTable(schema, self.tableName())
except:
pass

try:
conn.createSchema(schema)
except:
pass

schemas = conn.schemas()
self.assertTrue(schema in schemas)

fields = QgsFields()
fields.append(QgsField("string_t", QVariant.String))
options = {}
crs = QgsCoordinateReferenceSystem.fromEpsgId(4326)
typ = QgsWkbTypes.Point

# Create table
conn.createVectorTable(schema, 'test_styles', fields, typ, crs, True, options)
uri = self.layerUri(conn, schema, 'test_styles')
conn.createVectorTable(schema, self.tableName(), fields, typ, crs, True, options)

uri = self.layerUri(conn, schema, self.tableName())

vl = QgsVectorLayer(uri, 'vl', self.providerKey)
self.assertTrue(vl.isValid())
Expand Down
17 changes: 16 additions & 1 deletion tests/src/python/test_stylestorage_oracle.py
Expand Up @@ -16,7 +16,8 @@
from stylestoragebase import StyleStorageTestBase, StyleStorageTestCaseBase
from qgis.PyQt.QtCore import QTemporaryDir
from qgis.core import (
QgsDataSourceUri
QgsDataSourceUri,
QgsProviderRegistry,
)
from qgis.testing import unittest

Expand All @@ -35,6 +36,20 @@ def setUp(self):

self.uri = dbconn

md = QgsProviderRegistry.instance().providerMetadata(self.providerKey)
md.createConnection(self.uri, {})
conn = md.createConnection(self.uri, {})
conn.executeSql('DELETE FROM mdsys.sdo_geom_metadata_table WHERE sdo_table_name = \'TEST_STYLES\'')

def schemaName(self):

return QgsDataSourceUri(self.uri).param('username')

def tableName(self):
"""Providers may override (Oracle?)"""

return 'TEST_STYLES_TABLE'

def layerUri(self, conn, schema_name, table_name):
"""Providers may override if they need more complex URI generation than
what tableUri() offers"""
Expand Down

0 comments on commit 148848e

Please sign in to comment.