Skip to content
Permalink
Browse files
[MSSQL] Fix loading of layers in browser and dialog.
Add ODBC connection pooling
  • Loading branch information
NathanW2 committed Jun 13, 2014
1 parent d34b759 commit ea0e1b11ada50d72be2d98606da67dcb2fbb2bbd
Showing with 15 additions and 40 deletions.
  1. +1 −18 src/providers/mssql/qgsmssqldataitems.cpp
  2. +5 −0 src/providers/mssql/qgsmssqlprovider.cpp
  3. +9 −22 src/providers/mssql/qgsmssqlsourceselect.cpp
@@ -109,24 +109,7 @@ QVector<QgsDataItem*> QgsMssqlConnectionItem::createChildren()
return children;
}

QString connectionName;
if ( mService.isEmpty() )
{
if ( mHost.isEmpty() )
{
children.append( new QgsErrorItem( this, "QgsMssqlProvider host name not specified", mPath + "/error" ) );
return children;
}

if ( mDatabase.isEmpty() )
{
children.append( new QgsErrorItem( this, "QgsMssqlProvider database name not specified", mPath + "/error" ) );
return children;
}
connectionName = mHost + "." + mDatabase;
}
else
connectionName = mService;
QString connectionName = db.connectionName();

QgsMssqlGeomColumnTypeThread *columnTypeThread = 0;

@@ -87,6 +87,7 @@ QgsMssqlProvider::QgsMssqlProvider( QString uri )
if ( !OpenDatabase( mDatabase ) )
{
setLastError( mDatabase.lastError( ).text( ) );
QgsDebugMsg( mLastError );
mValid = false;
return;
}
@@ -225,7 +226,10 @@ QSqlDatabase QgsMssqlProvider::GetDatabase( QString service, QString host, QStri
connectionName = service;

if ( !QSqlDatabase::contains( connectionName ) )
{
db = QSqlDatabase::addDatabase( "QODBC", connectionName );
db.setConnectOptions("SQL_ATTR_CONNECTION_POOLING=SQL_CP_ONE_PER_HENV");
}
else
db = QSqlDatabase::database( connectionName );

@@ -263,6 +267,7 @@ QSqlDatabase QgsMssqlProvider::GetDatabase( QString service, QString host, QStri
db.setPassword( password );

db.setDatabaseName( connectionString );
QgsDebugMsg( connectionString );
return db;
}

@@ -497,7 +497,7 @@ void QgsMssqlSourceSelect::on_btnConnect_clicked()

mConnInfo = "dbname='" + database + "'";
if ( !host.isEmpty() )
mConnInfo += " host=" + host + "'";
mConnInfo += " host='" + host + "'";
if ( !username.isEmpty() )
mConnInfo += " user='" + username + "'";
if ( !password.isEmpty() )
@@ -516,27 +516,7 @@ void QgsMssqlSourceSelect::on_btnConnect_clicked()
return;
}

QString connectionName;
if ( service.isEmpty() )
{
if ( host.isEmpty() )
{
QMessageBox::warning( this,
tr( "MSSQL Provider" ), "QgsMssqlProvider host name not specified" );
return;
}

if ( database.isEmpty() )
{
QMessageBox::warning( this,
tr( "MSSQL Provider" ), "QgsMssqlProvider database name not specified" );
return;
}
connectionName = host + "." + database;
}
else
connectionName = service;

QString connectionName = db.connectionName();

// Read supported layers from database
QApplication::setOverrideCursor( Qt::WaitCursor );
@@ -784,6 +764,13 @@ void QgsMssqlGeomColumnTypeThread::run()

// issue the sql query
QSqlDatabase db = QSqlDatabase::database( mConnectionName );
if ( !QgsMssqlProvider::OpenDatabase( db ) )
{
QString msg = db.lastError().text();
QgsDebugMsg( msg );
continue;
}

QSqlQuery q = QSqlQuery( db );
q.setForwardOnly( true );
if ( !q.exec( query ) )

0 comments on commit ea0e1b1

Please sign in to comment.