2016-11-22 43 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