-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
db misses an API to precompile the query and bind data later. #9453
Comments
Please rephrase the title, |
Can you provide an example of how you imagine the changed API? |
I renamed it but give me a hint if it's not sufficient. An example how the preparedStatement stuff is working: Important thing is: the binding of the values is done at the database side A good explanation how the binding is done can be found here: Detailed information how it's working (postgresql but more or less generic) |
I think I get it now, you want an API to compile a query and then execute it with arbitrary data, instead of an API that generates a query string including the data that needs to be evaluated on each call. And no the issue title is still not good, using the word |
yep, that's correct - you got me now 😃 the api would consist of a generic part and a vendor specific one. Also connection pooling and that stuff. But that is not that easy as it looks. I'd like to contribute here but I could only offer modest timeslots.. I also was not sure if I should file a bug or feature request. |
@mikra01 yes the issue templates are still quite new and not final. Since they are supposed to help your feedback is very welcome. What kind of issue template would you have prefer? |
@krux02 thank you the changed topic looks much better now. The thing is that all related issues here from the past are just symptoms (missing parameter binding). |
I have made a fork of db_sqlite that uses Noteworthy, you can just replace Reusing precompiled statements is not supported at the moment, but I am considering adding it. |
@xzfc fine exactly thats it :-) (low-level api). Also dbNulls are handled the right way by your impl. I glanced at it shortly (but not tried yet). you could get rid of the dbQuoting-stuff now. Additional remark: within the iterator (fastRows iterator) you could put a finally in it to make the database happy if the iterator is aborted with break by the caller (I remember it was your thread in the forum a few days ago?) . Edit: I thought about the caching of the preparedStatements: it's better (I think) to delegate that job to the caller. the user code knows better when (or when not) to cache. just ensure that prepare_v2 is only called once and for a new binding sqlite3_reset() must be called (I could imagine a kind of binding-iterator for bulk loads...). just ensure that finalize() is called but only within the destructor of the preparedStatement (or deInit). |
@mikra01 Concerning |
To encourage you a bit, once |
I recently found now a timeslot to implement what I thought. please take a look at it: https://github.com/mikra01/nimdb . A starter would be the examples directory (tested wth 0.19.9). At the moment I am fiddling with ODBC.... |
…mat() with '?' in query without arguments.
dbFormat is used to substitute the param values.
the question mark (?) is matched on the entire sql-string instead
of binding by the database. This would harden the API and the
database is able to cache the (already parsed) prepared statements.
At the moment the database does a hard-parse on every invocation.
example for sqlite3 to demonstrate the issue:
Solution:
DbType already present within db_common.nim; for db_postres.nim
there is also a "prepare" proc already present but
unfortunately the parameter dbType is missing.
The API could be extended a little bit (introduce new procs without affecting the
present API) so that the caller is able to promote the dbTypes.
Or introduce a preparedStatement object (better solution I think) and bind the values like this: ps.setString(1,"fine!")
Binding (driver layer) would be not that difficult then.
Additional Information
this affects the entire db-driver layer.
Discussion can be found here:
https://forum.nim-lang.org/t/4320
related discussion here
nim-lang/db_connector#12
also in the past some issues relating this problem
bubbled up:
#3328
#6571
The text was updated successfully, but these errors were encountered: