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

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top