Help: Omitting quotes from SQL Queries.

keithk member21858 at dbforums.com
Wed Jan 8 05:30:09 EST 2003


Hi again,

I have tried some of your suggestions when using a variable for a
column name:

Using a correct Column name:

fileName = "Hello World's"
for fileName in fileNameList:
      cursor.execute("""SELECT fileSize FROM DBServer.database a where
      a.ColumnName = "%s" """" % fileName)
      fileSizes = cursor.fetchall()

Above returns an 'invalid column name' error.

fileName = "Hello World's"
for fileName in fileNameList:
      cursor.execute("SELECT fileSize FROM DBServer.database a where
      a.ColumnName= %s " % fileName)
      fileSizes = cursor.fetchall()

Above gives an "incorrect syntax near" error.


fileName = "Hello World's"
for fileName in fileNameList:
      cursor.execute("SELECT fileSize FROM DBServer.database a where
      a.ColumnName= '%s' " % (fileName),)
      fileSizes = cursor.fetchall()

I also tried the above with various qoutes, eg:

fileName = "Hello World's"
for fileName in fileNameList:
      cursor.execute("""SELECT fileSize FROM DBServer.database a where
      a.ColumnName = '"%s" """ % (fileName),)
      fileSizes = cursor.fetchall()

'Invalid column name' is returned, this is returned whenever I use the
triple qoutes, """.

If I use string.replace() method and replace the ' with " then I receive
no errors but no data is retrived from the DB as "Hello World's" does
not equal 'Hello World"s' thus no match is made in the DB.

Daniel,

Could you give me a little more detail about the

execute ("SELECT ...",[fileName]) appraoch as I am not familiar with
the syntax.

Thanks to all for replying.

--
Posted via http://dbforums.com




More information about the Python-list mailing list