"""modifypix.py -- change image in database -- version 0.0

version 0.0 2011-02-17 by Vernon Cole - vernondcole@gmail.com 
"""
#Expects Python version 2.6 or later from http://python.org
#  and a matching pywin32 from http://sourceforge.net/projects/pywin32
#  and adodbapi version 2.4.2 or later from http://sourceforge.net/projects/adodbapi

#---------------------------------------------
#subroutine to open and read a binary file 
def readpic(fname):
    with open(fname,'rb') as infile:
        buf = infile.read()
    return buf
# -------------- main program starts here -------------------------------
if __name__ == '__main__':
    import adodbapi
    constr = "Provider=SQLOLEDB.1; Integrated Security=SSPI; Initial Catalog={db};Data Source={dbsrvr}"
    s = constr.format(dbsrvr='(local)', db='Imagenes')

    adodbapi.adodbapi.verbose = True   #debugging output

    buf = readpic('16.jpg')
    con = adodbapi.connect(s)           # connect to the db server
    c = con.cursor()                    # open a cursor on the connection
    sql = 'update Fotos set Foto = ?, Descripcion = ? where Codigo = ?'
    c.execute(sql,[buf,'Emergency equipment on Salt Flats',6])
    if c.rowcount >= 0:
        print('Updated',c.rowcount,'records')
    c.close()
    con.commit()
    con.close
    