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

B

bobb

(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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top