#24438: Django: Sqlite and regexp in query
---------------------------------+--------------------
     Reporter:  ctrl-alt-delete  |      Owner:  nobody
         Type:  Uncategorized    |     Status:  new
    Component:  Uncategorized    |    Version:  1.6
     Severity:  Normal           |   Keywords:  SQLite
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+--------------------
 I'm using Django with a PostgreSQL database and this query works fine:

 {{{#!python
     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}}}:

 {{{#!sql
     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: "^"}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24438>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/058.3897e86b1549c2de3e9fe82d7fe67ada%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to