From 7d8dfaa51ad1f4ba03c67629fbf18e6a223fd1a4 Mon Sep 17 00:00:00 2001 From: Ilmo Raunio Date: Sat, 22 May 2021 05:47:15 +0300 Subject: [PATCH] feat(ios): Harmonize foreign key enforcing (#98) --- README.md | 4 ++-- ios/RNSqlite2.m | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f493d5e..29cf5cc 100644 --- a/README.md +++ b/README.md @@ -102,9 +102,9 @@ PouchDB.plugin(SQLiteAdapter); var db = new PouchDB("mydb", { adapter: "react-native-sqlite" }); ``` -### Foreign key support on Android +### Foreign key support -As part of database initialization, this library will enable foreign key support automatically on Android devices, due to the fact that Android will not respect a PRAGMA statement to enable or disable them after it has been opened. Thus, any tables that define foreign key constraints will have them enforced whether or not foreign key support is explicitly enabled/disabled by PRAGMA statements sent via SQL. +As part of database initialization, this library will enable foreign key support automatically on both iOS & Android. Thus, any tables that define foreign key constraints will have them enforced whether or not foreign key support is explicitly enabled/disabled by PRAGMA statements sent via SQL. ## Changelog diff --git a/ios/RNSqlite2.m b/ios/RNSqlite2.m index 809c110..2750842 100644 --- a/ios/RNSqlite2.m +++ b/ios/RNSqlite2.m @@ -79,6 +79,7 @@ -(NSValue*)openDatabase: (NSString*)dbName { logDebug(@"cannot open database: %@", dbName); // shouldn't happen }; cachedDB = [NSValue valueWithPointer:db]; + sqlite3_exec(db, "PRAGMA foreign_keys = ON;", NULL, NULL, NULL); @synchronized(cachedDatabases) { [cachedDatabases setObject: cachedDB forKey: dbName]; }