A Quick MySQL Question
Victor Subervi
victorsubervi at gmail.com
Thu May 27 13:56:01 EDT 2010
More information about the Python-list mailing list
Thu May 27 13:56:01 EDT 2010
- Previous message (by thread): A Quick MySQL Question
- Next message (by thread): Chatroom
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, May 27, 2010 at 1:37 PM, Dennis Lee Bieber <wlfraed at ix.netcom.com>wrote: > On Wed, 26 May 2010 08:29:21 -0400, Victor Subervi > <victorsubervi at gmail.com> declaimed the following in > gmane.comp.python.general: > > > valueList = ("%value1", "%value2", "%value3") > > If I'd coded it correctly, there should have been a % on both sides > (I didn't actually test the statement, was coding from memory -- might > have needed to double up the % to escape them) > > > cur.execute("select * from table where name1 like %s and name2 like %s > and > > name3 like %s", ("%value1", "%value2", "%value3")) > > > > Why do the values have that extra "%"? > > Wild card -- match zero or more characters > > %value1% will match "value1" /anywhere/ in the field name1; useful > if doing keyword searches on text fields. > > To use my card catalog example: > > BOOK(title, author) > "Witch World", "Andre Norton" > "A Mankind Witch", "Dave Freer" > "Three Against the Witch World", "Andre Norton" > "The Jargoon Pard", "Andre Norton" > > names = ["author", "title"] > values = ["Norton", "Witch"] > > The final SQL statement should become > > select * from BOOK > where author like "%Norton%" > and title like "%Witch%" > > and that statement will find the first and third book listed. > Ok. Now I understand. Thank you! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20100527/0a24012c/attachment-0001.html>
- Previous message (by thread): A Quick MySQL Question
- Next message (by thread): Chatroom
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list