Genie プログラミング言語を使用して、SQLite データベース内の特定のエントリを検索する小さなプログラムを実行しようとしています。ただし、準備されたステートメントが適切なエントリを選択していない点で立ち往生しています。ステートメントの構文に何か問題があると思います。
まず、検索機能は次のとおりです。
def SearchForRecipe (db:Database)
print "-------------------------------"
print " Search in"
print "-------------------------------"
print " 1 - Recipe Name"
print " 2 - Recipe Source"
print " 3 - Ingredients"
print " 4 - Exit"
searchin:string = UserInterface.raw_input("Enter Search Type -> ")
search:string = " "
sql:string = " "
response:string=" "
if searchin != "4"
if searchin == "1"
search = "Recipe Name"
else if searchin is "2"
search = "Recipe Source"
else if searchin is "3"
search = "Ingredients"
else
print "An Error Occured"
print "--------------------------------------------------------------------------------------"
Process.exit (-1)
parm:string = searchin
response = UserInterface.raw_input ("Search for what in "+ search +" (blank to exit) -> ")
if parm == "1" // Recipe Name
stmt:Statement = PreparedStatements.select_recipe(db, response)
var row = new dict of string, string
cols:int = stmt.column_count ()
print cols.to_string()
for i:int = 0 to (cols - 1)
row[ stmt.column_name( i ) ] = stmt.column_text( i )
stdout.printf( "%-30s", row[ "name" ])
stdout.printf( "%-20s", row[ "servings" ])
stdout.printf( "%-30s\n", row[ "source" ])
問題は if ループで発生if parm == "1" // Recipe Name
しています。次の行で、選択したエントリの列数を出力するように要求すると、ゼロが返されます。何が起こっているのかをトラブルシューティングするためにその行を追加しましたが、それは最善の方法ではないかもしれません.
準備されたステートメントは名前空間内にあり、次のようになります。
namespace PreparedStatements
def select_recipe (db:Database, res:string) : Statement
statement:Statement
db.prepare_v2( "SELECT pkid,name,source,servings FROM Recipes WHERE name like" + res, -1, out statement)
return statement
データベース内の適切なエントリを選択していないため、select_recipe 関数の SELECT ステートメントに何か問題があると思います。
質問: エントリを適切に選択するにはどうすればよいですか? 別のアプローチを使用する必要がありますか、それとも準備済みステートメントが適切な方法ですか?