这个问题是前一个问题的衍生,这里创建了一个数据库。但是,在向该数据集添加信息时,我可以手动添加信息或通过编程方式进行。出于教学原因,后者是我的选择。
我在 python 中尝试做的等价物是:
for x in cursor.execute(sql):
lastid = x[0]
# Insert data into the instructions table
sql = 'INSERT INTO Instructions (recipeID,instructions) VALUES( %s,"Brown hamburger. Stir in all other ingredients. Bring to a boil. Stir. Lower to simmer. Cover and cook for 20 minutes or until all liquid is absorbed.")' % lastid
cursor.execute(sql)
我的方法是:
//Insert the rest of instructions
var last_id = db.last_insert_rowid()
for var x in last_id
query = """INSERT INTO Instructions (recipeID,instructions) VALUES(
%s,
"Brown hamburger. Stir in all other ingredients. Bring to a boil. Stir. Lower to simmer. Cover and cook for 20 minutes or until all liquid is absorbed."
), x
"""
但是,根据我得到的错误,似乎 last_id 是不能作为迭代器的 int64 类型:
valac --pkg sqlite3 cookcreate.gs cookcreate.gs:55.18-55.24: error:
int64' does not have an
iterator' method for var x in last_id ^^^^^^^ 编译失败:1 个错误,0 个警告
如何用 Genie 中的代码解决这个问题?我应该将它转换为另一种接受用作迭代器的类型吗?另外,那个语法(%s), x
正确吗?
谢谢