我在网上找到了一个教程,该教程使用户可以在命令行中输入电影,并且它将搜索IMDB并返回所有信息。可以了
因此,我决定我希望能够将电影数据导入SQLite数据库。该数据库正在与表一起生成,但是没有获取信息,并且没有出现错误。这是我所拥有的。
这是SQLite代码:
import sqlite3
from sqlite3 import Error
def sql_connection():
try:
con=sqlite3.connect('movies.db')
return con
except Error:
print(Error)
def sql_table(con):
cursorObj=con.cursor()
cursorObj.execute("CREATE TABLE movies(id integer PRIMARY KEY,\
tite text, year integer, full cast text, rating integer, plot \
text )")
con.commit()
con=sql_connection()
sql_table(con)
def sql_insert(con,entities):
cursorObj=con.cursor()
cursorObj.execute('INSERT INTO movies(id, title, year of \
release, full cast, rating, cast) VALUES(?,?,?,?,?,?)',entities)\
con.commit()
sql_insert(con,entities)
con.close()
我看到错误:
错别字:tite
,而不是:title
:
cursorObj.execute("CREATE TABLE movies(id integer PRIMARY KEY,\
tite text, year integer, full cast text, rating integer, plot \
text )")
在第二条语句中,您尝试更新不存在的字段year of release
(您之前将其命名为year
)。
cursorObj.execute('INSERT INTO movies(id, title, year of \
release, full cast, rating, cast) VALUES(?,?,?,?,?,?)',entities)\
con.commit()
如果要使用包含空格的列名,则需要使用反斜线或方括号,我会避免这种情况。因此,我将使用下划线字符(full cast
)代替空格_
,而不是full_cast
。但是在create
语句中,您调用了cast
字段,因此插入操作无效。