On Sun, Jun 27, 2010 at 3:20 PM, <petko...@dir.bg> wrote: > I have tried the following, too: > > from pg8000 import DBAPI > import os > import os.path > import sys > > # !!! that is test data. It must be changed > conn=DBAPI.connect(host="localhost", database="postgres", user="postgres", > password="test") > > #conn.cursor will return a cursor oject, you can use this cursor to perform > queries > cursor = conn.cursor() > > file = open( > "C:\\Blender_Library\\BlenderLib\\objectLib\\Faqns\\Osaka2\\faqns_osaka_2.jpg", > "rb" ) > data1 = DBAPI.Binary(file.read()) > data2 = 'faqns_osaka_2' > > # execute our Query > cursor.execute("UPDATE testtable SET jpeg = %s WHERE testtable_n = %s", > data1, data2) > sys.stdout.flush() > > # Save (commit) the changes > conn.commit() > > # We can also close the cursor if we are done with it > cursor.close() > > The problem this time was: > Traceback <most recent call last>: > File "insertdb_pg8000.py", line 19, in <module> > cursor.execute("UPDATE testtable SET jpeg = %s WHERE testtable_n = > %s", data1, data2) > File "build\bdist.win32\egg\pg8000\dbapi.py", line 243, in _fn > TypeError: execute() takes at most 3 arguments (4 given) > > I don't have any insight into your other piece of code, but here I think you just need another set of parentheses - so that the string interpolation is done first, and the result of it becomes the argument to cursor.execute(). I can't really test it at the moment, but try changing it to: cursor.execute( ("UPDATE testtable SET jpeg = %s WHERE testtable_n = %s", data1, data2) )
Either that, or break it into two lines: myQuery = "UPDATE testtable SET jpeg = %s WHERE testtable_n = %s", data1, data2 cursor.execute(myQuery) -- www.fsrtechnologies.com
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor