Thursday, June 28, 2007

oracle: data with single quote

When using java, prepared statement can insert string with single quote easily. I tried to achieve the same thing with python. I finally got prepared statement using cx_Oracle, but it was very ugly and unintuitive.
I tried this task with postgresql hoping for a better solution. Things were worse in Postgres. I knew that my favorite psycopg2 does not support prepared statement, yet. But, the rest of the drivers, such as pypgsql and all others that I have researched, were in the same status.

Anyway, I found this this link:
http://catherinedevlin.blogspot.com/2005_07_01_archive.html

Oracle had a different idea. Different quote operator. q'| |'. Like python block quote('''), it relieves single quote when wrapped around it.

Insert into tbl(txt) values ( q'|Hello world's geeks.|' );

No comments: