Skip to content

Commit

Permalink
Fix #11208 - Error when saving MSSQL layer when using DSN
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Oct 23, 2014
1 parent 8e2def5 commit a763594
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/providers/mssql/qgsmssqlprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,10 @@ bool QgsMssqlProvider::addFeatures( QgsFeatureList & flist )
statement = QString( "INSERT INTO [%1].[%2] (" ).arg( mSchemaName, mTableName );

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

Expand Down Expand Up @@ -951,6 +955,10 @@ bool QgsMssqlProvider::addAttributes( const QList<QgsField> &attributes )
statement += QString( "[%1] %2" ).arg( it->name(), type );
}

if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
if ( !query.exec( statement ) )
Expand Down Expand Up @@ -979,6 +987,11 @@ bool QgsMssqlProvider::deleteAttributes( const QgsAttributeIds &attributes )
statement += QString( "[%1]" ).arg( mAttributeFields[*it].name() );
}

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

QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );

Expand Down Expand Up @@ -1015,6 +1028,10 @@ bool QgsMssqlProvider::changeAttributeValues( const QgsChangedAttributesMap & at
statement = QString( "UPDATE [%1].[%2] SET " ).arg( mSchemaName, mTableName );

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

Expand Down Expand Up @@ -1121,6 +1138,10 @@ bool QgsMssqlProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
QString statement;
statement = QString( "UPDATE [%1].[%2] SET " ).arg( mSchemaName, mTableName );

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

Expand Down Expand Up @@ -1190,6 +1211,10 @@ bool QgsMssqlProvider::deleteFeatures( const QgsFeatureIds & id )
featureIds += "," + FID_TO_STRING( *it );
}

if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
QString statement;
Expand Down Expand Up @@ -1221,6 +1246,10 @@ bool QgsMssqlProvider::createSpatialIndex()
if ( mUseEstimatedMetadata )
UpdateStatistics( false );

if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
QString statement;
Expand Down Expand Up @@ -1250,6 +1279,10 @@ bool QgsMssqlProvider::createSpatialIndex()

bool QgsMssqlProvider::createAttributeIndex( int field )
{
if ( !mDatabase.isOpen() )
{
mDatabase = GetDatabase( mService, mHost, mDatabaseName, mUserName, mPassword );
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
QString statement;
Expand Down

0 comments on commit a763594

Please sign in to comment.