On Tuesday, September 9, 2014 8:40:04 AM UTC-4, Maurice Waka wrote:
>
> Thanks for the input. Yes it is part of a web2py app game.
> I have about 1000 rows, but when a user types in the keyword(stored in any 
> of the rows) i should get a boolean answer which for now displays the 
> row(different code on this) 
>

OK, but how are the rows stored in SQLite? Are they just strings, like 
"['123', '1234', '12345', ]"? If so, you can do a query searching for the 
string "'[keyword]'," within each row to return rows with a matching 
keyword. Again, I would recommend using the DAL with a list:string field:

db.define_table('keywords',
    Field('x', 'list:string'))

This allows you to insert and extract actual Python lists from the field, 
though the lists will be stored in the database as a string in the form 
"|item1|item2|item3|". So, to find rows that match a keyword, you would 
just do:

keyword = '123' # in reality, this is obtained via user input
match_row = db(db.keywords.x.contains('|%s|' % keyword)).select().first()

Your boolean test would then simply be "if match_row:". The list of 
keywords in the matching row would be in match_row.x, which would be an 
actual Python list rather than a string representation of a list.

Anthony

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to