uploading binary file - ODBC (SapDB)

M.-A. Lemburg mal at lemburg.com
Thu Feb 20 12:30:45 CET 2003

Dan Fratean wrote:
> OnThanks. It works. Somehow. But it truncates my binary data. Maybe
> because of that special characters? I don't know why. Used that example
> from sapdb.org, tried some more combinations, and still the same
> problem. I made a 'hello world' program in C, and tried to upload it
> into a long byte column. In this way I could upload the first 6 bytes:
> 'ELF'. But that's all. Any ideas?

Make sure you are using LONG BYTE as column type.

> Thanks in anticipation.
>  Thu, 2003-02-20 at 11:13, Daniel Dittmar wrote:
>>Dan Fratean wrote:
>>>I am trying to find a way to upload a binary file into a field from a
>>>database. Can anyone give me some ideas? I can take the file, parse it
>>>and escape the special characters, but I don't like this idea. Better
>>>I would use streams, eventually a persistent ODBC connection. Can
>>Extrapolating the file contents into the SQL isn't a good idea as you
>>- there is a maximum size for SQL statements (configuration dependent)
>>- this doesn't work at all for UPDATE statements
>>Use parameters instead.
>>If you use mxODBC, the following should work:
>>data = open (fname, 'rb').read ()
>>cursor.execute ("insert into sometable (keycol, longcol) values (?, ?)",
>>[keyval, data])
>>I don't know if mxODBC supports the putchunk and getchunk functionality of

Yes. BLOBs are no problem at all -- for any database/ODBCdriver
combo that supports these (most do in some way).

>>You could also use the SAPDB python modules, which allow you to pass streams
>>as parameters so there is no need to load the whole data into memory.
>>An example for the native module sapdb.sql is at
>>An example using the DB API compatible sapdb.dbapi:
>># pass the read method, not the read data
>>reader = open (fname, 'rb').read
>>cursor.execute ("insert into sometable (keycol, longcol) values (?, ?)",
>>[keyval, reader])

Marc-Andre Lemburg

Professional Python Software directly from the Source  (#1, Feb 20 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
Python UK 2003, Oxford:                                     40 days left
EuroPython 2003, Charleroi, Belgium:                       124 days left

More information about the Python-list mailing list