Skip to content

Commit

Permalink
[mssql] Fix connection ID used by column type thread
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 2, 2018
1 parent 9958c0b commit 7c27a5b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/providers/mssql/qgsmssqldataitems.cpp
Expand Up @@ -220,8 +220,7 @@ QVector<QgsDataItem *> QgsMssqlConnectionItem::createChildren()
{
if ( !mColumnTypeThread )
{
mColumnTypeThread = new QgsMssqlGeomColumnTypeThread(
connectionName, true /* use estimated metadata */ );
mColumnTypeThread = new QgsMssqlGeomColumnTypeThread( mService, mHost, mDatabase, mUsername, mPassword, true /* use estimated metadata */ );

connect( mColumnTypeThread, &QgsMssqlGeomColumnTypeThread::setLayerType,
this, &QgsMssqlConnectionItem::setLayerType );
Expand Down
10 changes: 7 additions & 3 deletions src/providers/mssql/qgsmssqlgeomcolumntypethread.cpp
Expand Up @@ -20,8 +20,12 @@
#include "qgslogger.h"
#include "qgsmssqlprovider.h"

QgsMssqlGeomColumnTypeThread::QgsMssqlGeomColumnTypeThread( const QString &connectionName, bool useEstimatedMetadata )
: mConnectionName( connectionName )
QgsMssqlGeomColumnTypeThread::QgsMssqlGeomColumnTypeThread( const QString &service, const QString &host, const QString &database, const QString &username, const QString &password, bool useEstimatedMetadata )
: mService( service )
, mHost( host )
, mDatabase( database )
, mUsername( username )
, mPassword( password )
, mUseEstimatedMetadata( useEstimatedMetadata )
, mStopped( false )
{
Expand Down Expand Up @@ -67,7 +71,7 @@ void QgsMssqlGeomColumnTypeThread::run()
layerProperty.sql.isEmpty() ? QString() : QStringLiteral( " AND %1" ).arg( layerProperty.sql ) );

// issue the sql query
QSqlDatabase db = QSqlDatabase::database( QgsMssqlProvider::dbConnectionName( mConnectionName ) );
QSqlDatabase db = QgsMssqlProvider::GetDatabase( mService, mHost, mDatabase, mUsername, mPassword );
if ( !QgsMssqlProvider::OpenDatabase( db ) )
{
QgsDebugMsg( db.lastError().text() );
Expand Down
8 changes: 6 additions & 2 deletions src/providers/mssql/qgsmssqlgeomcolumntypethread.h
Expand Up @@ -27,7 +27,7 @@ class QgsMssqlGeomColumnTypeThread : public QThread
{
Q_OBJECT
public:
QgsMssqlGeomColumnTypeThread( const QString &connectionName, bool useEstimatedMetadata );
QgsMssqlGeomColumnTypeThread( const QString &service, const QString &host, const QString &database, const QString &username, const QString &password, bool useEstimatedMetadata );

// These functions get the layer types and pass that information out
// by emitting the setLayerType() signal.
Expand All @@ -43,7 +43,11 @@ class QgsMssqlGeomColumnTypeThread : public QThread
private:
QgsMssqlGeomColumnTypeThread() = delete;

QString mConnectionName;
QString mService;
QString mHost;
QString mDatabase;
QString mUsername;
QString mPassword;
bool mUseEstimatedMetadata;
bool mStopped;
QList<QgsMssqlLayerProperty> layerProperties;
Expand Down
6 changes: 3 additions & 3 deletions src/providers/mssql/qgsmssqlsourceselect.cpp
Expand Up @@ -588,7 +588,7 @@ void QgsMssqlSourceSelect::btnConnect_clicked()
{
if ( type == QLatin1String( "GEOMETRY" ) || type.isNull() || srid.isEmpty() )
{
addSearchGeometryColumn( connectionName, layer, estimateMetadata );
addSearchGeometryColumn( service, host, database, username, password, layer, estimateMetadata );
type.clear();
srid.clear();
}
Expand Down Expand Up @@ -690,12 +690,12 @@ void QgsMssqlSourceSelect::setSql( const QModelIndex &index )
}
}

void QgsMssqlSourceSelect::addSearchGeometryColumn( const QString &connectionName, const QgsMssqlLayerProperty &layerProperty, bool estimateMetadata )
void QgsMssqlSourceSelect::addSearchGeometryColumn( const QString &service, const QString &host, const QString &database, const QString &username, const QString &password, const QgsMssqlLayerProperty &layerProperty, bool estimateMetadata )
{
// store the column details and do the query in a thread
if ( !mColumnTypeThread )
{
mColumnTypeThread = new QgsMssqlGeomColumnTypeThread( connectionName, estimateMetadata );
mColumnTypeThread = new QgsMssqlGeomColumnTypeThread( service, host, database, username, password, estimateMetadata );

connect( mColumnTypeThread, &QgsMssqlGeomColumnTypeThread::setLayerType,
this, &QgsMssqlSourceSelect::setLayerType );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mssql/qgsmssqlsourceselect.h
Expand Up @@ -129,7 +129,7 @@ class QgsMssqlSourceSelect : public QgsAbstractDataSourceWidget, private Ui::Qgs
typedef QList<geomPair> geomCol;

// queue another query for the thread
void addSearchGeometryColumn( const QString &connectionName, const QgsMssqlLayerProperty &layerProperty, bool estimateMetadata );
void addSearchGeometryColumn( const QString &service, const QString &host, const QString &database, const QString &username, const QString &password, const QgsMssqlLayerProperty &layerProperty, bool estimateMetadata );

// Set the position of the database connection list to the last
// used one.
Expand Down

0 comments on commit 7c27a5b

Please sign in to comment.