I
I
Ilkhomjon Matazimov2020-05-11 19:54:57
MySQL
Ilkhomjon Matazimov, 2020-05-11 19:54:57

Python sql select returns None. Why?

Good day. I know this has been asked, but I can't seem to solve the problem.

Here is the code:

sql_select = "SELECT telegram_user_id FROM users"
sql_select = db.cursor(buffered=True).execute(sql_select)
print(sql_select)
if message.from_user.id not in sql_select:
    sql_insert = "INSERT INTO users ('что-то') VALUES (%s)"
    val = (['что-то'])
    db.cursor().execute(sql_insert, val)
    await message.answer("Вы не были до зарегистрированы, поэтому мы занесли в базу данных")
db.commit()


Gives an error:
if message.from_user.id not in sql_select:
TypeError: argument of type 'NoneType' is not iterable


This is new to me, so I can't figure out what's going on. Help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Botsman, 2020-05-11
@mr_qpdb

Try like this

sql_select = "SELECT telegram_user_id FROM users"
cursor = db.cursor(buffered=True)
cursor.execute(sql_select)
result = cursor.fetchall()
print(result)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question