FMDB中的sqlite查询中的“LIKE”运算符

时间:2016-01-01 13:21:19

标签: swift sqlite sql-like fmdb

请解释我如何为这样的代码编写LIKE运算符?我在下面编写了代码,但它似乎不适用于 FMDB

func getsearchStudentData(word:String) -> NSMutableArray {
sharedinstance.database!.open()
let resultSet: FMResultSet! = sharedinstance.database!.executeQuery("SELECT * FROM student_info WHERE name LIKE '%?' ",  withArgumentsInArray: [word])
let sarrStudentInfo : NSMutableArray = NSMutableArray()
if (resultSet != nil) {
    while resultSet.next() {
        let studentInfo : student_info = student_info()
        studentInfo.RollNo = resultSet.stringForColumn("RollNo")
        studentInfo.Name = resultSet.stringForColumn("Name")
        studentInfo.Marks = resultSet.stringForColumn("Mark")
        sarrStudentInfo.addObject(studentInfo)
    }
}
sharedinstance.database!.close()
return sarrStudentInfo           }

1 个答案:

答案 0 :(得分:-2)

swift 3

试试这个

let query = "select \(field_ImageID) from \(imageTag_tableName) where \(field_ImageTag) LIKE ?;"

...

let results = try database.executeQuery(query, values: ["%\(tag)%"])