此代码触发错误,指出rightAnswer
为nil
。它应该很简单;在添加namesSoFar
变量和查询的and name not in
部分之前,它工作正常。我还尝试将not in
更改为in
,可能会将我的查询限制为这三个值(我肯定会在那里)并得到相同的错误。
namesSoFar = ["Bob", "Susan", "Gordon"]
let querySQL = "SELECT name, picture_name from member_data where picture_name is not ? and name not in ? ORDER BY RANDOM() LIMIT 1";
rightAnswer = memberDatabase!.executeQuery(querySQL, withArgumentsInArray: ["None", namesSoFar])
rightAnswer!.next()
编辑:
仍在尝试调试。
这有效:
let querySQL = "SELECT name, picture_name from member_data where picture_name is not ? and name is ? ORDER BY RANDOM() LIMIT 1";
rightAnswer = memberDatabase!.executeQuery(querySQL, withArgumentsInArray: ["None", "Bob"])
这些不是:
let querySQL = "SELECT name, picture_name from member_data where picture_name is not ? and name in ? ORDER BY RANDOM() LIMIT 1";
rightAnswer = memberDatabase!.executeQuery(querySQL, withArgumentsInArray: ["None", ["Bob"]])
或
rightAnswer = memberDatabase!.executeQuery(querySQL, withArgumentsInArray: ["None", ("Bob")])
答案 0 :(得分:0)
显然正确的语法是
let querySQL = "SELECT name, picture_name from member_data where picture_name is not ? and name not in (?, ?) ORDER BY RANDOM() LIMIT 1";
rightAnswer = memberDatabase!.executeQuery(querySQL, withArgumentsInArray: ["None", "Bob", "Susan"])