Understand that this will not affect django for the next several releases.  
Probably django 2.0.  The transition from db-api 2 to db-api 3 will be a 
lot like the transition from Python 2 to Python 3.  You will have to import 
a different module to get the different behavior, and today's api-2 
interface will linger around for innumerable years to come.

The reason that 'format' and 'pyformat' have fallen into disfavor is that 
they *look* like the %s and %(identifier)s used by the string "%" operator, 
but they don't quite *work* like them.  That causes no small amount of 
confusion and trouble -- such as having to use %%s sometimes but not 
others.  I need not explain to this group, you have all been bitten by it, 
or will be.  Someday, some poor human will, I suspect, have to look at 
every occurrence of %s in the entire django code base and decide whether to 
replace it with '?' because it is going to an SQL query, or with "{}" 
because it will be a string format operation. The only examples of %s still 
left will be in templates, and in ADO connection strings.  [Having heard 
myself say that, I may decide to write a .format() method for Python 2.5 so 
that I can keep them out of ADO connection strings -- so that that problem 
would never appear.  Must give us pause.]
 
Expect % as a format specifier in an SQL query to go away ... someday ... 
but not today, and not tomorrow.
--
Vernon Cole

On Wednesday, May 22, 2013 3:37:55 AM UTC-6, roman wrote:
>
> Hello, 
>
>
> the docs say: 
>
> """ 
> Passing parameters into raw() 
>
> If you need to perform parameterized queries, you can use the params 
> argument to raw(): 
>
> >>> lname = 'Doe' 
> >>> Person.objects.raw('SELECT * FROM myapp_person WHERE last_name = %s', 
> [lname]) 
>
> params is a list of parameters. You’ll use %s placeholders in the 
> query string (regardless of your database engine); they’ll be replaced 
> with parameters from the params list. 
> """ 
>
> 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) 
>
> 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. 
>
> Regards Roman 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to