By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Problem with write binary data to OLE field in Access

P: n/a
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(op en('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
Mar 26 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.