473,321 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

python/mysql/list question...

hi.

i have the following sample code. i'm trying to figure out if there's a way
to use a 'list of lists' in a mysql execute...

i've tried a variety of combinations but i get an error:
Error 1241: Operand should contain 1 column(s)

the test code is:

insertSQL = """insert into appTBL
(appName, universityID)
values(%s,%s)"""

a = []
b = []
a.append('qqa')
a.append(222)
b.append(a)
a=[]
a.append('bbb')
a.append(66)
b.append(a)

try:
c.execute(insertSQL, (b[0],b[1])) <<<<<<<<<<<<<<<<<<<
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
print b
sys.exit (1)

i've tried to use b, (b), etc...
using b[0] works for the 1st row...
any thoughts/comments...

thanks
Aug 11 '06 #1
1 1926

bruce wrote:
hi.

i have the following sample code. i'm trying to figure out if there's a way
to use a 'list of lists' in a mysql execute...

i've tried a variety of combinations but i get an error:
Error 1241: Operand should contain 1 column(s)

the test code is:

insertSQL = """insert into appTBL
(appName, universityID)
values(%s,%s)"""

a = []
b = []
a.append('qqa')
a.append(222)
b.append(a)
a=[]
a.append('bbb')
a.append(66)
b.append(a)
What's wrong with b = [['qqa', 222], ['bbb', 66]] ???
>
try:
c.execute(insertSQL, (b[0],b[1])) <<<<<<<<<<<<<<<<<<<
I don't use mysqldb but here are some thoughts:
(1) the v 2.0 DB API says the second arg should be a list of tuples,
not a tuple of lists
(2) and that usage is deprecated -- use executemany() instead.
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
print b
sys.exit (1)

i've tried to use b, (b), etc...
using b[0] works for the 1st row...
any thoughts/comments...
At first glimpse [like I said, I don't use this and have not visited
the website before now], the author of mySQLdb has put a lot of effort
into the docs e.g.. the executemany() example at the end of this page
answers your question:

http://sourceforge.net/docman/displa...#some-examples

.... why don't you bother to read the docs???

Aug 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Irmen de Jong | last post by:
QOTW: "Confronting the Martellibot is like flirting with an encyclopedia, I'd rather not do it myself, but I respect those who do, because it produces knowledge." -- Anton...
5
by: Zunbeltz Izaola | last post by:
Hi! I am planning a program and I need some advice about what tool to use. Basically my program will deal with a object A. A is a list like object with same attributtes and a list of objects...
1
by: Yong Wang | last post by:
Hi, All: We have a network management system written in C++, MysQL, and Hp SNMP. It works in Solaris command line. When I wrote a similar python codes which call compiled C++ and mysql codes in...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
2
by: Richard Brosnahan | last post by:
I hate asking questions that have probably been answered before, but I have not found a way to conveniently search the archives of this mailing list. So... Can someone tell me how to...
4
by: ataanis | last post by:
Hey all, I'm running a query within some python code, and I'm having difficulties doing something that seems to be really simple . I'm running a query in the following form: query01 = 'select...
13
by: James | last post by:
Hello, I'm a newbie to Python & wondering someone can help me with this... I have this code: -------------------------- #! /usr/bin/python import sys
1
by: Steve Ametjan | last post by:
I've been trying to get MySQL-python to install on Leopard for the past couple of days, and I keep running into relatively the same error. I'm hoping that someone on this list will be able to...
3
by: kyosohma | last post by:
Hi, Is there some way to get a list of "impure" Python modules/extensions from PyPI? I know the mySQL module is a good example, but I am working on creating some decent instructions on how to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.