On Mon, 06 Feb 2006 13:39:17 +0000, Steve Holden wrote: > Chason Hayes wrote: >> I am trying to convert raw binary data to data with escaped octets in >> order to store it in a bytea field on postgresql server. I could do this >> easily in c/c++ but I need to do it in python. I am not sure how to read >> and evaluate the binary value of a byte in a long string when it is a non >> printable ascii value in python. I read some ways to use unpack from the >> struct module, but i really couldn't understand where that would help. I >> looked at the MIMIEncode module but I don't know how to convert the object >> to a string. Is there a module that will convert the data? It seems to me >> that this question must have been answered a million times before but I >> can't find anything. >> >> >> >> See http://www.postgresql.org/docs/8.1/interactive/datatype-binary.html >> for a description of the problem domain. >> >> > The URL you reference is discussing how you represent arbitrary values > in string literals. If you already have the data in a Python string the > best advise is to use a parameterized query - that way your Python DB > API module will do the escaping for you! > > regards > Steve
Thanks for the input. I tried that with a format string and a dictionary, but I still received a database error indicating illegal string values. This error went away completely when I used a test file consisting only of text, but reproduced everytime with a true binary file. If you can let me know where I am wrong or show me a code snippet with a sql insert that contains a variable with raw binary data that works, I would greatly appreciate it. Chason -- http://mail.python.org/mailman/listinfo/python-list