String formatting - mysql insert

Christian ozric at web.de
Thu Jul 14 17:00:14 CEST 2011


Hi,

I get some problem  when i like to set the table name dynamic.
I'm appreciate for any help.

Christian

### works ####
newcur.execute (  """ INSERT INTO events (id1,id2)   VALUES  (%s,%s);
""" , (rs[1],rs[2]))

### works not
newcur.execute (  """ INSERT INTO %s_events (id1,id2)   VALUES  (%s,
%s); """ , (table_name,rs[1],rs[2]))

### works but is not really perfect: None from rs list result in
"None" instead of NULL.
newcur.execute (  """ INSERT INTO %s_events (id1,id2)   VALUES
('%s','%s'); """  %  (table_name,rs[1],rs[2]))



More information about the Python-list mailing list