Help: Omitting quotes from SQL Queries.
taocairns
nospam at earthlink.net
Tue Jan 7 11:54:39 EST 2003
keithk wrote:
> Hi All,
>
> I am using an mx.ODBC connection to MSSQL and am iterating through a
> list to get data from the DB, for eg:
>
> for fileName in fileNameList:
> cursor.execute("SELECT fileSize FROM database where
> database.filename = '%s'" % fileName)
> fileSizes = cursor.fetchall()
>
> However, when it iterates through the list and fileName equals something
> like "Hello World's" with a single quote inside the query fails as the
> string is ended prematurely, does anybody know how I can solve this?
>
> Thanks in advance,
>
> Keith
>
> --
> Posted via http://dbforums.com
Try unquoting the placeholder (%s):
for fileName in fileNameList:
cursor.execute("SELECT fileSize FROM database where
database.filename = %s" % fileName)
fileSizes = cursor.fetchall()
More information about the Python-list
mailing list