<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">Currently I am working on just a prototype to show what is possible to</div>
be done to get me some fundings for my future work. after that I will<br>
get over to an SQL Alchemy. It's ORM will take over this business for<br>
me.<br>
<br>
A lot of people a not aware of SQL injection. My friend from college<br>
asked me and a couple of other guys for Pen testing of an website. His<br>
SQL injection mistake made him an epic fail.<br>
</blockquote><div><br></div><div>You don't really need to go the full ORM route to do this safely -- constructing SQL from user input is not only wrong from a security point of view, but it's actually just harder to do it that way then use the mechanisms provided in PEP-249 compliant DB-API modules. Life's easier if you use parameterized queries, really :)</div>

<div><br></div><div>You're probably connecting to your database via a DB-API compatible library, I assume? Most are. If so, it's simply a matter of:</div><div><br></div><div>cur = con.cursor()</div><div>cur.execute("SELECT name FROM blah WHERE id = ? AND zone = ?", (my_id, my_zone))</div>

<div><br></div><div>All DB-API compliant modules support this, though some mark the parameters differently. That's qmark, some alternates are numeric (:1, :2, etc), some named (:id, :zone), some format (%s, %d, etc), some pyformat, (%(id)d, %(zone)s).</div>

<div><br></div><div>The module should provide a 'paramstyle' stating what is supported.</div><div><br></div><div>--S</div></div>