Problem with write binary data to OLE field in Access

L

lialie

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top