Skip to content

Commit 7c27a5b

Browse files
committed
[mssql] Fix connection ID used by column type thread
1 parent 9958c0b commit 7c27a5b

5 files changed

+18
-11
lines changed

src/providers/mssql/qgsmssqldataitems.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ QVector<QgsDataItem *> QgsMssqlConnectionItem::createChildren()
220220
{
221221
if ( !mColumnTypeThread )
222222
{
223-
mColumnTypeThread = new QgsMssqlGeomColumnTypeThread(
224-
connectionName, true /* use estimated metadata */ );
223+
mColumnTypeThread = new QgsMssqlGeomColumnTypeThread( mService, mHost, mDatabase, mUsername, mPassword, true /* use estimated metadata */ );
225224

226225
connect( mColumnTypeThread, &QgsMssqlGeomColumnTypeThread::setLayerType,
227226
this, &QgsMssqlConnectionItem::setLayerType );

src/providers/mssql/qgsmssqlgeomcolumntypethread.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
#include "qgslogger.h"
2121
#include "qgsmssqlprovider.h"
2222

23-
QgsMssqlGeomColumnTypeThread::QgsMssqlGeomColumnTypeThread( const QString &connectionName, bool useEstimatedMetadata )
24-
: mConnectionName( connectionName )
23+
QgsMssqlGeomColumnTypeThread::QgsMssqlGeomColumnTypeThread( const QString &service, const QString &host, const QString &database, const QString &username, const QString &password, bool useEstimatedMetadata )
24+
: mService( service )
25+
, mHost( host )
26+
, mDatabase( database )
27+
, mUsername( username )
28+
, mPassword( password )
2529
, mUseEstimatedMetadata( useEstimatedMetadata )
2630
, mStopped( false )
2731
{
@@ -67,7 +71,7 @@ void QgsMssqlGeomColumnTypeThread::run()
6771
layerProperty.sql.isEmpty() ? QString() : QStringLiteral( " AND %1" ).arg( layerProperty.sql ) );
6872

6973
// issue the sql query
70-
QSqlDatabase db = QSqlDatabase::database( QgsMssqlProvider::dbConnectionName( mConnectionName ) );
74+
QSqlDatabase db = QgsMssqlProvider::GetDatabase( mService, mHost, mDatabase, mUsername, mPassword );
7175
if ( !QgsMssqlProvider::OpenDatabase( db ) )
7276
{
7377
QgsDebugMsg( db.lastError().text() );

src/providers/mssql/qgsmssqlgeomcolumntypethread.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class QgsMssqlGeomColumnTypeThread : public QThread
2727
{
2828
Q_OBJECT
2929
public:
30-
QgsMssqlGeomColumnTypeThread( const QString &connectionName, bool useEstimatedMetadata );
30+
QgsMssqlGeomColumnTypeThread( const QString &service, const QString &host, const QString &database, const QString &username, const QString &password, bool useEstimatedMetadata );
3131

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

46-
QString mConnectionName;
46+
QString mService;
47+
QString mHost;
48+
QString mDatabase;
49+
QString mUsername;
50+
QString mPassword;
4751
bool mUseEstimatedMetadata;
4852
bool mStopped;
4953
QList<QgsMssqlLayerProperty> layerProperties;

src/providers/mssql/qgsmssqlsourceselect.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ void QgsMssqlSourceSelect::btnConnect_clicked()
588588
{
589589
if ( type == QLatin1String( "GEOMETRY" ) || type.isNull() || srid.isEmpty() )
590590
{
591-
addSearchGeometryColumn( connectionName, layer, estimateMetadata );
591+
addSearchGeometryColumn( service, host, database, username, password, layer, estimateMetadata );
592592
type.clear();
593593
srid.clear();
594594
}
@@ -690,12 +690,12 @@ void QgsMssqlSourceSelect::setSql( const QModelIndex &index )
690690
}
691691
}
692692

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

700700
connect( mColumnTypeThread, &QgsMssqlGeomColumnTypeThread::setLayerType,
701701
this, &QgsMssqlSourceSelect::setLayerType );

src/providers/mssql/qgsmssqlsourceselect.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class QgsMssqlSourceSelect : public QgsAbstractDataSourceWidget, private Ui::Qgs
129129
typedef QList<geomPair> geomCol;
130130

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

134134
// Set the position of the database connection list to the last
135135
// used one.

0 commit comments

Comments
 (0)