Print

Print


Hi Jacek,


    In general, parameter substitution in the Python DBAPI only works for values, not for any sort of name (column/table/database). Yo’llu have to substitute names yourself, so you should write:

cursor.execute(“CREATE DATABASE `%s`” % dbName)

to create a database with the desired name. See e.g. http://stackoverflow.com/questions/9394291/python-and-mysqldb-substitution-of-table-resulting-in-syntax-error.

Cheers.
Serge


On Apr 21, 2015, at 12:21 PM, Jacek Becla <[log in to unmask]> wrote:

Brian and I have troubles forcing sqlalchemy to do proper escaping/binding. The bottom line is that it is not clear
how to do that even in plan mysqldb, we eg tried this:


#!/usr/bin/python

import MySQLdb

con = MySQLdb.connect(unix_socket="/var/run/mysqld/mysqld.sock", user="becla")
cursor = con.cursor()

# this will create database called 'aaa' (with quotes!)
# cursor.execute("CREATE DATABASE `%s`", ('aaa',))

# all these reports "wrong syntax" error
# cursor.execute("CREATE DATABASE %s", ('aaa',))
# cursor.execute("CREATE DATABASE '%s'", ('aaa',))

cursor.close()
con.close()


Are we missing something obvious???

J.

########################################################################
Use REPLY-ALL to reply to list

To unsubscribe from the QSERV-L list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=QSERV-L&A=1



Use REPLY-ALL to reply to list

To unsubscribe from the QSERV-L list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=QSERV-L&A=1