0

I'm trying to debug some sqlite.swift statements that aren't delivering the results I expect.

The documentation shows examples of SQL in comments.

for user in try db.prepare(users.select(id, email)) {
    print("id: \(user[id]), email: \(user[email])")
    // id: 1, email: alice@mac.com
}
// SELECT "id", "email" FROM "users"

How do I get the statement to print that SQL?

print("\(users.select(id, email))") does not give me SQL. Am I overlooking something in the documentation?

adamek
  • 2,324
  • 3
  • 24
  • 38
  • A quick glance at the source showed that Statement objects have a .description variable and QueryType has an expression variable. I would try those. Though if you post the statement maybe someone can help with it too.. – twiz_ Nov 22 '16 at 18:09

2 Answers2

6

If you want to see the SQL being executed then print(query.asSQL())

let query = dbTable
            .filter(dbSourceKey == Int64(minElement))
            .filter(dbTargetKey == Int64(maxElement))

print(query.asSQL())//Will show SQL statement
Yarm
  • 1,178
  • 4
  • 16
  • 29
3

The following command will print all SQL statements:

db.trace(print)

See https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md#logging

Gwendal Roué
  • 3,949
  • 15
  • 34