[英]How do I use the values in the tuple miltiple times when doing an execute in sqlite3
我正在嘗試使用sqlite3的execute函數來清理得到的字符串。 但是,我無法做到這一點,因為我無法弄清楚如何多次使用元組中的值。
我能做的就是這個
cursor.execute("""
select *
from rides r
where r.cno = c.cno
and (r.src like '%{0}%'
or r.dst like '%{0}%'
or e.lcode like '%{0}%'
and (r.src like '%{1}%'
or l3.address like '%{1}%')
and (r.src like '%{2}%'
or l1.address like '%{2}%')
;
""".format(keywords[0], keywords[1], keywords[2]))
但是,我了解到它可以進行直射攻擊,因為此處直接使用了輸入。 有沒有一種方法可以在執行函數的結尾多次使用元組?
sqlite3將衛生設施放在文檔的首位。 使用命名的占位符樣式。
https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.execute
# This is the qmark style:
cur.execute("insert into people values (?, ?)", (who, age))
# And this is the named style:
cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
上一篇文章的答案也可以幫助您直觀地看到此修復程序: https : //stackoverflow.com/a/12184247/10553976
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.