Skip to content

Commit 7d8dfaa

Browse files
authored
feat(ios): Harmonize foreign key enforcing (#98)
1 parent b4fc3ee commit 7d8dfaa

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ PouchDB.plugin(SQLiteAdapter);
102102
var db = new PouchDB("mydb", { adapter: "react-native-sqlite" });
103103
```
104104

105-
### Foreign key support on Android
105+
### Foreign key support
106106

107-
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.
107+
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.
108108

109109
## Changelog
110110

ios/RNSqlite2.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ -(NSValue*)openDatabase: (NSString*)dbName {
7979
logDebug(@"cannot open database: %@", dbName); // shouldn't happen
8080
};
8181
cachedDB = [NSValue valueWithPointer:db];
82+
sqlite3_exec(db, "PRAGMA foreign_keys = ON;", NULL, NULL, NULL);
8283
@synchronized(cachedDatabases) {
8384
[cachedDatabases setObject: cachedDB forKey: dbName];
8485
}

0 commit comments

Comments
 (0)