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

Discussion in 'Python' started by bobb, Jan 5, 2004.

  1. bobb

    bobb Guest

    (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()
     
    bobb, Jan 5, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markusek Peter

    save BLOB to file from MySQL using c#

    Markusek Peter, Feb 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    24,209
    chemacecilia
    Jun 9, 2007
  2. =?Utf-8?B?S2VubmV0aCBQ?=

    MySql's equivalence to MsSql's 'TOP' command/function/clause

    =?Utf-8?B?S2VubmV0aCBQ?=, Jan 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,757
    John Timney \(ASP.NET MVP\)
    Jan 8, 2005
  3. Roedy Green
    Replies:
    0
    Views:
    4,140
    Roedy Green
    Aug 23, 2003
  4. Moerderin

    Blob using MySQL

    Moerderin, Jul 30, 2004, in forum: Java
    Replies:
    6
    Views:
    9,956
    John Fereira
    Jul 31, 2004
  5. Sam
    Replies:
    4
    Views:
    73
    Mark Lawrence
    Jan 17, 2014
Loading...

Share This Page