Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can escape parameters but this not good idea. It is better to use prepared statement. Such statements are much easier do database to parse and use. See at pyodbc explanation: <a href="http://code.google.com/p/pyodbc/wiki/GettingStarted#Parameters" rel="nofollow">http://code.google.com/p/pyodbc/wiki/GettingStarted#Parameters</a></p> <p>There is code that uses such prepared statement:</p> <pre><code>data = [ ('user_name', "Adam 'Adi' Bobek"), ('user_age', 23), ('person_name', "Jurek 'Jerry' Jimowski") ,('person_age', 28), ] data = dict(data) cols = ",".join(data.keys()) qmarks = ','.join(['?' for s in data.keys()]) values = [v for v in data.values()] insert_statement = "INSERT INTO users (%s) VALUES (%s);" % (cols, qmarks) import pyodbc connection = pyodbc.connect('DSN=pglocal') cursor = connection.cursor() cursor.execute(insert_statement, values) connection.commit() </code></pre> <p>Other PostgreSQL/database drivers (psycopg, JDBC) can use similar techniques. This was tested with <code>pyodbc</code> and <code>odbc</code> (part of PyWin32 package that is also part of ActiveState Python distribution).</p> <p>EDIT:</p> <p>There is example of prepared with <code>psycopg2</code>, read: <a href="http://www.psycopg.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries" rel="nofollow">http://www.psycopg.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries</a> to find more:</p> <pre><code>import psycopg2 .... connect_string = 'dbname=test host=localhost port=5493 user=postgres password=postgres' connection = psycopg2.connect(connect_string) cursor = connection.cursor() psycopg_marks = ','.join(['%s' for s in data.keys()]) insert_statement = "INSERT INTO users (%s) VALUES (%s)" % (cols, psycopg_marks) cursor.execute(insert_statement, values) connection.commit() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload