Skip to content

Commit 148848e

Browse files
committedNov 10, 2022
Fix Oracle crazyness
1 parent 724f82e commit 148848e

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed
 

‎tests/src/python/stylestoragebase.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ def layerUri(self, conn, schema_name, table_name):
5151

5252
return conn.tableUri(schema_name, table_name)
5353

54+
def schemaName(self):
55+
"""Providers may override (Oracle?)"""
56+
57+
return 'test_styles_schema'
58+
59+
def tableName(self):
60+
"""Providers may override (Oracle?)"""
61+
62+
return 'test_styles_table'
63+
5464
def testMultipleStyles(self):
5565

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

68-
schema = 'testStyles'
78+
schema = self.schemaName()
6979
# Start clean
7080
if schema in conn.schemas():
7181
conn.dropSchema(schema, True)
@@ -75,15 +85,32 @@ def testMultipleStyles(self):
7585
schemas = conn.schemas()
7686
self.assertTrue(schema in schemas)
7787

88+
elif (capabilities & QgsAbstractDatabaseProviderConnection.Schemas):
89+
schema = self.schemaName()
90+
91+
try:
92+
conn.dropVectorTable(schema, self.tableName())
93+
except:
94+
pass
95+
96+
try:
97+
conn.createSchema(schema)
98+
except:
99+
pass
100+
101+
schemas = conn.schemas()
102+
self.assertTrue(schema in schemas)
103+
78104
fields = QgsFields()
79105
fields.append(QgsField("string_t", QVariant.String))
80106
options = {}
81107
crs = QgsCoordinateReferenceSystem.fromEpsgId(4326)
82108
typ = QgsWkbTypes.Point
83109

84110
# Create table
85-
conn.createVectorTable(schema, 'test_styles', fields, typ, crs, True, options)
86-
uri = self.layerUri(conn, schema, 'test_styles')
111+
conn.createVectorTable(schema, self.tableName(), fields, typ, crs, True, options)
112+
113+
uri = self.layerUri(conn, schema, self.tableName())
87114

88115
vl = QgsVectorLayer(uri, 'vl', self.providerKey)
89116
self.assertTrue(vl.isValid())

‎tests/src/python/test_stylestorage_oracle.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
from stylestoragebase import StyleStorageTestBase, StyleStorageTestCaseBase
1717
from qgis.PyQt.QtCore import QTemporaryDir
1818
from qgis.core import (
19-
QgsDataSourceUri
19+
QgsDataSourceUri,
20+
QgsProviderRegistry,
2021
)
2122
from qgis.testing import unittest
2223

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

3637
self.uri = dbconn
3738

39+
md = QgsProviderRegistry.instance().providerMetadata(self.providerKey)
40+
md.createConnection(self.uri, {})
41+
conn = md.createConnection(self.uri, {})
42+
conn.executeSql('DELETE FROM mdsys.sdo_geom_metadata_table WHERE sdo_table_name = \'TEST_STYLES\'')
43+
44+
def schemaName(self):
45+
46+
return QgsDataSourceUri(self.uri).param('username')
47+
48+
def tableName(self):
49+
"""Providers may override (Oracle?)"""
50+
51+
return 'TEST_STYLES_TABLE'
52+
3853
def layerUri(self, conn, schema_name, table_name):
3954
"""Providers may override if they need more complex URI generation than
4055
what tableUri() offers"""

0 commit comments

Comments
 (0)
Please sign in to comment.