我正在尝试迭代从我的数据库中提取的食谱,从每个食谱中解析成分并将成分插入到他们自己的表中。问题是我不知道如何在我的内部选择中包含当前的成分变量:目前我收到以下错误:
ExtractIngredients.rb:21:在“查询”中:“字段列表”中的未知列“ing”(Mysql::Error)
你能告诉我如何在我的选择语句中包含“ing”吗?
谢谢,李
begin
db = Mysql.new 'localhost', 'root', 'pass', 'recs'
results = db.query "SELECT id, freeText FROM recipes"
nRows = results.num_rows
for i in 0..nRows-1
curRow = results.fetch_row
recipeInd = curRow[0]
recipeFreeText = curRow[1]
ingredients = getIngredients(recipeFreeText).to_s.scan(/\'(\w+)\'/).flatten
ingredients.each do |ing|
db = Mysql.new 'localhost', 'root', 'pass', 'recs'
# In the next awful select statement I'm trying to insert the current ingredient to the ingredient table if it isn't already there
db.query "INSERT INTO ingredient(name, created_at, updated_at) SELECT ing, created_at, updated_at FROM dummytable WHERE (SELECT count(*) FROM ingredient WHERE Name = ing)=0"
ingInd = db.query "SELECT id FROM ingredient WHERE name=ing"
db.query "INSERT INTO ingredients_recipes(ingredient_id, recipe_id) ingInd, recipeInd"
end
end
end