Another MySQL Question
Victor Subervi
victorsubervi at gmail.com
Thu Jun 3 08:49:44 EDT 2010
Hi;
I have this code:
options = ''
our_options = []
our_options_string = ''
for op in ops:
options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:])
our_options.append('%s' % form.getfirst('%s' % op))
our_options_string += '%s", "' % op
cursor.execute('''create table if not exists tmp%s (
Store varchar(40) not null,
PatientID varchar(40) not null,
ProdID varchar(40) not null,
Pkg varchar(10) not null,
%s)''' % (tmpTable, options[:-2]))
sql_string = 'insert into tmp%s values (%s, %s, %s, %s, "%s")' %
(tmpTable, store, patientID, prodid, pkg, our_options_string[:-4])
print sql_string
sql = 'insert into tmp%s values (%s, %s, %s, %s, %%s)' % (tmpTable,
store, patientID, prodid, pkg)
cursor.execute(sql, (our_options,))
Now, I can insert that printed string, but my execute throws this error:
Traceback (most recent call last):
File "/var/www/html/angrynates.com/cart/insertOrder.py", line 235, in ?
insertOrder()
File "/var/www/html/angrynates.com/cart/insertOrder.py", line 228, in
insertOrder
cursor.execute(sql, (our_options,))
File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 163, in
execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line 35,
in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1136, "Column count doesn't match value count at row 1")
So it appears to me that it's saying there's only one value packed in
our_options; however, there are in fact two. Please advise.
TIA,
beno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100603/e3b2cd3a/attachment.html>
More information about the Python-list
mailing list