Answer the question
In order to leave comments, you need to log in
How to get around error when searching in SQLite database?
Good afternoon. I'm learning Python 3.5.1 and SQLite 3. There is a test
table in the database with the entry: id | data1
| 123
I am trying to search this database:
text = ['123, '456']
sql = """SELECT * FROM test WHERE data LIKE (?)"""
try:
for i in text:
cur.execute(sql, [(i),])
result = cur.fetchone()[1]
if i == result:
print("Найдено.")
else:
print("Не найдено.")
except TypeError as err:
print("Ошибка: ", err)
else:
print("Готово.")
Answer the question
In order to leave comments, you need to log in
You can, for example, first check the number of records returned
if cur.rowcount > 0:
result = cur.fetchone()[1]
print('Найдено')
else:
print('Не найдено')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question