我认为我有正确的想法来解决这个问题,但是我不确定为什么在测试它时会出现这个错误。有人可以帮我解决这个问题吗?
错误:conn = sqlite3.connect(db) sqlite3.OperationalError:无法打开数据库文件
期望的输出:
>>> get_locations(db, 'ANTA01H3F')
[('ANTA01H3F','LEC01','AA112'),('ANTA01H3F','LEC01','SY110'),('ANTA01H3F','LEC02','AC223')]
def get_locations(db, course):
'''Return the course, section and locations of the exam for the given course.'''
return run_query('''SELECT Courses.Course, Courses.Sections, Room.Locations
FROM Courses JOIN Locations ON Courses.ID = Locations.ID WHERE Course = ?''', [course])
答案 0 :(得分:0)
这太抽象了。 ;)
请参阅run_query(),从中获取db(sqlite数据库文件名)的值以运行查询。它没有获得您期望的正确文件名。
您正在调用该函数,它接受db和sql语句字符串:
return run_query(db, "SELECT Courses.Course, Courses.Sections, Locations.Room " \
" FROM Courses JOIN Locations ON Courses.ID = Locations.ID WHERE Course = '{}'".format(course))