-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add support for prepared statements #116
Comments
Note that currently, Should this be a separate issue? |
Also note that MonetDB destroys all existing prepared statements when a transaction aborts due to an error or a ROLLBACK. If we go the way of the |
on the server side work has started to fix this by recompiling the prepared statements |
Just handle the result set. Leave the id of the prepared statement in cursor.lastrowid so it can be used with EXEC. See also issue #116.
the server now handles :name paramstyle='named' formated queries. The multi statement remains an issue. |
This crash has already been fixed in pymonetdb 1.6.4. In 1.8.2 we document how to use PREPARE and EXEC. |
It has been supported since 1.6.4 but it wasn't documented See also #116
Using prepared statements can be more efficient but PEP 249 does not provide an API for it. Instead, it mentions that
However, it is not safe for pymonetdb to simply prepend
PREPARE
to an arbitrary block of SQL code and expect it to work. For example, if there is more than one sql statement in there, only the first would get prepared, the rest would get executed. There could also beEXPLAIN
, or ddl statements, misleading comments, or other things that would break.Pymonetdb just cannot be sure that the user has taken into account that
cursor.execute(code_with_percent_s, args)
might actually be transformed intocursor.execute('PREPARE ' + code_with_question_marks); ...; cursor.execute('EXEC 42(...)', args)
.Instead of having pymonetdb try to guess, I propose we add a
.prepare()
method toCursor
and maybeConnection
. This method would prepare the statement and return an object that knows about the parameter- and result types, and which you can invoke.execute()
and.executemany()
on.Alternatively, if we also want applications that are not pymonetdb-aware to benefit from prepared statements, we could augment the responses from the server with information on whether the given statements would have been suitable for PREPARE. Pymonetdb could remember this and if it encounters the same SQL code again, use it to decide whether or not to PREPARE this time.
It has also been suggested to add a connect parameter that says "use prepared statements, I promise not to pass any sql code that cannot be PREPAREd". I am a little uneasy with this because it seems very error prone. The person who writes the Connect statement (or MAPI URL parameter) may not be the same as the person who writes the individual execute statements.
The text was updated successfully, but these errors were encountered: