Skip to content
Permalink
Browse files

[mssql] Fix connection ID used by column type thread

  • Loading branch information
nyalldawson committed Oct 2, 2018
1 parent 9958c0b commit 7c27a5b4017c17bdf9d5cb26f10634591e7cfa38
@@ -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 );
@@ -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 )
{
@@ -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() );
@@ -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.
@@ -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;
@@ -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();
}
@@ -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 );
@@ -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.

0 comments on commit 7c27a5b

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