mxODBC and apostrophe's in strings

Andrew Dalke dalke at dalkescientific.com
Wed Sep 12 04:25:16 EDT 2001


Ben C:
>_text = "This is some really 'extraordinary' text read from a file
>somewhere"

>SQLExpress = "INSERT INTO table (Date, Time) VALUES (" + _date + ",'"
>+ _text + "')"
>
>cursor.execute(SQLExpress)

>Does anyone know of a workaround for this keeping in mind that any
>combination of ASCI characters could appear in the _text string.

Hmm, haven't used mxODBC but the mySQL interface has a way to
do the proper escapes. ... Looking at the mxODBC docs, how about

SQLExpress = "INSERT INTO table (Date, Time) VALUES (?, ?)"
cursor.execute(SQLExpress, (_date, _text))

  ?

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list