我正在用 aiogram,python 编写一个电报机器人。有需要使用数据库,写了如下查询:
for value in cur.execute("SELECT field FROM vlnt_table WHERE faculty = ? AND university = ?", (faculty_pressed, university_pressed)):
current_value = str(value)
fields_list.append(current_value)
但是,此代码不起作用,会引发错误:
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
我检查了所有变量,将它们与数据库中的值相关联,尝试使用每个 Faculty_pressed 和 university_pressed 变量编写两个单独的查询(它们有效),但是在一个 WHERE 中,它们不起作用。我正是需要这两个条件,请告诉我问题是什么!如果可以选择使用两个查询来实现这些条件,我会很高兴(我需要在一个循环中使用它)
upd:显示我放入变量的内容:
faculty_pressed = (message.text[10:],)
async with state.proxy() as abit_filter:
abit_filter['university'] = (message.text[12:],)
university_pressed = abit_filter['university']
这就是我检查是否有匹配项的方式:
for value in cur.execute('SELECT university FROM vlnt_table'):
print(value)
if value == university_pressed:
print('Должно работать!!')
我会放弃整个功能,也许:
async def cmd_abit_filters_faculty(message: types.Message, state = FSMContext):
async with state.proxy() as abit_filter:
abit_filter['faculty'] = (message.text[10:],)
university_pressed = abit_filter['university']
faculty_pressed = (message.text[10:],)
print(abit_filter['university'])
fields_list = []
for value in cur.execute('SELECT university FROM vlnt_table'):
print(value)
if value == university_pressed:
print('Должно работать!!')
for i in cur.execute("SELECT field FROM vlnt_table WHERE (faculty = ?) AND (university = ?)", (faculty_pressed, university_pressed)):
current_value = str(value)
current_value = current_value.replace('(', '')
current_value = current_value.replace(')', '')
current_value = current_value.replace("'", "")
current_value = current_value.replace(',', '')
fields_list.append(current_value)
base.commit()
fields_set = list(set(fields_list))
fields_set = fields_list
kb_fields = ReplyKeyboardMarkup(resize_keyboard=True)
for i in fields_set:
kb_fields.add(f"Направление {i}")
await FSMFilters.next()
await bot.send_message(message.from_user.id, 'Выберите направление подготовки, о котором хотели бы узнать', reply_markup=kb_fields)