Opened 10 years ago

Closed 7 years ago

#6400 closed (invalid)

extra() with LIKE and params breaks

Reported by: Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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/", line 108, in __repr__
    return repr(self._get_data())
  File "/usr/lib/python2.4/site-packages/django/db/models/", line 483, in _get_data
    self._result_cache = list(self.iterator())
  File "/usr/lib/python2.4/site-packages/django/db/models/", 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/", line 18, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.4/site-packages/django/db/backends/sqlite3/", 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 Changed 10 years ago by

I forgot: This output is generated using sqlite3 and newforms-admin revision 7020.

comment:2 Changed 10 years ago by Jacob

Triage Stage: UnreviewedAccepted

comment:3 Changed 9 years ago by anonymous

Has this issue been addressed?
Is there a work around for it?

comment:4 Changed 9 years ago by alfredo1

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 Changed 7 years ago by Klaas van Schelven

Resolution: invalid
Status: newclosed

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.
Back to Top