2016-11-22 85 views
0

我想调试一些sqlite.swift语句不提供我期望的结果。如何将sqlite.swift语句打印为SQL?

该文档显示了注释中的SQL示例。

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" 

如何获得用于打印该SQL的语句?

print("\(users.select(id, email))")不给我SQL。我在文档中忽略了什么?

+0

快速浏览一下源代码,发现Statement对象有一个.description变量,QueryType有一个表达式变量。我会尝试这些。虽然如果你发布声明,也许有人可以帮助它.. –

回答

2

如果你想看到的SQL被执行,然后打印(query.asSQL())

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

print(query.asSQL())//Will show SQL statement