Export to GitHub

django-firebird - issue #4

icontains doesn't work. Bad where clause is generated


Posted on Sep 27, 2009 by Happy Panda

The icontains search option doesn't work correctly. Firebird must to implement CONTAINING sql clause for icontans searchs but the sql result has not correctly generated.

It generate:

WHERE "TABLE"."FIELD" CONTAINING %value%

And should be:

WHERE "TABLE"."FIELD" CONTAINING 'value'

Use 'instead %

More Info:

Django 1.1 Python 2.6 (virtualenv 1.3) Firebird 1.5.5

Comment #1

Posted on Nov 9, 2009 by Grumpy Kangaroo

In SVN I found this (commented out) solution: #if 'CONTAINING' in where: # w_params = [w_params[0].replace('%', '')]

This approach has a number of issues, for instance when there is no where clause or w_params is empty. Furthermore, there might by more than one parameter to be converted, as in django-admin search_field.

I'd like to share my approach which handles above situations and loops through w_params, only converting parameters matching \%([^%]+)\%

            if where and 'CONTAINING' in where and len(w_params) > 0:
                  import re
                  i=0;
                  for p in w_params:
                      w_params[i] = re.match('\%([^%]+)\%', p).group(1)
                      i = i + 1;

Tested with Django 1.1 Python 2.6.2 Firebird 2.1.3

Comment #2

Posted on Nov 10, 2009 by Happy Panda

Thomas, Your solution look better. Anyway, I donĀ“t know if there is the correct place to implement this. I was looking for a standard method to override but I could found a correct method. What do you think?
Do you know a better approach?

Comment #3

Posted on Nov 10, 2009 by Grumpy Kangaroo

Do you know a better approach? Unfortunately, I couldn't come up with something better since I'm quite new to Django. But I'm also not sure if this is the way to go, since the "STARTING WITH"-Case isn't handled and I don't like the idea of hacking each case to make it work.

Status: New

Labels:
Type-Defect Priority-Medium