-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Multiple query enhanced feedback #429
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
Multiple query enhanced feedback #429
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great ! I think this is close to what we want. Ideally we would be able to have client code be as simple as :
for (const stmt of db.iterateStatements(txt))
console.log(stmt.getAsObject())
This would require adding an @@iterator
method to the returned object (if the iterator symbol is available in the current runtime.
We need to either automatically free the statements after the iteration is over or make it very explicit in the documentation that we don't. Maybe add an example in the jsdoc, to show how this is supposed to be used.
Comments above. I will do my best to address your points, but there are aspects of Javascript, and particularly Javascript + emscripten, that I am not well versed in. Long time programmer, but self-taught in Javascript. |
I just made some testing with your implementation. It looks like |
Yes, that is because I didn't actually implement the iterable protocols - I wasn't sure that was what was wanted/needed. I used the iterable protocols as an inspiration, but tested it manually (not with for .. of). |
OK, so if we want something that works only in a for...of loop and then gets invalidated on exception or when done, that gives me 95% of what I want, which is better than what I have now. The 5% is that I won't have any access to the part of the query that caused an exception when there is an error, because, if I understand correctly, I will have deallocated the memory storing the sql that any pointers I have point into, in the iterator. I.e., I want to be able to do something like:
Maybe there's a workaround where I copy the tail pointer into a string in the iterator object when there's an exception? Would that make sense to you? |
…ed tests and documentation to be written.
NVM, I think I have it working. I should be able to push an update tomorrow. |
If you want to access your "lastSql" after an error, you can attach it to the error type you are throwing... But I don't see the interest, since SQLite doesn't make any guarantee concerning where pzTail is going to end after an invalid SQL statement. What do you want to do with that string ? |
I was never using pzTail itself as the lastSql value, I was trying to subtract pzTail from the nextSql string. My new code doesn't use pzTail at all, and I don't call it "lastSql" now, as that is confusing (you helped my clarify my thinking on this). Instead, the iterator now has a method "getRemainingSql()", which simply reports the value pointed to by the nextSql pointer. This works, and makes more sense; if a user wants to see the remaining SQL after each statement is prepared, they can do so (not sure why they would, but it is there). In my case, if there is an exception, I can access the remaining SQL to report that "the error occurred in here somewhere". |
Perfect, this sounds like what we want |
I marked everything that was resolved as such. Once the remaining open points are fixed, we can merge. |
I think I've addressed all the change requests... do you want me to resolve the open conversations, or do you prefer to do that? |
src/api.js
Outdated
* **Warning**: When you close a database (using db.close()), | ||
* using any statement iterators created by the database will | ||
* result in undefined behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* **Warning**: When you close a database (using db.close()), | |
* using any statement iterators created by the database will | |
* result in undefined behavior. |
src/api.js
Outdated
|
||
/** | ||
* @typedef {{ | ||
value:Statement, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the iterator is done, we return { done: true }
which doesn't match this definition. I think the most useful type definition we can give is {done : true, value: undefined} | {done: false, value: Statement}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are almost done !
I marked all the github conversations that you addressed as resolved. |
Fixed those two documentation issues. I'm very excited to see these changes merged (and hopefully released soon)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
It's on NPM : https://www.npmjs.com/package/sql.js 😃 |
Sweet! |
Added ability to iterate over statements in a multi-statement SQL string. Also added Statement methods accessing SQLite's sqlite3_sql() and sqlite3_normalized_sql() functions.