SQLite.swift文档说关于执行任意 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?
,我不知道如何将其转换为我需要的类型。我看到源代码中有一个Statement.bind
方法,但我仍然没有发现如何应用它。