Newbie Help on ODBC & Apostrophes
Glenn A. Hockley
ghockleyNOSPAM at home.com
Mon Jun 18 23:40:12 CEST 2001
I have a question that probably has a very simple answer. I am trying to
use an Access database via the PythonWin ODBC modules to store a list of
names. I get these names via a form on a web page through CGI. My problem
lies with a name with an apostrophe in it, such as O'Brien for example. In
this case, the ODBC statement doesn't seem to work.
For example, if I try to do the following:
myCursor.execute("SELECT * FROM MyTable WHERE Name='O'Brien'")
it obviously doesn't work. However, the name is retrieved from the web site
and is automatically insterted into this string.
>From what I have read, to use a string in an ODBC execution statement
requires that it be surrounded by single quotes. For example:
myCursor.execute("INSERT INTO MyTable values ('glenn')")
So is there a way to make it so that if the user enters name with an
apostrophe, that this apostrophe doesn't cause my program to crash, and that
the name is added to the database with the apostrophe in it?
Hopefully that makes sense...
More information about the Python-list