我試圖做一個小程序,搜索使用精靈編程語言SQLite數據庫內的特定條目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 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語句,因爲它不是採摘正確的入口數據庫。
問題:如何正確選擇條目?我是否應該使用另一種方法,或者準備好的聲明是否是正確的方法?