Opened 18 years ago
Closed 15 years ago
#6400 closed (invalid)
extra() with LIKE and params breaks
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
What I am seeing is this. I think it is somehow related to the mass use of the percentage char. I couldn't get it to work on both sqlite and PostgreSQL 7.4
>>> Speaker.objects.extra(where=['first_name LIKE "%%bla%%"'])
[]
>>> Speaker.objects.extra(where=['first_name = %s'], params=['bla'])
[]
>>> Speaker.objects.extra(where=['first_name LIKE "%%%s%%"'], params=['bla'])
Traceback (most recent call last):
File "<console>", line 1, in ?
File "/usr/lib/python2.4/site-packages/django/db/models/query.py", line 108, in __repr__
return repr(self._get_data())
File "/usr/lib/python2.4/site-packages/django/db/models/query.py", line 483, in _get_data
self._result_cache = list(self.iterator())
File "/usr/lib/python2.4/site-packages/django/db/models/query.py", line 189, in iterator
cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
File "/usr/lib/python2.4/site-packages/django/db/backends/util.py", line 18, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.4/site-packages/django/db/backends/sqlite3/base.py", line 133, in execute
return Database.Cursor.execute(self, query, params)
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 1 supplied.
As a model to try with this should suffice:
class Speaker(models.Model):
first_name = models.CharField(max_length=25)
Change History (5)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:4 by , 16 years ago
I think you should change the percentage sings to be in the actual params
So it would be like:
Speaker.objects.extra(where=['first_name LIKE %s'], params=['%bla%'])
comment:5 by , 15 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
I'm marking this as invalid. alfredo1's remark is correct. I've just doublechecked:
>>> Two.objects.all().extra(where=['a_field LIKE %s'], params=['%bla%']) []
Note:
See TracTickets
for help on using tickets.
I forgot: This output is generated using sqlite3 and newforms-admin revision 7020.