SQLite.swift documentation说关于执行任意SQL:
let stmt = try db.prepare("SELECT id, email FROM users")
for row in stmt {
for (index, name) in stmt.columnNames.enumerate() {
print ("\(name)=\(row[index]!)")
// id: Optional(1), email: Optional("alice@mac.com")
}
}
我希望像这样直接获取值
let stmt = try db.prepare("SELECT id, email FROM users")
for row in stmt {
let myInt: Int64 = row[0] // error: Cannot convert value of type 'Binding?' to specified type 'Int64'
let myString: String = row[1] // error: Cannot convert value of type 'Binding?' to specified type 'String'
}
但行索引的类型为Binding?
,我无法弄清楚如何将其转换为我需要的类型。我看到source code中有一个Statement.bind
方法,但我仍然没有发现如何应用它。