mxODBC and apostrophe's in strings

Ben C benc1 at today.com.au
Wed Sep 12 09:28:13 CEST 2001


Hi,

I am uploading some random text to a MSSQL DB using the mxODBC module.

ie.

...
_text = "This is some really 'extraordinary' text read from a file
somewhere"

_date = 10000232

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

cursor.execute(SQLExpress)
...

The probelm occurs if an apostrophe appears in the text (I assume
because it has been used as a delimiter in the SQL Expression). The
error message I recieve is similar to this

...
ProgrammingError: ('37000', 170, "[Microsoft][ODBC SQL Server
Driver][SQL Server]Line 1: Incorrect syntax near 'rline'.", 4523)
...

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

thanks in advance

Ben



More information about the Python-list mailing list