#11975 closed (fixed)
invalid sql returned from django.db.backends.sqlite3.DatabaseOperations.date_trunc_sql
| Reported by: | Owned by: | Fabián Ezequiel Gallina | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Keywords: | sqlite DatabaseOperations pycamp2010 djangosprint famaf | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
this method returns 'django_date_trunc("<precision>", <field>)'. in sqlite3, double quoted strings are identifiers, and string literals are single quoted (see http://www.sqlite.org/lang_keywords.html). so it should return "django_date_trunc('<precision>', <field>)". this breaks code such as the following:
MyModel.objects.extra(select={'year':connection.ops.date_trunc_sql('year', '"mymodel"."date"')}).values('year').order_by().annotate(total=Count('pk'))
the resulting query:
[{'time': '0.007', 'sql': u'SELECT (django_date_trunc("year", "mymodel"."date")) AS "year", COUNT("mymodel"."id") AS "total" FROM "mymodel" GROUP BY django_date_trunc("year", "mymodel"."date")'}]
same problem exists with date_extract_sql()
Attachments (1)
Change History (7)
comment:1 by , 16 years ago
| milestone: | → 1.2 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
| Owner: | changed from to |
|---|
comment:3 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:4 by , 16 years ago
| Has patch: | set |
|---|
comment:5 by , 16 years ago
| Keywords: | pycamp2010 djangosprint famaf added |
|---|
Note:
See TracTickets
for help on using tickets.
I was not able to reproduce this issue. My guess is that it was fixed in this revision[0].
Attached is a patch which adds a test for this bug.
[0] http://code.djangoproject.com/changeset/12573/django/trunk/django/db/backends/sqlite3/base.py