Hi everybody.

I think I found an issue in the DB2 adapter. This is the scenario:

I have a field in a table with the following two attributes:

*db.table1.field.requires=IS_EMPTY_OR(IS_IN_DB(db, db.table2.id, 
'%(description)s, null=None)*

*db.table1.field.widget = SQLFORM.widgets.autocomplete(*
*     request, db.table2.description, id_field=db.table2.id, 
limitby=(0,10), min_length=2)*

The "requires" attribute is supposed to be necessary because I accept null 
values in this field, otherwise it would not allow me to leave the field 
empty.

The problem is that, when using the autocomplete widget on a record with 
null db.table1.field, the DB2 adapter attempts to issue a SELECT statement 
like: 

"SELECT LIBRARY.TABLE.description FROM LIBRARY.TABLE WHERE 
(LIBRARY.TABLE.id = NULL)", which is syntactically wrong on DB2 (the right 
syntax is "...WHERE ... *IS* NULL").

I tried to follow the code to see if I could fix the generation of the SQL 
statement, but that goes beyond my ability and knowledge of web2py.

I found a workaround, though, that i suggest you to consider as a fix to 
the Autocomplete widget inside sqlhtml.py:

around line 707, in case of a self-referencing field (like the one I am 
working on), I changed this line:

record = self.db(
                self.fields[1] == value).select(self.fields[0]).first()

to:

record = self.db(
                self.fields[1] == value).select(self.fields[0]).first()* if 
value != '' else None*

I suggest it as a fix because it's a time and resource waste to query the 
database for a record with null id, beside my need to "workaround" the 
mistaken behaviour of the DB2 sql adapter.

This is just my opinion. I'd like to know what you think about it.

Ciao
Maurizio

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to