473,800 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MySQL error from Python

I encountered the following error when trying to perform a SQL UPDATE to a
MySQL database table from Python.

I would apprciate any assistance. In the Python code I have tried integer
and decimal format specifiers in addition to the string specifier and
nothing worked.

Traceback (most recent call last):
File "e:\my_python_s cripts\commerce craft.py", line 36, in ?
cursor.execute ("UPDATE product SET price = '%s' WHERE competitorID=1
AND sku = '%s'",(myprice, mysku))
File "E:\Python22\Li b\site-packages\MySQLd b\cursors.py", line 95, in
execute
return self._execute(q uery, args)
File "E:\Python22\Li b\site-packages\MySQLd b\cursors.py", line 114, in
_execute
self.errorhandl er(self, exc, value)
File "E:\Python22\Li b\site-packages\MySQLd b\connections.p y", line 33, in
defaulterrorhan dler
raise errorclass, errorvalue
_mysql_exceptio ns.ProgrammingE rror: (1064, "You have an error in your SQL
syntax. Check the manual that cor
responds to your MySQL server version for the right syntax to use near
'139.80'' WHERE competitorID=1 AND sk
u = ''50300288''' at line 1")


Describe product;

Field Type Null Key Default Extra
------------ ------------ ------ ------ ------- --------------
productID int(11) PRI (NULL) auto_increment
sku varchar(50) YES (NULL)
description varchar(60) YES (NULL)
price decimal(7,2) YES (NULL)
scrape_date datetime YES (NULL)
competitorID int(11) YES (NULL)

*************** *************** *************** *************** **
import test_iopus
import MySQLdb
import sys
import string
try:
conn = MySQLdb.connect (host = "localhost" ,
user = "root",
passwd = "xyz",
db = "commerce")
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)

cursor = conn.cursor()
cursor.execute ("SELECT sku FROM product WHERE competitorID=1" )
while (1):
row = cursor.fetchone ()
if row == None:
break
mysku = row[0]
print mysku
print "%d rows were returned" % cursor.rowcount

result = test_iopus.Scra pe(mysku)
price = result.split(" ")
tmpprice = str(price[0])

conversion = string.maketran s("$"," ")
myprice = tmpprice.transl ate(conversion)
print myprice

cursor.execute ("UPDATE product SET price = '%s' WHERE competitorID=1 AND
sku = '%s'",(myprice, mysku))
cursor.close()
conn.close()
Jul 18 '05 #1
3 2422
You probably should write
cursor.execute ("UPDATE product SET price = %s WHERE competitorID=1"
" AND sku = %s",(myprice,my sku))
(remove the single-quotes -- the splitting of the string makes no
difference vs a single line) not
cursor.execute ("UPDATE product SET price = '%s' WHERE competitorID=1
AND sku = '%s'",(myprice, mysku))


Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA3hDOJd0 1MZaTXX0RAgIqAJ 4toIJNhq3Mc2UOS YvBg6hNxXyO5gCe MdiA
ntIqmZLA3Ik5YWY qM3nL8TA=
=PZl8
-----END PGP SIGNATURE-----

Jul 18 '05 #2
On Sun, 27 Jun 2004 00:04:54 GMT, "Paul M" <no***@nohow.co m> declaimed
the following in comp.lang.pytho n:

cursor.execute ("UPDATE product SET price = '%s' WHERE competitorID=1
AND sku = '%s'",(myprice, mysku))
Get rid of the single quotes around the %s fields... The
..execute method should, in theory, determine the data type and needed
quoting internally.

-- =============== =============== =============== =============== == <
wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.com/> <

Jul 18 '05 #3
That fixed it.

Thank You!
"Dennis Lee Bieber" <wl*****@ix.net com.com> wrote in message
news:4r******** *************** *********@4ax.c om...
On Sun, 27 Jun 2004 00:04:54 GMT, "Paul M" <no***@nohow.co m> declaimed
the following in comp.lang.pytho n:

cursor.execute ("UPDATE product SET price = '%s' WHERE competitorID=1 AND sku = '%s'",(myprice, mysku))


Get rid of the single quotes around the %s fields... The
.execute method should, in theory, determine the data type and needed
quoting internally.

--
> =============== =============== =============== =============== == <
> wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wu******@dm.net | Bestiaria Support Staff <
> =============== =============== =============== =============== == <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.ne tcom.com/> <

Jul 18 '05 #4

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

Similar topics

2
10289
by: francescomoi | last post by:
Hi. I'm trying to build 'MySQL-python-1.2.0' on my Linux FC2: ---------------------------------- # export PATH=$PATH:/usr/local/mysql/bin/ # export mysqlclient=mysqlclient_r # python setup.py clean # python setup.py build running build running build_py
1
15879
by: francescomoi | last post by:
Hi. I'm trying to build MySQL-python-1.2.0 on my Linux FC2 (with MySQL 3.23.58). But when building, I get this error message: ------------------------------------------------------- # python setup.py build running build running build_py running build_ext building '_mysql' extension
2
2560
by: Cathy Hui | last post by:
Do u know why do i get the following message when trying to build the MySql-Python (1.2.0) on my Solaris 8 system? (with mysql 4.0.21 and python 2.4). thanks! error mesg: ld: fatal: relocations remain against allocatable but non-writable sections collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1
3
863
by: Mark Adams | last post by:
I am a relative newbie to MySQL. I had a Postfix+Courier+MySQL mail server running for several months. It took me a week or so to get it up and running in September. Now, I did a clean upgrade to Mandrake 9.2 and am reinstalling everything. This thing is kicking my ass and I can't seem to get past it. I could really use some help if anybody has any. Just for reference, this was my primary source for information on installation and...
0
1768
by: google account | last post by:
*sigh* I have done all that I know how.... I am using fedora core1, I believe. I have updated the MySQL version to 4.0.17-0. I am trying this: rpm -i MySQL-python2.1-0.9.2-1.i386.rpm
3
7009
by: Nick | last post by:
hi, all I have a red hat 9 and looks like it had mysql 3.2.54 installed before, but, actually not, i can not find the install folder and I can not uninstall it. So I am trying to install/upgrade to 4.1, but, still can not get it work. Here is what I did: # rpm -Uvh MySQL-server-standard-4.1.14-0.rhel4.i386.rpm warning: MySQL-server-standard-4.1.14-0.rhel4.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
2
1842
by: simen.haugen | last post by:
Hi. I'm trying to use Python 2.4 with MySql 5.0, but I'm having installation problems. I've tried to follow the following articles to install mysql-python with the free visual c++ toolkit http://mail.python.org/pipermail/python-list/2004-December/255184.html http://www.vrplumber.com/programming/mstoolkit/
1
3017
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 help me out in solving the issue. I'd like to get this solved so I can continue developing with Django using MySQL since that's what my web server uses as well. I'd hate to have to develop using a different database engine on my local...
3
1237
by: chinnujoy | last post by:
Hi I am using CentOS 4 machine..trying to install MySQL for python to setup a boinc project.. During the building process I am getting this error..I have even set the LD lIBRARY PATH.. ./python -E ./setup.py build ./python: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory I tried installing both the ways.. 1. downloaded mysql for the python present and builded...
0
1721
by: Edwin.Madari | last post by:
-----Original Message----- statement prepared first and executed many times with exectemany - db API http://www.python.org/dev/peps/pep-0249/ inline statemets can be exeucuted only. hope that helps Edwin
0
9551
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10279
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4150
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
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.