Dennis , Chris<div><br></div><div>Thanks so much!</div><div><br></div><div><br><br><div class="gmail_quote">On Mon, Feb 6, 2012 at 1:23 AM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Mon, 6 Feb 2012 00:41:24 +0200, Emeka <<a href="mailto:emekamicro@gmail.com">emekamicro@gmail.com</a>> wrote:<br>
<br>
>Hello All,<br>
><br>
>I noticed that MySQLdb not allowing hyphen may be way to prevent injection<br>
>attack.<br>
<br>
</div> What hyphen?<br>
<div class="im"><br>
>I have something like below:<br>
><br>
>"insert into reviews(message, title)values('%s', '%s')" %( "We don't know<br>
>where to go","We can't wait till morrow" )<br>
><br>
</div> <snip><br>
<div class="im">>How do I work around this error?<br>
<br>
</div> Very simple... DON'T QUOTE PLACEHOLDERS AND USE MySQLdb<br>
parameterized queries.<br>
<br>
csr.execute("insert into reviews (message, title) values (%s, %s)",<br>
( "We don't know where to go",<br>
"We can't wait till <sic> morrow" ) )<br>
<br>
The whole purpose of parameterized queries is that the .execute()<br>
logic will SAFELY wrap the supplied values with quotes AND escape any<br>
problem characters within the value.<br>
<br>
The reason you got an error was not a hyphen (there are no hyphens<br>
in your example) but rather that you closed the quote. Your generated<br>
SQL was:<br>
<br>
insert into reviews (message, title) values ('We don't know where to<br>
<div class="im">go', 'We can't wait till morrow')<br>
<br>
</div>which means a string of:<br>
"We don"<br>
SQL garbage<br>
<div class="im"> t know where to go<br>
</div>string<br>
", "<br>
SQL garbage<br>
We can<br>
and another string<br>
"t wait till morrow"<br>
<span class="HOEnZb"><font color="#888888">--<br>
Wulfraed Dennis Lee Bieber AF6VN<br>
<a href="mailto:wlfraed@ix.netcom.com">wlfraed@ix.netcom.com</a> <a href="HTTP://wlfraed.home.netcom.com/" target="_blank">HTTP://wlfraed.home.netcom.com/</a><br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><i>Satajanus Nig. Ltd<br><br><br></i><br>
</div>