-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send PRAGMA queries to SELECT handler (Android) #91
Conversation
Thanks for the PR. Are there any drawbacks to always call |
Thanks for getting back so quickly :) So I don't actually have access to a mac/iOS simulator and don't have any experience with swift or objective-c - I can't really even say if this is a problem on that platform. According to the error message, which references the android-specific API methods Re: always enabling foreign key constraints, from what I can gather from https://www.sqlite.org/foreignkeys.html#fk_enable, the only reason they haven't done it is for "backwards compatibility", but they also note that
To me, that means it would be fine to always call it, because if someone is writing SQL queries that include foreign keys, that means they would want to be utilizing that feature. But it's obviously your library and your call whether you want it in. If so, I can either add it to this PR or make a new one. As far as iOS is concerned, again I just don't know if they have the same issue. The android API for that method explicitly forbids calling it after the database has been set up, and I don't know if the iOS code has the same limitation/requirement. For someone who does have access to iOS, they could run something like |
Thanks for the explanation. |
Yes sir, here's the PR for that: |
I can confirm await db.transaction((txn) => {
txn.executeSql('PRAGMA foreign_keys = ON', [])
})
await db.transaction((txn) => {
txn.executeSql('PRAGMA foreign_keys', [], (tx, res) => {
console.log(res)
})
}) Result: |
@bbalan PR would be appreciated as I don't use it personally. |
This patch addresses Issue #65. Basically we just want to treat a PRAGMA query (but not an assignment) with the same handler as the one which does SELECT, so that it can return the results of the query (and not throw the exception named in the issue).
Semi-related, and I didn't include this change in this pull request, but in order to enable foreign key support I had to add a call to
database.setForeignKeyConstraintsEnabled(true);
in the Module just afterdatabase = SQLiteDatabase.openOrCreateDatabase(file, null);
. Apparently Android won't respectPRAGMA foreign_keys = ON
if you do it at a later time. I wasn't sure how best to address this, whether to add a parameter toopenDatabase
insrc/index.js
(which would defy the websql API it's going for) or to add a parameter to both theRNSqlite2Package
andRNSqlite2Module
constructors (which looks ugly but at least doesn't mess with the API). I was wondering if you had any other ideas or if you want me to do it one of these ways I can submit another PR.Cheers