<div class="gmail_quote">On Sun, Jun 27, 2010 at 3:20 PM, <span dir="ltr"><<a href="mailto:petkovas@dir.bg">petkovas@dir.bg</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I have tried the following, too:<br>
<br>
from pg8000 import DBAPI<br>
import os<br>
import os.path<br>
import sys<br>
<br>
# !!! that is test data. It must be changed<br>
conn=DBAPI.connect(host="localhost", database="postgres", user="postgres", password="test")<br>
<br>
#conn.cursor will return a cursor oject, you can use this cursor to perform queries<br>
cursor = conn.cursor()<br>
<br>
file = open( "C:\\Blender_Library\\BlenderLib\\objectLib\\Faqns\\Osaka2\\faqns_osaka_2.jpg", "rb" )<br>
data1 = DBAPI.Binary(file.read())<br>
data2 = 'faqns_osaka_2'<br>
<br>
# execute our Query<br>
cursor.execute("UPDATE testtable SET jpeg = %s WHERE testtable_n = %s", data1, data2)<br>
sys.stdout.flush() <br>
<br>
# Save (commit) the changes<br>
conn.commit()<br>
<br>
# We can also close the cursor if we are done with it<br>
cursor.close()<br>
<br>
The problem this time was:<br>
Traceback <most recent call last>:<br>
File "insertdb_pg8000.py", line 19, in <module><br>
cursor.execute("UPDATE testtable SET jpeg = %s WHERE testtable_n = %s", data1, data2)<br>
File "build\bdist.win32\egg\pg8000\dbapi.py", line 243, in _fn<br>
TypeError: execute() takes at most 3 arguments (4 given)<br>
<br></blockquote><div><br>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:<br>
cursor.execute( ("UPDATE testtable SET jpeg = %s WHERE testtable_n = %s",
data1, data2) )<br><br>Either that, or break it into two lines:<br><br>myQuery = "UPDATE testtable SET jpeg = %s WHERE testtable_n = %s",
data1, data2<br>cursor.execute(myQuery)<br><br></div></div>-- <br><a href="http://www.fsrtechnologies.com">www.fsrtechnologies.com</a><br>