0
根據之前的問題,我設法將create數據集,print列出的所有食譜,現在我試圖從該列表中選擇其中一個食譜並顯示其標題,說明和成分。說明通過pkID列映射到配方,並通過recipeID列將配料映射到配方。當我在Sqlite數據庫瀏覽器上打開數據庫時,我可以在Tables下拉列表中訪問這些信息,所以我想他們的專有名稱是數據庫中的表格。如何使用genie編程語言打印sqlite表格內容
我無法通過pkID和recipeID進行「過濾」,因此在選取一個配方後,只顯示適當的內容。
這是什麼我想在精靈做的Python代碼:
def PrintSingleRecipe(self,which):
sql = 'SELECT * FROM Recipes WHERE pkID = %s' % str(which)
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
for x in cursor.execute(sql):
recipeid =x[0]
print "Title: " + x[1]
print "Serves: " + x[2]
print "Source: " + x[3]
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
sql = 'SELECT * FROM Ingredients WHERE RecipeID = %s' % recipeid
print 'Ingredient List:'
for x in cursor.execute(sql):
print x[1]
print ''
print 'Instructions:'
sql = 'SELECT * FROM Instructions WHERE RecipeID = %s' % recipeid
for x in cursor.execute(sql):
print x[1]
print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
resp = raw_input('Press A Key -> ')
我一直沒能改善很多我的代碼,似乎是用我迭代之前使用的方法在一個步驟聲明中不能在這裏使用。這是我得到多遠的精靈:
def PrintSingleRecipe(db:Database)
stmt:Statement = PreparedStatements.select_all(db)
res:int = UserInterface.raw_input("Select a recipe -> ").to_int()
cols:int = stmt.column_count()
var row = new dict of string, string
item:int = 1
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
while res == ROW
for i:int = 0 to (cols - 1)
row[ stmt.column_name(i) ] = stmt.column_text(i)
stdout.printf("%-5s", item.to_string("%03i"))
stdout.printf("%-30s", row[ "Title" ])
stdout.printf("%-20s", row[ "Serves" ])
stdout.printf("%-30s\n", row[ "Source" ])
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "Ingredient list"
print " "
stdout.printf("%-5s", item.to_string("%03i"))