Merge pull request #43989 from elpaso/ogr-sqlite-pragma-defer_foreign_keys-on

OGR/SQLite/GPKG pragma-defer_foreign_keys=ON
This commit is contained in:
Alessandro Pasotti 2021-07-02 16:16:09 +02:00 committed by GitHub
commit 6031e7546f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -270,6 +270,7 @@ class CORE_EXPORT QgsOgrProviderUtils
class QgsOgrDataset
{
friend class QgsOgrProviderUtils;
friend class QgsOgrTransaction;
QgsOgrProviderUtils::DatasetIdentification mIdent;
QgsOgrProviderUtils::DatasetWithLayers *mDs;

View File

@ -31,6 +31,16 @@ QgsOgrTransaction::QgsOgrTransaction( const QString &connString, QgsOgrDatasetSh
bool QgsOgrTransaction::beginTransaction( QString &error, int /* statementTimeout */ )
{
GDALDriverH hDriver = GDALGetDatasetDriver( mSharedDS.get()->mDs->hDS );
const QString driverName = GDALGetDriverShortName( hDriver );
if ( driverName == QLatin1String( "GPKG" ) || driverName == QLatin1String( "SQLite" ) )
{
QString fkDeferError;
if ( ! executeSql( QStringLiteral( "PRAGMA defer_foreign_keys = ON" ), fkDeferError ) )
{
QgsDebugMsg( QStringLiteral( "Error setting PRAGMA defer_foreign_keys = ON: %1" ).arg( fkDeferError ) );
}
}
return executeSql( QStringLiteral( "BEGIN" ), error );
}