Skip to content

Commit

Permalink
OGR/SQLite/GPKG pragma-defer_foreign_keys=ON
Browse files Browse the repository at this point in the history
When in transaction forces defer FK evaluation.
  • Loading branch information
elpaso committed Jun 30, 2021
1 parent 2745732 commit 3df8e58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/providers/ogr/qgsogrproviderutils.h
Expand Up @@ -270,6 +270,7 @@ class CORE_EXPORT QgsOgrProviderUtils
class QgsOgrDataset
{
friend class QgsOgrProviderUtils;
friend class QgsOgrTransaction;
QgsOgrProviderUtils::DatasetIdentification mIdent;
QgsOgrProviderUtils::DatasetWithLayers *mDs;

Expand Down
10 changes: 10 additions & 0 deletions src/core/providers/ogr/qgsogrtransaction.cpp
Expand Up @@ -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 );
}

Expand Down

0 comments on commit 3df8e58

Please sign in to comment.