mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #9055 -- Standardized behaviour of parameter escaping in db cursors
Previously, depending on the database backend or the cursor type, you'd need to double the percent signs in the query before passing it to cursor.execute. Now cursor.execute consistently need percent doubling whenever params argument is not None (placeholder substitution will happen). Thanks Thomas Güttler for the report and Walter Doekes for his work on the patch.
This commit is contained in:
parent
e7514e4978
commit
76aecfbc4b
7 changed files with 43 additions and 12 deletions
|
@ -227,6 +227,12 @@ For example::
|
|||
were committed to the database. Since Django now defaults to database-level
|
||||
autocommit, this isn't necessary any longer.
|
||||
|
||||
Note that if you want to include literal percent signs in the query, you have to
|
||||
double them in the case you are passing parameters::
|
||||
|
||||
cursor.execute("SELECT foo FROM bar WHERE baz = '30%'")
|
||||
cursor.execute("SELECT foo FROM bar WHERE baz = '30%%' and id = %s", [self.id])
|
||||
|
||||
If you are using :doc:`more than one database </topics/db/multi-db>`, you can
|
||||
use ``django.db.connections`` to obtain the connection (and cursor) for a
|
||||
specific database. ``django.db.connections`` is a dictionary-like
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue