#20516: Allow use of prepared statements
-------------------------------------+-------------------------------------
Reporter: est | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: db, prepared | Triage Stage: Accepted
statement |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by thedrow):
I investigated about implementing it today and it turns out that the Query
class has a method called sql_with_params() which returns the SQL query
without concatenating the parameters.
MySQL uses the following syntax:
{{{#!sql
PREPARE usrrptplan FROM "SELECT * FROM users u, logs l WHERE u.usrid=? AND
u.usrid=l.usrid
AND l.date = ?;"
EXECUTE usrrptplan USING 1, NOW()
}}}
PostgreSQL uses the following syntax:
{{{#!sql
PREPARE usrrptplan (int) AS
SELECT * FROM users u, logs l WHERE u.usrid=$1 AND u.usrid=l.usrid
AND l.date = $2;
EXECUTE usrrptplan(1, NOW());
}}}
It seems that when you call prepare() you need to switch the query
entirely with the EXECUTE syntax.
Moreover, at least in PostgreSQL you have to check if the statement is
already prepared and there's no SQL syntax to do that.
You need to query the pg_prepared_statements table in order to verify that
it doesn't exist.
Since a prepared statement requires a name we can either randomize one or
have one provided for us.
I think that providing both options is a good idea.
--
Ticket URL: <https://code.djangoproject.com/ticket/20516#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/061.bf6507b274c56ca32c953d9304cc2ee2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.