Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #43989 from elpaso/ogr-sqlite-pragma-defer_foreign…
…_keys-on

OGR/SQLite/GPKG pragma-defer_foreign_keys=ON
  • Loading branch information
elpaso committed Jul 2, 2021
2 parents c8156b0 + 3df8e58 commit 6031e75
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 6031e75

Please sign in to comment.