Updating SQL table problems with python

Andy Todd andy47 at halfcooked.com
Thu Jun 5 12:02:11 CEST 2003

DJ wrote:

> Realised when posting this that title value is misspelt
> That was not the error though :)
> "DJ" <dj3000 at iinet.net.au.nospam> wrote in message
> news:3eddac41$0$31519$5a62ac22 at freenews.iinet.net.au...
>>Hi there,
>>I get a Syntax error from this following SQL statement:
>>file_open = urllib.urlopen(url)
>>xmldoc = minidom.parse(file_open)
>>blah = xmldoc.toxml()
>>title = minidom.parseStrin(blah).getElementsByTagNam('title')
>>connection = gadfly.gadfly("portal", "dbase")
>>cursor = connection.cursor()
>>for x in title:
>>        j = x.firstChild.data
>>        j = j.encode('ascii', 'replace')
>>        cursor.execute("update items set title = '%s' where title =
> 'Title'"
>>% j)
>>        connection.commit()
>>As you can tell, im parsing a xml RSS feed and updating items table. Im
>>trying to replace
>>default value of 'Title' with the title from the RSS feed.
>>The update statement is givng me the syntax error
>>I cant see whats wrong
>>Need some help
>>Thanks in advance

What error message are you getting? The only thing that I can see which 
*might* be causing you trouble is your use of the 'format' paramstyle 
rather than the prescribed 'qmark' style.

If you change your execute statement to;

     cursor.execute("update items set title=? where title='Title'", (j,))

You may get a different outcome.

For a definition of the different paramstyles, check the DB-API 
specification at http://www.python.org/peps/pep-0249.html

For a description of how to use dynamic values in Gadfly, see 


More information about the Python-list mailing list