【发布时间】:2022-01-05 10:13:14
【问题描述】:
我想将此字典“all_movies”插入到表“movie_table”中。
使用 asyncio 对数据进行网络抓取,然后将其收集到 original_movies 中。
"CREATE TABLE IF NOT EXISTS movie_table
(actor_rank INTEGER, movie_name TEXT, year TEXT, genre TEXT, rating TEXT);"
我尝试了多种方法,但出现以下错误:
1.错误:
sqlite3.ProgrammingError: Incorrect number of bindings supplied.
The current statement uses 5, and there are 65 supplied.
使用此查询(original_movie 已更改)
insertQuery = '''INSERT INTO
movie_table (actor_rank, movie_name, year, genre, rating) VALUES (:actor_rank, :movie_name, :year, :genre, :rating)'''
cursor.executemany(insertQuery, original_movie)
connection.commit()
2。错误:
sqlite3.ProgrammingError: Incorrect number of bindings supplied.
The current statement uses 5, and there are 1 supplied.
使用此查询(original_movie 已更改)
insertQuery = '''INSERT INTO
movie_table (actor_rank, movie_name, year, genre, rating) VALUES (:actor_rank, :movie_name, :year, :genre, :rating)'''
cursor.executemany(insertQuery, [original_movie])
connection.commit()
3.错误:
sqlite3.ProgrammingError: Incorrect number of bindings supplied.
The current statement uses 5, and there are 65 supplied.
使用此查询(VALUES 已更改,并且 original_movies 现在是包含元组的列表)
insertQuery = '''INSERT INTO
movie_table (actor_rank, movie_name, year, genre, rating) VALUES (?, ?, ?, ?, ?)'''
cursor.executemany(insertQuery, original_movie)
connection.commit()
【问题讨论】: