468,765 Members | 1,157 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

Problem with write binary data to OLE field in Access

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
0 1239

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Brandon McCombs | last post: by
6 posts views Thread by arne.muller | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.