简体   繁体   中英

How to query substring in a string in python sqlite3

How to query substring in a string in python sqlite3?

I am using this:

cur.execute("SELECT FirstName FROM customers where instr(FirstName,'Le')")
This works fine but I want to search for user input like this:
ss=(some_user_Entry).get()
cur.execute("SELECT FirstName FROM customers where instr(FirstName,ss)") 

but it wont work

what shall I do?

Use a prepared statement and bind the user input's value to your query:

ss = (some_user_Entry).get()
cur.execute("SELECT FirstName FROM customers WHERE INSTR(FirstName, ?)", (ss,))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM