Copying a blob from one mysql record to another with a where clause

bobb RAWBOBB at hotmail.com
Mon Jan 5 03:42:23 CET 2004


(I'm a long term newbie :) )
I wanted to copy a blob's contents in mysql in python from one record to another.
I had a heck of a time with it, so I wanted to post it for others.
The where clause was the tricky part for me.
It probably has poor syntax, but it works.
(Obviously) it can be used cross table and across db's.


import MySQLdb

con0 = MySQLdb.connect(host="localhost",user="",passwd="",db="in")
con1 = MySQLdb.connect(host="localhost",user="", passwd="", db="in")


sourcefield = 'logo'
sourceid = 2514
# A string
s = 2515

curs0=con0.cursor()
selectstring = "select %s from table where id = %s" % (sourcefield, sourceid)
curs0.execute(selectstring)

sourceresult = curs0.fetchone()

cursor1 = con1.cursor()


s1 = "update table set "+ sourcefield + " = %s where id = " 
s2 = s1 + str(s)
tup = s2
cursor1.execute(tup[::],(sourceresult )) 

con0.close()
con1.close()



More information about the Python-list mailing list