The SQLite.swift documentation says about executing arbitrary 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("[email protected]")
}
}
I wanted to get the values directly like this
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'
}
but the row index is of type Binding?
and I can't figure out how to convert that to the type I need. I see there is a Statement.bind
method in the source code but I am still not discovering how to apply it.
Expression
?, (eg.let myInt: Expression<Int64> = ...
) – DeathblowBinding?
toExpression<Int64>
). I've been successful usingExpression
in the past but now that I am trying to get arbitrary SQL to work (because of my problem with this), I've been having a lot of trouble. – Brightness