#10070: Named parameters not working on raw sql queries with sqlite
-------------------------------------+-------------------------------------
Reporter: Matias Surdi | Owner: Ryan
| Cheley
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Shai Berger):
Replying to [comment:27 Ryan Cheley]:
>
> I think the way to fix the issue is to update that method to include the
following logic:
>
>
> {{{
> query = re.sub("\)s", "", re.sub("%\(", ":", query))
> }}}
>
This looks quite fragile (consider, e.g. a query which, for whatever
reason, includes {{{)s}}} in a string constant).
A more robust approach is to create a naming-dict from all the param-
names, and use that to format the original text:
{{{#!python
naming_dict = { param: f":{param}" for param in param_names}
query = query % naming_dict
}}}
Where {{{param_names}}} can be collected either by parsing the query, or
from the parameters given.
(take a look at the Oracle backend -- I wrote that piece too long ago to
remember which it takes, but at the time I knew what I was doing there)
--
Ticket URL: <https://code.djangoproject.com/ticket/10070#comment:28>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701842a2e6402-21b1e7d6-3590-4ef5-a251-02a6c204b553-000000%40eu-central-1.amazonses.com.