<div class="gmail_quote">On Thu, May 27, 2010 at 1:37 PM, Dennis Lee Bieber <span dir="ltr"><<a href="mailto:wlfraed@ix.netcom.com">wlfraed@ix.netcom.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
On Wed, 26 May 2010 08:29:21 -0400, Victor Subervi<br>
<div class="im"><<a href="mailto:victorsubervi@gmail.com">victorsubervi@gmail.com</a>> declaimed the following in<br>
gmane.comp.python.general:<br>
<br>
</div>> valueList = ("%value1", "%value2", "%value3")<br>
<br>
If I'd coded it correctly, there should have been a % on both sides<br>
(I didn't actually test the statement, was coding from memory -- might<br>
have needed to double up the % to escape them)<br>
<div class="im"><br>
> cur.execute("select * from table where name1 like %s and name2 like %s and<br>
> name3 like %s", ("%value1", "%value2", "%value3"))<br>
><br>
> Why do the values have that extra "%"?<br>
<br>
</div> Wild card -- match zero or more characters<br>
<br>
%value1% will match "value1" /anywhere/ in the field name1; useful<br>
if doing keyword searches on text fields.<br>
<br>
To use my card catalog example:<br>
<br>
BOOK(title, author)<br>
"Witch World", "Andre Norton"<br>
"A Mankind Witch", "Dave Freer"<br>
"Three Against the Witch World", "Andre Norton"<br>
"The Jargoon Pard", "Andre Norton"<br>
<br>
names = ["author", "title"]<br>
values = ["Norton", "Witch"]<br>
<br>
The final SQL statement should become<br>
<br>
select * from BOOK<br>
where author like "%Norton%"<br>
and title like "%Witch%"<br>
<br>
and that statement will find the first and third book listed.<br></blockquote><div><br>Ok. Now I understand. Thank you!<br>beno<br></div></div><br>