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. Advertisements

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. Guest
    Replies:
    2
    Views:
    1,474
    Kevin Spencer
    Nov 21, 2003
  2. loveNUNO
    Replies:
    2
    Views:
    1,189
    loveNUNO
    Nov 20, 2003
  3. Gactimus
    Replies:
    12
    Views:
    987
    Chris \( Val \)
    Nov 18, 2004
  4. Josh Valino

    Copying styles from one control to another

    Josh Valino, Aug 22, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    428
    HillBilly
    Aug 23, 2008
  5. C. J. Clegg
    Replies:
    63
    Views:
    4,767
    Keith Thompson
    Mar 18, 2009
  6. janus

    Copying one array to another array

    janus, Feb 3, 2010, in forum: C Programming
    Replies:
    16
    Views:
    869
    Peter Nilsson
    Feb 3, 2010
  7. Robert Cohen
    Replies:
    3
    Views:
    549
    Andrew Durstewitz
    Jul 15, 2003
  8. Sam
    Replies:
    4
    Views:
    183
    Mark Lawrence
    Jan 17, 2014
Loading...