0

我正在尝试编写用于更新数据库表列的函数(这里的列名会在不同的时间点有所不同。)所以在这样做的同时,我得到“操作错误,数据库锁定”。任何人都可以提出这背后的原因。为了更清楚,我提供如下代码:

def UpdateDB_ForFields(DB_name, DB_tableName, dev_name, devindex, colList, colValList): 
    try:
        conn = None
        cloudDBlockList[devindex].acquire()
        pool_sema.acquire()
        conn = sqlite3.connect("XYZ.db",timeout=20)
        for i in range(len(colList)):
            cursor = conn.execute("""UPDATE XYZ_settings SET {0} = ? WHERE {1} = ?;""".format(colList[i],"devName"),(colValList[i],dev_name))           
        conn.commit()
        conn.close()
        pool_sema.release()
        cloudDBlockList[devindex].release()
    except Exception as ex:
        template = "An exception of type {0} occurred. Arguments:\n{1!r}"
        message = template.format(type(ex).__name__, ex.args)
        print(message)
        logging.error(message)
        if conn == None:
            print("Error")
        else:
            conn.close()
            pool_sema.release()
            cloudDBlockList[devindex].release()

I am getting error while updating db as database locked. Please suggest the solution.
4

0 回答 0