我试图做一个小程序,搜索使用精灵编程语言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语句,因为它不是采摘正确的入口数据库。
问题:如何正确选择条目?我是否应该使用另一种方法,或者准备好的声明是否是正确的方法?