@param param: tuple of string params to insert in the query
(see notes below)
@param n: number of tuples in result (0 for unbounded)
@param with_desc: if true, will return a
DB API 7-tuple describing columns in query
@return: if SELECT, SHOW, DESCRIBE statements: tuples of data, followed
by description if parameter
provided
if INSERT: last row id.
else: SQL result as provided by database
</pre>
<h2>3. <a name="notes">Notes</a></h2>
<h3>3.1 Params</h3>
As said before, params must be of type string. Trying to pass non character data
may lead to an error. Developers should consider converting to string, or render
string before sending, giving no param:
<pre>
initial_params=(1234,)
query = "SELECT id FROM user where id>%s"
params = (str(initial_params[0]),)
run_sql(query, params)
</pre>
or
<pre>
query = "SELECT id FROM user where id>%d" % 1234
run_sql(query)
</pre>
<p>When using this last technique, be careful with SQL injection problem. One should
use the <code>MySQLdb.escape_string()</code> method.
<h3>3.2 Dates</h3>
<p>Switching from MySQLdb 0.9 to MySQLdb 1.2, while using Python 2.2 or 2.3
led to discovery of incompatibilities</p>
<p>If a date field is in the received tuple, its format will be:</p>
<ul>
<li>string with MySQLdb 0.9</li>
<li>datetime with MySQLdb 1.2</li>
</ul>
<p>As Python 2.2 doesn't provide <code>datetime</code> class, handling of this
problem should be done for backwards compatibility reasons. The
solution is to force MySQL to convert date to a textual format:</p>
<pre>
SELECT DATE_FORMAT(date_field,'%%Y-%%m-%%d %%H:%%i:%%s') FROM table
</pre>
<p>This conversion will return a datetext format as described in <a href="./dateutils.html">dateutils library</a><code>(YEAR-MONTH-DAY HOUR:MINUTE:SECOND)</code></p>