在 Sqlite3 中执行查询时出错

Error while executing the query in SqlLite3

我正在尝试在用户在 Telegram 机器人中按 /start 后添加用户名、用户 ID 和许多其他变量。但是我在这段代码中遇到错误

def add_user(userid, username):
    userCount = c.execute(f"COUNT({userIdColumn} FROM {info_table} WHERE {userIdColumn}={userid}")
    if(userCount <= 0):
        c.execute(f"INSERT INTO {info_table}({userIdColumn},{usernameColumn},{isBannedColumn},{isSubscribedColumn},{userNotesColumn}) VALUES ({userid},{username},0,1,' ')")
        c.commit()
        db.close()

我尝试在函数内声明 cursor() 甚至数据库,但我得到的错误是

  1. sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 20532 and this is thread id 19184.
  2. sqlite3.OperationalError: near "COUNT": syntax error

我也知道有一个 post 关于同样的问题,不幸的是没有解决我的问题。

我的问题是这里的正确声明是什么?

第一个错误的修复方法是添加 check_same_thread=False 作为参数 = sqlite3.connect("Your db",check_same_thread=False) 并且您还需要在函数

中声明 cursor()

第二个错误是格式错误造成的,应该是SELECT COUNT