0

How to print a sqlite table content with genie programming languageという質問を解決しようとしているときに、Database.exec からのコールバックとして PrintSingleRecipe を呼び出すことができることがわかりました。ただし、コールバックは通常の関数にすることはできないようです。それらには、インターネットで見つけられないように見えるいくつかのプロパティがあります。

私はこのように呼んでいます:

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)

関数自体は次のようになります。

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

ただし、コンパイル時に次のエラーが発生します。

valac --pkg sqlite3 --pkg gee-0.8 cookbook.gs
cookbook.gs:42.26-42.42: error: Argument 2: Cannot convert from `PrintSingleRecipe' to `Sqlite.Callback?'
            db.exec(sql, PrintSingleRecipe, null)
                         ^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

Genie でコールバックを正しく実行するには?

4

1 に答える 1