473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

(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()
Jul 18 '05 #1
0 1201

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sams | last post by:
Iam posting this after trying many tutorials in the NG and failing to retrieve the blob out of a record. So please bear with me before before you pull the water hose or flame throwers ...... I...
7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or...
3
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around...
5
by: Lyn | last post by:
I am trying to copy selected fields from one table to another, by reading the source table record into a recordset (ADO) and then copying the relevant fields to an SQL statement "INSERT INTO...". ...
2
by: m.k.ball | last post by:
Thanks Rich - that's great. Before I found this group, I thought I had a reasonable understanding of SQL (well, MySQL's implementation of it, at least) but the truth is there are great chunks that...
2
by: Ted | last post by:
1) In several tables, in my MySQL version, I created columns using something like the following: `ab_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, This...
6
by: onnodb | last post by:
Hi all, While working on an Access UI to a MySQL database (which should be a reasonable, low-cost, flexible interface to the DB, better than web-based, much less costly than a full-fledged .NET...
2
by: Vinciz | last post by:
hi guys... im new in java and i would love to learn some of these... basically i got a sample code to retrieve the blob from the mysql. however, i dont really know what to do with these...
6
by: bill | last post by:
I am about to start on a module that will accept a location from a user, use Google geolocation services to get the lat/lon and then compute the distance from the site visitor to about 100 kennels...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.