sqlite.swift

Getting results from arbitrary SQL statements with correct binding in SQLite.swift

99封情书 提交于 2019-12-01 00:40:10
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("alice@mac.com") } } 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

What different between store database in different locations in iOS?

走远了吗. 提交于 2019-11-30 23:06:17
I'm working with SQLite.swift. In the document, the path to the database is: let path = NSSearchPathForDirectoriesInDomains( .DocumentDirectory, .UserDomainMask, true ).first! but i want to import and use an existing database, so i've dragged my existing database to my keyboard extension folder, and create connection to it with path is: let path = NSBundle.mainBundle().pathForResource("db", ofType:"sqlite3") So, i've noticed that the first way, the database will be store in /Users/*/Library/Developer/CoreSimulator/Devices/8B1DB861-AA3F-446F-A559-D4727CDB9285/data/Containers/Data

Subtle cast warning when using SQLite.Swift … Binding? to Any

柔情痞子 提交于 2019-11-28 10:08:46
问题 Here's one, import SQLite var r:[[Any]] = [] do { if let stmt = try local.db?.prepare(q) { r = Array(stmt) } else { print("woe in sql?") } } catch { return [] } the call r = Array(stmt) gives Expression implicitly coerced from 'Binding?' to Any. And indeed, I do not know how to Provide a default value to avoid this warning, Force-unwrap the value to avoid this warning, or even Explicitly cast to Any with 'as Any' to silence this warning. :O Here's a self-contained example that reproduces the