update images inside a mysql database

Discussion in 'Python' started by Jonas Meurer, Feb 24, 2005.

  1. Jonas Meurer

    Jonas Meurer Guest

    hello,

    i develop a project with a mysql interface. one mysql table holds all
    the images for my project.

    everything works quite well so far, except i'm not able to upload images
    into the database. the following function does the mysql UPDATE, it
    requires the image and the image ID as arguments.

    additionally it dumps the image to my filesystem ('/tmp/image.gif') -
    i test this with gif images.

    for some reason, the file dumped to /tmp/image.gif is exactly the same
    as uploaded, but in mysql the file is corrupted, far to small and not
    even viewable.

    here is my function:

    def i_update(image, imgid):
    image = "%s" % (image)
    sql_exec = """UPDATE Images SET Image='%s' WHERE ImgID = '%s'
    """ % (image, imgid)
    o = open("/tmp/file.jpg", "w")
    o.write(image)
    o.close()
    db_connect.cursor.execute(sql_exec)


    i've the strong feeling that the substitution makes problems. if the
    string 'image' conains ' or " for example, the sql_exec is broken.

    what do you suggest?

    bye
    jonas
    Jonas Meurer, Feb 24, 2005
    #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. Matt
    Replies:
    0
    Views:
    384
  2. Jonas Meurer
    Replies:
    2
    Views:
    410
    Jonas Meurer
    Feb 25, 2005
  3. Alina Ghergu
    Replies:
    3
    Views:
    494
    Alina Ghergu
    Sep 6, 2006
  4. Robert
    Replies:
    2
    Views:
    157
    Florian GroƟ
    Sep 9, 2005
  5. julian
    Replies:
    8
    Views:
    448
    Avatar
    Apr 6, 2006
Loading...

Share This Page