Skip to content

Commit

Permalink
feat(ios): Harmonize foreign key enforcing (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmoraunio committed May 22, 2021
1 parent b4fc3ee commit 7d8dfaa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions ios/RNSqlite2.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit 7d8dfaa

Please sign in to comment.