Web2py sqlite select database records using wildcards

86 views
Skip to first unread message

Meinolf

unread,
Sep 12, 2016, 3:39:17 PM9/12/16
to web2py-users
Anyone knows the web2py's sqlite syntax to select database records using wildcards such as %like% or contains instead of query = db.mytable.myfield == 'value'?

Dave S

unread,
Sep 12, 2016, 4:08:16 PM9/12/16
to web...@googlegroups.com


On Monday, September 12, 2016 at 12:39:17 PM UTC-7, Meinolf wrote:
Anyone knows the web2py's sqlite syntax to select database records using wildcards such as %like% or contains instead of query = db.mytable.myfield == 'value'?


According to the book, it's db(db.log.event.like('string%')).select()
(where I've used the example DB names).
<URL:http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#like--ilike--regexp--startswith--endswith--contains--upper--lower>

(I found it a good idea to pretty much read the book through ... I got the hardcopy, which is not quite up-to-date now ... and that made it easier to search through for answers to specific questions.)

I don't have examples on this computer (instead, the early code here used executesql() with "LIKE" in the WHERE clause), but I probably have an example at home.

/dps



Meinolf

unread,
Sep 12, 2016, 5:55:42 PM9/12/16
to web2py-users
yes an example would do especially to use a string variable name instead of 'value', i.e db.mytable.myfield.like(variablename).select() for example. But thanks for the response, so far at least i've got an idea..
Reply all
Reply to author
Forward
0 new messages