Skip to content
Permalink
Browse files
More tests for execSql
  • Loading branch information
elpaso committed Jul 6, 2021
1 parent 2c123dc commit 5d5e828d80c349b9a8798cb5c2c1da2032bb7d5b
@@ -271,7 +271,6 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsMssqlProviderConnection::e
{
results.appendColumn( rec.field( idx ).name() );
}
iterator->nextRow();
return results;
}

@@ -280,6 +279,15 @@ QgsAbstractDatabaseProviderConnection::QueryResult QgsMssqlProviderConnection::e
}


QgssMssqlProviderResultIterator::QgssMssqlProviderResultIterator( bool resolveTypes, int columnCount, const QSqlQuery &query )
: mResolveTypes( resolveTypes )
, mColumnCount( columnCount )
, mQuery( query )
{
// Load first row
nextRow();
}

QVariantList QgssMssqlProviderResultIterator::nextRowPrivate()
{
const QVariantList currentRow = mNextRow;
@@ -25,11 +25,7 @@
struct QgssMssqlProviderResultIterator: public QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator
{

QgssMssqlProviderResultIterator( bool resolveTypes, int columnCount, const QSqlQuery &query )
: mResolveTypes( resolveTypes )
, mColumnCount( columnCount )
, mQuery( query )
{}
QgssMssqlProviderResultIterator( bool resolveTypes, int columnCount, const QSqlQuery &query );

private:

@@ -113,7 +113,7 @@ void QgsOracleProviderConnection::setDefaultCapabilities()
Capability::DeleteSpatialIndex,
Capability::DeleteField,
Capability::DeleteFieldCascade,
Capability::AddField
Capability::AddField,
};
mGeometryColumnCapabilities =
{
@@ -19,6 +19,7 @@
QgsVectorLayer,
QgsProviderRegistry,
QgsDataSourceUri,
QgsAbstractDatabaseProviderConnection,
)
from qgis.testing import unittest

@@ -126,6 +127,22 @@ def test_schemas_filtering(self):
self.assertEqual(len(schemas), 1)
self.assertEqual(schemas, ['qgis_test'])

def test_exec_sql(self):

md = QgsProviderRegistry.instance().providerMetadata('mssql')
conn = md.createConnection(self.uri, {})

results = conn.executeSql('select * from qgis_test.some_poly_data')

rows = []
results2 = conn.execSql('select * from qgis_test.some_poly_data')

while results2.hasNextRow():
rows.append(results2.nextRow())

self.assertEqual(len(rows), 4)
self.assertEqual(rows, results)


if __name__ == '__main__':
unittest.main()
@@ -19,7 +19,9 @@
QgsVectorLayer,
QgsProviderRegistry,
QgsDataSourceUri,
QgsAbstractDatabaseProviderConnection
QgsAbstractDatabaseProviderConnection,
QgsProviderConnectionException,

)
from qgis.testing import unittest
from qgis.PyQt.QtSql import QSqlDatabase, QSqlQuery
@@ -44,6 +46,14 @@ class TestPyQgsProviderConnectionOracle(unittest.TestCase, TestPyQgsProviderConn
myUtf8Table = 'MYUTF8\U0001F604TABLE'
geometryColumnName = 'GEOM'

def execSQLCommand(self, sql, ignore_errors=False):
self.assertTrue(self.conn)
query = QSqlQuery(self.conn)
res = query.exec_(sql)
if not ignore_errors:
self.assertTrue(res, sql + ': ' + query.lastError().text())
query.finish()

@classmethod
def setUpClass(cls):
"""Run before all tests"""
@@ -63,15 +73,24 @@ def setUpClass(cls):
cls.conn.setDatabaseName(os.environ['QGIS_ORACLETEST_DBNAME'])
cls.conn.setUserName('QGIS')
cls.conn.setPassword('qgis')
assert cls.conn.open()

def execSQLCommand(self, sql, ignore_errors=False):
self.assertTrue(self.conn)
query = QSqlQuery(self.conn)
res = query.exec_(sql)
if not ignore_errors:
self.assertTrue(res, sql + ': ' + query.lastError().text())
query.finish()
# Start clean
md = QgsProviderRegistry.instance().providerMetadata('oracle')
conn = md.createConnection(cls.dbconn, {})

for table_name in (cls.myNewTable, cls.myVeryNewTable):

try:
conn.dropVectorTable('QGIS', table_name)
except QgsProviderConnectionException:
pass

try:
conn.executeSql(f"DELETE FROM user_sdo_geom_metadata WHERE TABLE_NAME = '{table_name}'")
except QgsProviderConnectionException:
pass

assert cls.conn.open()

def test_tables_with_options(self):

0 comments on commit 5d5e828

Please sign in to comment.