lundi 20 juillet 2015

Search for keywords from a string using sqlite and python

I have a search box where some text can be entered and results from a database are returned, for example, if I was to search for 'John Smith' the record for all the John Smiths would appear.

However, I would like to make the search less specific, as in if I was to just search for 'John' that record would appear.

This is my query:

cur = g.db.execute('SELECT name, id, location, education FROM accounts WHERE email=? COLLATE NOCASE OR name=? COLLATE NOCASE OR education=? COLLATE NOCASE', (query, query, query,))

As you can see, it also returns a search for not just 'name' but 'location' and 'education' too so I would like the keyword search to apply to these too.

Thanks.

Aucun commentaire:

Enregistrer un commentaire