W
W
WolfInChains2020-06-01 20:17:30
Python
WolfInChains, 2020-06-01 20:17:30

Why is the name not written to the database? OperationalError('near "Fallen": syntax error')?

def get_name(uid: int) -> str:
    data = vk.method("users.get", {"user_ids": uid})[0]
    return "{} {}".format(data["first_name"], data["last_name"])


if not is_user_statlisted(user_id):
      insert_statlist(user_id, get_name(user_id))


def is_user_statlisted(user_id: int) -> bool:
    cmd = "select count(user_id) from statlist where user_id = %d" % (user_id)
    c.execute(cmd)
    result = c.fetchone()[0]
    print("Проверка айди на наличие в статлисте")
    return result > 0


def insert_statlist(user_id: int, name):
    cmd = "INSERT INTO statlist(user_id, sms, name) VALUES (%d, 0, %s)" % (user_id, name)
    c.execute(cmd)
    conn.commit()
    print("Пользователь добавлен в статлист")


Logs
OperationalError('near "Падший": syntax error')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-06-01
@WolfInChains

And in which function did the error occur? The request from the is_user_statlisted function was completed for me. To query the database from the insert_statlist function, you can wrap %s in single quotes:

cmd = "INSERT INTO statlist(user_id, sms, name) VALUES (%d, 0, '%s')" % (user_id, name)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question