Opened 10 years ago
Closed 10 years ago
#24438 closed Uncategorized (worksforme)
Django: Sqlite and regexp in query
Reported by: | Vera Mazhuga | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.6 |
Severity: | Normal | Keywords: | SQLite |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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: https://github.com/django/django/blob/master/django/db/backends/sqlite3/base.py#L129, 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.
And when I execute the SQL I get the following error:
OperationalError: unrecognized token: "^"
Attachments (1)
Change History (2)
comment:1 by , 10 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
by , 10 years ago
Attachment: | 0001-Add-a-passing-test-case.patch added |
---|
Hi @ctrl-alt-delete,
I couldn't reproduce your issue against
master
orstable/1.6.x
with the attached patch; I got the same results on both PostgreSQL and SQLite3.Please re-open if you can provide more details to help us reproduce your issue. A failing test case in our test suite would be perfect, thanks!