Introduced prepared statement APIs#238
Conversation
|
Hello @Benjamin-Dobell, Thank you for implementing this feature; it has been long pending :)
Using LLMs is okay, as long as we do some rigorous reviewing before merging :) |
2shady4u
left a comment
There was a problem hiding this comment.
I did a surface-level review; I need to review in more depth at some point.
| active_instances.reserve(statement_instance_ids.size()); | ||
|
|
||
| query_result.clear(); | ||
| for (uint64_t instance_id : statement_instance_ids) { |
| } | ||
|
|
||
| void SQLite::finalize_statements() { | ||
| for (uint64_t instance_id : statement_instance_ids) { |
| } | ||
|
|
||
| if (stmt == nullptr) { | ||
| stmt = nullptr; |
There was a problem hiding this comment.
Statement is already nullptr? Why assign again?
There was a problem hiding this comment.
As much as I'd love to blame AI. This was almost certainly me 😛 AI generated the first iteration but I made a heap of changes after the fact - mostly removing cruft like useless helper methods. So this was probably the direct body of a helper method that was (naively) inlined.
|
|
||
| for (int i = 0; i < column_count; i++) { | ||
| const char *column_name = sqlite3_column_name(stmt, i); | ||
| column_names.append(String::utf8(column_name)); |
There was a problem hiding this comment.
Should this method clear the column_names first before appending?
To make sure the column_names is actually empty.
There was a problem hiding this comment.
It bails out early if the array is not empty. Basically it's lazy initialization, so subsequent calls aren't expected to mutate the column names at all.
There was a problem hiding this comment.
Perhaps it's worth noting that since these are prepared statements, the columns themselves aren't mutable. Once the statement is prepared, the columns included in the query are final. You don't reuse a statement for a different query, only for re-execution or rebinding SQL arguments.
| int rc = SQLITE_OK; | ||
|
|
||
| if (stmt != nullptr) { | ||
| rc = sqlite3_finalize(stmt); |
There was a problem hiding this comment.
No need for if statement because SQLite docs say:
Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
| return true; | ||
| } | ||
|
|
||
| void SQLiteStatement::release_statement(StatementStatus p_next_status) { |
There was a problem hiding this comment.
This method should be cleaned up a bit manually.
| db = nullptr; | ||
| } | ||
|
|
||
| bool SQLiteStatement::check_valid(const char *p_method_name) { |
There was a problem hiding this comment.
I don't get the point of this method? It always returns false if status of the statement is not INITIALIZED so why not use is_valid instead?
There was a problem hiding this comment.
It's a private method and sets the error message, where as is_valid is part of the public API designed for library consumers.
8e294a0 to
4f291f8
Compare
|
First round of feedback addressed. Feel free to take your time on a more thorough review - just actioning this quickly because I happened to be at the start of a work session and easier for me to do this now than worry about context switching later 😅 Probably worth noting, whilst I used an LLM to generate the first iteration, I have made extensive changes to what the LLM spat out - even introducing some of the mistakes the good ol' fashion way 😉 However, I must admit, it did save me a good chunk of time. This isn't exactly novel engineering work 😂 Bindings, porting code, and somewhat surprisingly, reverse engineering, are the areas I've found LLMs to really excel at. First PR I've ever submitted where AI did more than auto-complete; so figured I better flag it. |
|
Hello :) |
Support for prepared statements.
API
New API exported
SQLiteStatementclass.Please note that you really do want to call
finalize()to avoid memory leaks. That said, the connection itself also tracks the prepared statements, so if you clean up the connection it will clean-up any left over prepared statements.Tests
Tests have been updated to include code similar to the above.
Docs
XML docs have been updated too.
AI Disclosure
LLMs were used during development. If that's an concern for this repo, do not merge.