-
-
Notifications
You must be signed in to change notification settings - Fork 321
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
on_open is never called for in memory storage #1000
Comments
Hi. Yes what you are saying is right: things turn out a way when you never get |
Ok, Those queries are either predefined (for which SQLite orm is great) or are supplied as external input/user-defined. Naturally, the second case cannot be handled via statically typed queries at compile time (think a pre-validated but pretty generic WHERE clause). So, it's really this second edge-case that requires access to the sqlite3* handle. Right now I have just worked around that by adding a utility function to storage_base. The other option I have thought about would be to allow something like
instead of
And that compiles just fine, but the resulting prepared statement is wrong. I think this goes wrong somewhere in the handling of where_t / expression_type (which is just const char* in that case). Edit: Basically, it results in something like
This makes sense, because i) I am really not supplying anything that fits as a prepared statement, ii) kinda breaks the typed API. |
Lol yes. You pass a string, string is a valid SQL expression. It makes a query like You can create a universal query with all available options chained with bool flags. Please take a look at this issue #272. Guy there was sure that he can only use dynamic queries but I told him how to use static queries. It allows to
|
Hi, It does not work in the case of an example roughly such as: table { for which all the following are possible conditions:
Basically, the query is (optionally) constructed in an external query builder, validated against a shared schema, and then executed (for some cases). I think it is fundamentally not possible to prepare for that at compile time. |
Yes such a situation is not designed to be handled by |
Ok, I will look into this :-) Would it make any sense to add special handling for in-memory cases tho? I would be willing to prepare the code changes if you have any suggestions on how to go about this. |
I'd like to fix this issue of course. But I don't know how to do it. Actually the thing is that when you set |
Hmm, |
I guess we can fix it without creating auto storage = make_storage("path.sqlite", [](sqlite3* db) {
// handle db here
}, make_table(...), ...); What do you think? |
Hi,
assuming the standard way to obtain a sqlite3 handle in the FAQ (https://github.com/fnc12/sqlite_orm/wiki/FAQ)
in combination with in-memory storage, the on_open lambda is never executed.
The reason is the following special treatment of in-memory in storage_base:
Basically, I see no way to have anything registered for on_open at this point already.
Attaching it after the storage has been created has no effect, because, e.g.:
So, retain_count is already 2 (for the in-memory case) and on_open_internal is never called (which makes sense).
Is this on purpose / by design?
One option would be to provide the on_open handler directly for make_storage, but in general, I am not sure if the on_open semantics make sense for the in-memory model (which by definition is just ... open). Thoughts?
The text was updated successfully, but these errors were encountered: