#17741: QuerySet.query.__str__() does not generate valid MySQL query with dates
-------------------------------------+-------------------------------------
     Reporter:  anonymous            |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  1.3
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by zachborboa):

 If you need the correct parameter substitution, use `EXPLAIN`. Then remove
 the first 8 chars.

 {{{#!python
 In [1]: import datetime

 In [2]: from django.db import connection

 In [3]: from myapp.models import Entry

 In [4]: today_entry_list =
 Entry.objects.filter(post_date=datetime.date.today())

 In [5]: sql, params = today_entry_list.query.sql_with_params()

 In [6]: cursor = connection.cursor()

 In [7]: cursor.execute('EXPLAIN ' + sql, params)
 Out[7]: 1L

 In [8]: print(cursor.db.ops.last_executed_query(cursor, sql, params))
 EXPLAIN SELECT `myapp_entry`.`id`, `myapp_entry`.`title`,
 `myapp_entry`.`slug`, `myapp_entry`.`body`, `myapp_entry`.`post_date` FROM
 `myapp_entry` WHERE `myapp_entry`.`post_date` = '2016-04-04'
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/17741#comment:4>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.3e222b71ec2b7dad0d2f50a34a232e4a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to