So I asked this question about how to construct a SQL query to exclude certain values in my Swift app. It didn't get a lot of traction, but I figure out a way that works (maybe there's a better way?)
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"])
While this works for this case, I don't know how many names I'd want to exclude; it could be 0-10 names (it's a quiz game and I don't want to repeat questions, so each time I push the name to an array). What I want is something like:
badNames = ("Bob", "Susan") //this can be 0-10 items long
let querySQL = "SELECT name, picture_name from member_data where picture_name is not ? and name not in \(badNames) ORDER BY RANDOM() LIMIT 1";
Aucun commentaire:
Enregistrer un commentaire