uploading binary file - ODBC (SapDB)
Dan Fratean
danf at astral.ro
Thu Feb 20 05:58:07 EST 2003
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
--
/dan fratean
More information about the Python-list
mailing list