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: [email protected]
}
// 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?

1
  • 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.. Commented Nov 22, 2016 at 18:09

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

1 Comment

As of version 0.14.1 asSQL() is now internal, not public. You can instead use query.description.
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

1 Comment

That prints all statements. I'm trying to print one specific statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.