Skip to content
Permalink
Browse files

Use connections API for creating tables

  • Loading branch information
elpaso committed Jul 16, 2020
1 parent 9d1d88d commit 9a17d9355a9f84e79c8c9814e402986a97fd8f63
Showing with 7 additions and 19 deletions.
  1. +7 −19 tests/src/python/test_provider_mssql.py
@@ -23,12 +23,12 @@
QgsGeometry,
QgsPointXY,
QgsRectangle,
QgsProviderRegistry,
NULL,
QgsVectorLayerExporter,
QgsCoordinateReferenceSystem)

from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant
from qgis.PyQt.QtSql import QSqlDatabase, QSqlQuery
from utilities import unitTestDataPath
from qgis.testing import start_app, unittest
from providertestbase import ProviderTestCase
@@ -58,24 +58,14 @@ def setUpClass(cls):
assert cls.poly_vl.isValid(), cls.poly_vl.dataProvider().error().message()
cls.poly_provider = cls.poly_vl.dataProvider()

cls.conn = QSqlDatabase.addDatabase('QODBC')
cls.conn.setDatabaseName('testsqlserver')
if 'QGIS_MSSQLTEST_DB2' in os.environ:
print(os.environ['QGIS_MSSQLTEST_DB2'])
cls.conn.setDatabaseName(os.environ['QGIS_MSSQLTEST_DB2'])
elif 'QGIS_MSSQLTEST_DB' in os.environ:
print(os.environ['QGIS_MSSQLTEST_DB'])
cls.conn.setDatabaseName(os.environ['QGIS_MSSQLTEST_DB'])
else:
cls.conn.setUserName('SA')
cls.conn.setPassword('<YourStrong!Passw0rd>')

assert cls.conn.open(), cls.conn.lastError().text()

# Triggers a segfault in the sql server odbc driver on Travis - TODO test with more recent Ubuntu base image
if os.environ.get('TRAVIS', '') == 'true':
del cls.getEditableLayer

# Use connections API
md = QgsProviderRegistry.instance().providerMetadata('mssql')
cls.conn_api = md.createConnection(cls.dbconn, {})

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
@@ -86,10 +76,8 @@ def setUp(self):
self.execSQLCommand('DROP TABLE IF EXISTS qgis_test.[{}]'.format(t))

def execSQLCommand(self, sql):
self.assertTrue(self.conn)
query = QSqlQuery(self.conn)
self.assertTrue(query.exec_(sql), sql + ': ' + query.lastError().text())
query.finish()
self.assertTrue(self.conn_api)
self.conn_api.executeSql(sql)

def getSource(self):
# create temporary table for edit tests

0 comments on commit 9a17d93

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