Hello all –
I am new to Python, very new so I apologize if this is a basic question. My question concerns the use of sqlite3 module and how to pass multiple parameters into a search string. Below are two examples. The first works fine when passing a single parameter. The second fails. Can someone tell me what I am doing wrong here
Thanks
Bob Bartis
The following code works fine with finding and print matching rows using the slite3 module
userKeywords = ('*')
shell = ('CLI')
# Extract matching records to build up list of commands
matchingKeywords = c.execute('SELECT * FROM commandInfo WHERE keywords LIKE ? AND shell ?', ('%'+userKeywords+'%',))
for row in matchingKeywords:
print (row)
When trying to pass more than one parameter into the SQL cursor for execution the following error occurs
# Extract matching records to build up list of commands
matchingKeywords = c.execute('SELECT * FROM commandInfo WHERE keywords LIKE ? AND shell ?', ('%'+userKeywords+'%',shell,))
for row in matchingKeywords:
print (row)
Traceback (most recent call last):
File "C:\Users\bartis\Desktop\Python\db.py", line 105, in
matchingKeywords = c.execute('SELECT * FROM commandInfo WHERE keywords LIKE ? AND shell ?', ('%'+userKeywords+'%',shell,))
sqlite3.OperationalError: near "?": syntax error