Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 返回包含位置的数据库_Python_Database_Sqlite - Fatal编程技术网

Python 返回包含位置的数据库

Python 返回包含位置的数据库,python,database,sqlite,Python,Database,Sqlite,我认为我有正确的想法来解决这个函数,但我不确定为什么在测试它时会出现这个错误。谁能帮我修一下吗 错误:conn=sqlite3.connectdb sqlite3.0错误:无法打开数据库文件 期望输出: >>> get_locations(db, 'ANTA01H3F') ['ANTA01H3F','LEC01','AA112','ANTA01H3F','LEC01','SY110','ANTA01H3F','LEC02','AC223'] def get_locatio

我认为我有正确的想法来解决这个函数,但我不确定为什么在测试它时会出现这个错误。谁能帮我修一下吗

错误:conn=sqlite3.connectdb sqlite3.0错误:无法打开数据库文件

期望输出:

  >>> 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])

这太抽象了

请参阅从何处获取db sqlite数据库文件名的值以运行查询的run_query。没有得到您所期望的正确文件名

您调用的函数错误,它接受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))

我的run_query函数运行得很好,我正在调用它,但我不知道为什么它不工作。def run_querydb,q,args=None:str,str,tuple->list of tuple返回在数据库db上运行带有参数args的query q的结果。conn=sqlite3.connectdb cur=conn.cursor使用传递的给定参数执行查询如果参数为无,则只有一个查询如果参数为无:cur.executeq else:cur.executeq,args results=cur.fetchall cur.close conn.close return results则传递的参数错误。让我来纠正它。它不应该是“代替”吗?此外,我现在还遇到了这个错误cur.executeq sqlite3.OperationalError:没有这样的列:Room.location您还需要更正SQL。SQL中未定义文件室表/别名。位置表中需要的列是什么?