SQLite parameter substitution and quotes

前端 未结 6 1072
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 14:41

I have this line that works OK:

c.execute(\'select cleanseq from cleanseqs WHERE newID=\"%s\"\'%name)

But I want to use SQLite parameter su

6条回答
  •  猫巷女王i
    2020-11-28 15:28

    To anyone who like me found this thread and got really frustrated by people ignoring the fact that sometimes you can't just ignore the quotes (because you're using say a LIKE command) you can fix this by doing something to the effect of:

    var = name + "%"
    c.execute('SELECT foo FROM bar WHERE name LIKE ?',(var,))
    

    This will allow you to substitute in wildcards in this situation.

提交回复
热议问题