Skip to content
Permalink
Browse files

Fix #11208 - Error when saving MSSQL layer when using DSN

  • Loading branch information
NathanW2 committed Oct 23, 2014
1 parent 8e2def5 commit a763594432aec48c72e7c574c9faf70a074d7a8e
Showing with 33 additions and 0 deletions.
  1. +33 −0 src/providers/mssql/qgsmssqlprovider.cpp
@@ -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 );

@@ -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 ) )
@@ -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 );

@@ -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 );

@@ -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 );

@@ -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;
@@ -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;
@@ -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;

0 comments on commit a763594

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