sqlite3 添加行到 table 不添加任何错误

sqlite3 add row to table doesnt add no errors

我有一个 SQLite3 数据库,我想用 python 添加到其中,这是我必须添加一行的代码

def create_connection(db_file):
    """ create a database connection to a SQLite database """
    conn = None
    try:
        conn = sqlite3.connect(db_file)
        return conn
    except Error as e:
        print(e)

def add_password(conn, data):
    """
    Create an entry into the password database
    """
    try:
        sql = 'INSERT INTO passwords(added,username,password,website,email) VALUES(?,?,?,?,?)'
        cur = conn.cursor()
        cur.execute(sql, data)
        print('done')
        return cur.lastrowid
    except Error as e:
        print(e)

connection = create_connection('passwords.db')

data = (datetime.now(), 'SomeUsername', 'password123', 'whosebug.com', 'some@email.com')
add_password(connection, data)

当我 运行 它打印 done 并结束时,没有错误。但是,当我打开数据库查看 table 时,它没有条目。

如果我打开数据库和运行相同SQL代码

INSERT INTO passwords(added,username,password,website,email) 
VALUES('13-5-2020', 'SomeUsername', 'password123', 'whosebug.com', 'some@email.com')

它添加到 table。所以一定是我的python代码有问题。我如何添加它?

执行完查询后conn.commit()即可。它应该工作