Problem with write binary data to OLE field in Access
lialie
lialie at gmail.com
Wed Mar 26 12:21:15 EDT 2008
Hi~
I would like to save images in OLE field in Microsoft Access. It writes
the binary data which read from an JPEG/BMP file.
But seems I meet an encoding problem.
The following code demos that.
Any sugguestion?
---------------------------------------------------------------------------
import win32com.client as wc
conn = wc.Dispatch(r'ADODB.Connection')
recordset = wc.Dispatch(r'ADODB.RecordSet')
dsn = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source="test.mdb";'
conn.Open(dsn)
print conn
k = recordset.Open('[tblImageDataTypes]', conn, 1, 3)
#recordset.AddNew()
#recordset.Fields('Field3_GENERAL').AppendChunk(open('tt.jpg', 'rb').read())
#recordset.Update()
#print ">>> Actual Size: ", recordset.Fields('Field3_GENERAL').ActualSize
recordset.MoveFirst()
kk = recordset.Fields('Field3_GENERAL').GetChunk(
recordset.Fields('Field3_GENERAL').ActualSize)
print len(str(kk).decode('utf-16'))
print len(open('tt.jpg', 'rb').read())
recordset.Close
conn.Close()
###############################
One of the results:
the length of original file is : 2598
the actual size of the field is: 3658
the length decode from the chunk is: 1829
I try to write some text files into the filed and read it out, it is OK.
Windows XP sp2; Python 2.4.4; Pywin32 210; Microsoft Access 2002
---------------------------------------------------------------------------------------
Regards,
lialie
More information about the Python-list
mailing list