Using python-PgSQL and the doublequote ("") problem...!

D'Arcy J.M. Cain darcy at vex.net
Sat Dec 9 13:04:29 EST 2000


sorular <sorular at netscape.net> wrote:
> Is there a standard sintax to filter the data before entering it into
> PgSQL database. to prevent parsing errors ?

Using PyGreSQL or something else?  If PyGreSQL are you using the "classic"
API or the DB-SIG 2.0 API?  By double quote do you mean empty string or
are you talking about embedding quoting characters within your string
and are wondering about quote reduction as strings are evaluated.  If the
following doesn't answer your question try to clarify some of these issues.

In PyGreSQL I have a function that does the following before putting a
string value into the database.

    return "'%s'" % string.strip(re.sub("'", "''", \
                             re.sub("\\\\", "\\\\\\\\", "%s" %d)))

This return the string inside of the single quotes that SQL needs.  Of
course if you are using PyGreSQL then you don't need to worry about this
as this function will be called for you when you insert or update.

-- 
D'Arcy J.M. Cain <darcy at vex.net>           |  Democracy is three wolves
http://www.vex.net/                        |  and a sheep voting on         
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list