A good way to escape quotes in a database query string?

后端 未结 9 1238
暖寄归人
暖寄归人 2020-12-09 07:49

I\'ve tried all manner of Python modules and they either escape too much or in the wrong way. What\'s the best way you\'ve found to escape quotes (\", \') in Python?

9条回答
  •  温柔的废话
    2020-12-09 08:20

    Triple single quotes will conveniently encapsulate the single quotes often used in SQL queries:

    c.execute('''SELECT sval FROM sdat WHERE instime > NOW() - INTERVAL '1 days' ORDER BY instime ASC''')
    

提交回复
热议问题