我有以下要调试的方法。我的问题是,当我从 main 调用 insertNewDataInDatabase() 方法时,它会转到方法中 for 循环的开头,但会跳过数据库执行语句并立即转到 getInStockItems() 方法,这对我是因为我已经调用了该方法并且 insertNewDataInDatabase 没有调用它。
数据集是一个生成器对象,如果这与问题有关。
任何帮助将非常感激!
def deleteOldDataFromDatabase(company, c):
c.execute('DELETE FROM company WHERE Company=?',(company,))
def insertNewDataInDatabase(items, c):
for each in items:
c.execute('INSERT INTO ammo VALUES (?, ?, ?, ?, ?, ?)', ("NULL", each["Company"], each["Value"],
each["Product"], each["Price"], each["Url"]))
def getInStockItems(c):
for i in chain(ctd.main()):
deleteOldDataFromDatabase(i[1], c)
for each in i[0]:
yield each
def retrieveDatafromDB(c):
c.execute("SELECT * from company")
return c.fetchall()
def main():
with sqlite3.connect(database) as connection:
c = connection.cursor()
dataset = getInStockItems(c)
insertNewDataInDatabase(dataset, c)
return retrieveDatafromDB(c)
if __name__ == '__main__':
main()