I don't think this is a good solution because it is retrieving all the rows 
from the database and then iterating over them to find a match.

Do you have the option of sanitizing a phone number before it is stored in 
the database?  Or, could you create a new 'sanitized' phone number field 
that you could select over?

Either that, or take the value you're looking for an parse it in to all the 
possible ways it could be stored and then search for those options.

Ex

phone_numbers = ['+31123456789', '+31-(0)123 456 789', '+31-0 123 456 789', 
etc.]

db(db.table.phonenumber.belongs(phone_numbers)).select()

-Jim


On Tuesday, October 19, 2021 at 2:17:55 AM UTC-5 A3 wrote:

> finally I tried:
> db((db.table.id >0)).select(db.table.phonenumber).find(lambda rw: 
> rw.phonenumber.replace("-","").replace(" ","").replace("(0)","")==caller if 
> rw is not None else None)
> Initially this gave an error TypeError: 'NoneType' object has no 
> attribute '__getitem__' 
> <https://www.ursadina.nl/admin/default/errors/gtd1#>
> The problem was that the field phonenumber could also be None. 
> Solution:  in the table definition :set default to ""  and update all 
> existing None values to "" 
>
> Any other suggestions?      
> Op maandag 18 oktober 2021 om 15:37:24 UTC+2 schreef A3:
>
>> Want to lookup a phone number in a db table 
>> the value to lookup is  e.g.  caller = "+31123456789"
>> Phone numbers in db field can contain + - .  and also () and is not very 
>> consistent.
>> could look like:  phonenumber = "+31-(0)123 456 789" 
>>
>> would like something: 
>> db(db.table.phonenumber.like(caller)).select()
>>
>> Any suggestions? 
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/4598cb35-aa4b-4f1b-99ce-c83498456c36n%40googlegroups.com.

Reply via email to