Skip to content
Permalink
Browse files

[mssql] Followup a76359, fix provider methods like featureCount,

uniqueValues, etc not working when using DSN for connection
  • Loading branch information
nyalldawson committed May 29, 2017
1 parent 67d778f commit fcafc82162c61e3ee8b7e9dd913e5c4c0073af6d
Showing with 39 additions and 1 deletion.
  1. +38 −0 src/providers/mssql/qgsmssqlprovider.cpp
  2. +1 −1 src/providers/mssql/qgsmssqlprovider.h
@@ -350,6 +350,11 @@ void QgsMssqlProvider::loadMetadata()
mSRId = 0;
mWkbType = QGis::WKBUnknown;

if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}

QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
if ( !query.exec( QString( "select f_geometry_column, coord_dimension, srid, geometry_type from geometry_columns where f_table_schema = '%1' and f_table_name = '%2'" ).arg( mSchemaName, mTableName ) ) )
@@ -368,7 +373,12 @@ void QgsMssqlProvider::loadFields()
{
mAttributeFields.clear();
mDefaultValues.clear();

// get field spec
if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
if ( !query.exec( QString( "exec sp_columns @table_name = N'%1', @table_owner = '%2'" ).arg( mTableName, mSchemaName ) ) )
@@ -532,6 +542,10 @@ QVariant QgsMssqlProvider::minimumValue( int index )
sql += QString( " where (%1)" ).arg( mSqlWhereClause );
}

if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );

@@ -563,6 +577,10 @@ QVariant QgsMssqlProvider::maximumValue( int index )
sql += QString( " where (%1)" ).arg( mSqlWhereClause );
}

if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );

@@ -603,6 +621,10 @@ void QgsMssqlProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, i
sql += QString( " where (%1)" ).arg( mSqlWhereClause );
}

if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );

@@ -631,6 +653,10 @@ void QgsMssqlProvider::UpdateStatistics( bool estimate )
// get features to calculate the statistics
QString statement;

if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );

@@ -758,6 +784,10 @@ long QgsMssqlProvider::featureCount() const

// If there is no subset set we can get the count from the system tables.
// Which is faster then doing select count(*)
if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );

@@ -1419,6 +1449,10 @@ QgsCoordinateReferenceSystem QgsMssqlProvider::crs()
return mCrs;

// try to load crs from the database tables as a fallback
if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
bool execOk = query.exec( QString( "select srtext from spatial_ref_sys where srid = %1" ).arg( QString::number( mSRId ) ) );
@@ -1472,6 +1506,10 @@ bool QgsMssqlProvider::setSubsetString( const QString& theSQL, bool )
sql += QString( " where %1" ).arg( mSqlWhereClause );
}

if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
if ( !query.exec( sql ) )
@@ -290,7 +290,7 @@ class QgsMssqlProvider : public QgsVectorDataProvider
QGis::WkbType mWkbType;

// The database object
QSqlDatabase mDatabase;
mutable QSqlDatabase mDatabase;

// The current sql query
QSqlQuery mQuery;

0 comments on commit fcafc82

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