Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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
如何用genie编程语言打印sqlite表内容_Sqlite_Genie - Fatal编程技术网

如何用genie编程语言打印sqlite表内容

如何用genie编程语言打印sqlite表内容,sqlite,genie,Sqlite,Genie,基于前面的问题,我设法找到了数据集,列出了所有的食谱,现在我试图从列表中选择一个食谱,并显示其标题、说明和成分。说明通过pkID列映射到配方,配料通过recipeID列映射到配方。当我在Sqlite数据库浏览器上打开数据库时,我可以在Tables下拉列表中访问这些信息,因此我认为它们的正确名称是数据库中的表 我无法通过pkID和recipeID进行过滤,因此在选择一个配方后,只显示适当的内容 这是Python中我在精灵中尝试执行的代码: def PrintSingleRecipe(self,

基于前面的问题,我设法找到了数据集,列出了所有的食谱,现在我试图从列表中选择一个食谱,并显示其标题、说明和成分。说明通过pkID列映射到配方,配料通过recipeID列映射到配方。当我在Sqlite数据库浏览器上打开数据库时,我可以在Tables下拉列表中访问这些信息,因此我认为它们的正确名称是数据库中的表

我无法通过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" ))
我还不能改进我的大部分代码,这里似乎不能使用我以前在step语句中使用的迭代方法。这就是我在精灵里走了多远:

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

我已经找到了问题的解决方案,也许可以优化。现在已经足够了

另一个人的回答帮了大忙。我使用的解决方案是使用exec函数并将回调指向PrintSingleRecipe

必须做一些调整才能使它作为回调,但我得到了我所需要的

以下是调用函数的代码:

while true
    response:string = UserInterface.get_input_from_menu()
    if response == "1" // Show All Recipes
        PrintAllRecipes(db)
    else if response is "2" // Search for a recipe
        pass
    else if response is "3" //Show a Recipe
        res:string = UserInterface.raw_input("Select a recipe -> ")
        sql:string = "SELECT * FROM Recipes WHERE pkID = " + res
        db.exec(sql, PrintSingleRecipe, null)
    else if response is "4"//Delete a recipe
        pass
    else if response is "5" //Add a recipe
        pass
    else if response is "6" //Print a recipe
        pass
    else if response is "0" //Exit
        print "Goodbye"
        break
    else
        print "Unrecognized command. Try again."
以下是PrintSingleRecipe的外观:

def PrintSingleRecipe(n_columns:int, values:array of string, column_names:array of string):int
    print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    for i:int = 0 to n_columns
        stdout.printf ("%s = %s\n", column_names[i], values[i])
    print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    print "Ingredient list"
    print " "
    return 0