473,566 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MySQLdb module, method executemany with anything other than strings?

The method cursor.executem any is there in order to avoid multiple calls
to cursor.execute( ).

I have tried, with success, to do like every single example (that I
have found on the www) on the subject shows, to use a insert statement
on the form:
statement = INSERT INTO table (colA,colB,colC ) values (%s,%s,%s)

and pass in a list containing tuples
list = [('bla','bla','b la'),('bla','bl a','bla'),('bla ','bla','bla')]

on the form

cursor.executem any(statement,l ist)

This works fine for all strings, but I have never been able to insert a
single integer or a float using this method. I get an error message
reporting that float (or an int) is required.

Statement is then of course changed to something like
statement = INSERT INTO table (colA,colB,colC ) values (%s,%i,%f)
list = [('bla',1,0.65), ('bla',3,3.7),( 'bla',3,0.9)]

Havee anybody experienced similar problems?
Am I doing something wrong?
Any feedback is greatly appreciated.
Here is som real output from the interpreter:
statement = 'insert into testtable3 (url,probabilit y) values (%s,%f)'
l [('url1', 0.9899999999999 9999), ('url2', 0.8900000000000 0001)] cursor.executem any(statement,l )

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python24\Li b\site-packages\MySQLd b\cursors.py", line 181, in
execu
any
self.errorhandl er(self, TypeError, msg)
File "C:\Python24\Li b\site-packages\MySQLd b\connections.p y", line 33,
in de
lterrorhandler
raise errorclass, errorvalue
TypeError: float argument required

Aug 25 '05 #1
2 3983
ol************* ***@gmail.com wrote:
The method cursor.executem any is there in order to avoid multiple calls
to cursor.execute( ).

I have tried, with success, to do like every single example (that I
have found on the www) on the subject shows, to use a insert statement
on the form:
statement = INSERT INTO table (colA,colB,colC ) values (%s,%s,%s)

and pass in a list containing tuples
list = [('bla','bla','b la'),('bla','bl a','bla'),('bla ','bla','bla')]

on the form

cursor.executem any(statement,l ist)

This works fine for all strings, but I have never been able to insert a
single integer or a float using this method. I get an error message
reporting that float (or an int) is required.

Statement is then of course changed to something like
statement = INSERT INTO table (colA,colB,colC ) values (%s,%i,%f)
list = [('bla',1,0.65), ('bla',3,3.7),( 'bla',3,0.9)]

Havee anybody experienced similar problems?
Am I doing something wrong?
Any feedback is greatly appreciated.
Here is som real output from the interpreter:
statement = 'insert into testtable3 (url,probabilit y) values (%s,%f)' ^^
That's your problem, right there.l
[('url1', 0.9899999999999 9999), ('url2', 0.8900000000000 0001)]
cursor.exec utemany(stateme nt,l)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python24\Li b\site-packages\MySQLd b\cursors.py", line 181, in
execu
any
self.errorhandl er(self, TypeError, msg)
File "C:\Python24\Li b\site-packages\MySQLd b\connections.p y", line 33,
in de
lterrorhandler
raise errorclass, errorvalue
TypeError: float argument required

It's just that you should use "%s" for *all* parameters, no matter what
their type:
conn = db.connect()
curs = conn.cursor()
curs.execute("" " .... create table thingy(
.... f1 char(10) primary key,
.... f2 float)""")
0L l = [('url1', 0.9899999999999 9999), ('url2', 0.8900000000000 0001)]
curs.executeman y(""" .... insert into thingy (f1, f2) values (%s, %s)""", l)
2L


regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Aug 25 '05 #2
I just realised that myself about two minutes ago, but thanks anyway!

Aug 25 '05 #3

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

Similar topics

21
5227
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All works as expected. But >>> numb=10 >>> cursor.execute("SELECT * FROM mytest where clientID = %d",numb) Traceback (innermost last): File...
6
2421
by: Daniel Bowett | last post by:
I have just started playing around with MySQLdb for a project I am planning. As a test I have written a script that executes 3000 insert statements on a table. The table contains 10 fields with a mix of text and numbers - its a product table for a website eg UPC, ProductName, Price etc. The problem I have is that it takes just over two...
0
3668
by: Daniel Bowett | last post by:
I seem to have found a bug/limitation of executemany in MySQLdb. I am inserting 3100 records into a database. It works fine and adds them in about 1 second. I went back to the program today and realised i'd missed a field so added it to the insert statement. This seems to break it if I try to add all the records in one go. Through trial...
1
4157
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) ...
1
2202
by: Grzegorz Smith | last post by:
Hi all. I'm trying get data from text field in MySQl 5.0 with my National characters. Data are stored in utf8 encodings. Here is the script: import MySQLdb, MySQLdb.cursors conn = MySQLdb.connect(host='localhost', user='root', passwd='123456', db='profile_locale') c = conn.cursor(MySQLdb.cursors.DictCursor) c.execute("SET CHARACTER SET...
8
2763
by: geert | last post by:
Hi all, I have a mac mini running maocosx 10.5 leopard I want to deploy a django project on. My backend is MySQL, and I have it running as a 64- bit app. Of course, apache2 is also running as 64-bit. MySQLdb installs with the usual warnings after applying the various patches I found here and there. These patches consist of altering...
1
1696
by: Aljosa Mohorovic | last post by:
i have a working MySQLdb module (/usr/lib/python2.4/site-packages/ MySQL_python-1.2.2-py2.4-linux-i686.egg), using it without problems. "clean shell" after login: python -c "import MySQLdb" reports no errors if i export PYTHONPATH: export PYTHONPATH=/var/www/projects/uv_portal/portal python -c "import MySQLdb" reports no errors as in...
0
239
by: David | last post by:
You're welcome. executemany is probably a good idea here. If memory becomes a problem at some point (eg: millions of lines) you'll probably want to use an on-disk database (I suggest postgresql), and read in batches of say 1000, which you save to the database with a single executemany. It sounds like your Python code has some serious...
3
1870
by: Lawrence D'Oliveiro | last post by:
In message <mailman.109.1216158151.922.python-list@python.org>, Cyril Bazin wrote: What's the error message? This should be in Apache's error_log file.
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.