Skip to content
Permalink
Browse files
OGR/SQLite/GPKG pragma-defer_foreign_keys=ON
When in transaction forces defer FK evaluation.
  • Loading branch information
elpaso committed Jun 30, 2021
1 parent 2745732 commit 3df8e5856736eea80356a8cf92359f88f06805ff
Showing with 11 additions and 0 deletions.
  1. +1 −0 src/core/providers/ogr/qgsogrproviderutils.h
  2. +10 −0 src/core/providers/ogr/qgsogrtransaction.cpp
@@ -270,6 +270,7 @@ class CORE_EXPORT QgsOgrProviderUtils
class QgsOgrDataset
{
friend class QgsOgrProviderUtils;
friend class QgsOgrTransaction;
QgsOgrProviderUtils::DatasetIdentification mIdent;
QgsOgrProviderUtils::DatasetWithLayers *mDs;

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

0 comments on commit 3df8e58

Please sign in to comment.