lundi 2 mars 2015

Django: Sqlite and regexp in query

I'm using Django with a PostgreSQL database and this query works fine:



REQUEST_TYPE_ENTRANCE = 1
REGEX_ENTRANCE = r'^{0},|,{0},|,{0}$|^{0}$'.format(
REQUEST_TYPE_ENTRANCE
)
entrance_registers = EntranceRegister.objects.filter(authorized_requests__regex=REGEX_ENTRANCE)


But when I run tests with SQLite database it returns no results.


Here is the output of print EntranceRegister.objects.filter(authorized_requests__regex=REGEX_ENTRANCE).query:



SELECT "porter_entranceregister"."id", "porter_entranceregister"."status", "porter_entranceregister"."authorized_requests", "porter_entranceregister"."gone_at", "porter_entranceregister"."created_at"
FROM "porter_entranceregister"
WHERE "porter_entranceregister"."authorized_requests"
REGEXP ^1,|,1,|,1$|^1$ ORDER BY "porter_entranceregister"."created_at"
DESC


I suppose that the problem might be with missing quotes here: http://ift.tt/1zztxPl, but when I change this file in my virtualenv, it fails with



ProgrammingError: Incorrect number of bindings supplied. The current statement uses 6, and there are 7 supplied.

Aucun commentaire:

Enregistrer un commentaire