Yet Another MySQL Problem
Kushal Kumaran
kushal.kumaran at gmail.com
Thu May 27 13:12:56 EDT 2010
On Thu, 2010-05-27 at 17:56 +0100, MRAB wrote:
> Kushal Kumaran wrote:
> [snip]
> > Since I'm in a good mood today, here's a little present:
> >
> > def insert(cursor, table, columns, values):
> > """Insert a row into a table. columns must be a list of column
> > names. values must be a list of values for the new row. The
> > columns and values must correspond."""
> > assert len(columns) == len(values)
> >
> > stmt = """
> > insert into %s (%s) values (%s)
> > """ % (table,
> > ', '.join(columns),
> > ', '.join('%s' * len(values)))
>
> That should be:
>
> ', '.join(['%s'] * len(values)))
My bad. Tested with sqlite using '?' as the placeholder, then simply
replaced with '%s'.
--
regards,
kushal
More information about the Python-list
mailing list