[DB-SIG] Mysqldb python variable in request

Marcos Sánchez Provencio msanchez at grupoburke.com
Thu Jan 22 04:55:07 EST 2004


I am not an expert in mysql, but i believe column names can not be a 
parameter. You should create the sql with the column names, and leave 
only the value as a parameter.


cursor.execute(' select ' +target+  ' from Xml2Mysql where ' 
+constraint+ '=%s ',(constraint_value,))


samira M'Bata wrote:

> Hi!
> i hope someone could help me.
> I d like to make an sql statement with python, in which the column 
> names will be parameter of a python function.
> Bevore I tried to define my definition, i tried this code:
>
> target= 'DataType'
> constraint= 'Location'
> #DataType and Location are two columns of my Table
> constraint_value= 'stuttgart'
> cursor.execute(""" select %s from Xml2Mysql where %s=%s """,(target, 
> constraint, constraint_value))
>
> I think the problem comes from the fact that my columns names are not 
> as a string type defined.
>
> Should I change something in my table definition?
>
> _________________________________________________________________





More information about the DB-SIG mailing list