Hi Roman,
On Wednesday 22 May 2013, Roman Klesel wrote:
>
> howerver this woks just fine and I see no reason why this should not be done:
> >>> param = dict(lname = 'Doe')
> >>> qs = Person.objects \
> >>> .raw('SELECT * FROM myapp_person WHERE last_name = %(lname)s', param)
>
This currently works almost by chance -- it depends on the database access
library's support for 'pyformat' parameter style; support which, luckily, is
there in most supported databases. The Oracle backend, specifically, does not
currently support this; see ticket #10070[0]. Also, there was very recently a
related discussion on this list[1].
> however still this fails:
> >>> repr(qs)
>
> /home/user/vpy/dev/lib/python2.7/site-packages/django/db/models/query.pyc
> in __repr__(self)
> 1530
> 1531 def __repr__(self):
> -> 1532 return "<RawQuerySet: %r>" % (self.raw_query %
> tuple(self.params))
> 1533
> 1534 def __getitem__(self, k):
>
> TypeError: format requires a mapping
>
> If no one objects, I could write a patch to the code and the docs that
> implements the functionality.
>
It would be nice if you could add this note to ticket #10070 -- I don't
believe the current patches against it address it.
Thanks,
Shai.
[0]
https://code.djangoproject.com/ticket/10070
[1]
https://groups.google.com/d/topic/django-developers/c1t3zwKMMmk/discussion