uploading binary file - ODBC (SapDB)

Daniel Dittmar daniel.dittmar at sap.com
Thu Feb 20 06:23:38 EST 2003


> into a long byte column. In this way I could upload the first 6 bytes:>
'ELF'. But that's all. Any ideas?

How do you check the value? If you try to look at it in SQL Studio, then it
might be that the data gets truncated on the first '\0'. If you read the
LONG from a Python script (the example script does that), does the
truncation happens there too? Please use sapdb.sql for reading, as I don't
know what mxODBC is doing in that case, maybe you'll have to call
.setoutputsizes () on the cursor.

Daniel


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?
>
> 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
>> noticed
>> - 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 ODBC.
>>
>> 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
>> http://www.sapdb.org/7.4/longtest.py.html.
>>
>> 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])
>>
>> Daniel
>>
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list