如何打印 Core Data 调试值? [英] How to print Core Data debug values?

查看:24
本文介绍了如何打印 Core Data 调试值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用 Core Data SQL Debug 时打印发送到 sqlite 数据库的值?

How can I print the values being sent to the sqlite database while using Core Data SQL Debug?

在我的启动时传递的参数"调试选项中使用-com.apple.CoreData.SQLDebug 1"可以很好地打印 SQL 结构

Using the "-com.apple.CoreData.SQLDebug 1" in my "Arguments Passed on Launch" debug options prints the SQL structure just fine

(您可以在此处查看如何使用它:XCode4 和 Core Data:如何启用 SQL 调试)

(you can check see how to use this here: XCode4 and Core Data: How to enable SQL Debugging)

但问题是打印的 NSLog 类似于 UPDATE ZTABLE SET ZCOLUMN = ?WHERE ZID = ? 如果您想查看发送到数据库的完整 SQL 语句和/或数据是什么,它根本没有帮助.

But the problem is that the NSLog printed is something like UPDATE ZTABLE SET ZCOLUMN = ? WHERE ZID = ? and it does not help at all if you are trying to see what is the full SQL statement and/or data being sent to the database.

推荐答案

在Xcode中打开Product -> Scheme -> Edit Scheme..."并添加到启动时传递的参数":

Open "Product -> Scheme -> Edit Scheme..." in Xcode and add to "Arguments Passed on Launch":

-com.apple.CoreData.SQLDebug 3
-com.apple.CoreData.Logging.stderr 1 

(核心数据调试需要第二个启动参数iOS 10/macOS 10.12 或更高版本,请参阅com.apple.CoreData.SQLDebug not workinga> 了解更多信息.)

(The second launch argument is needed for Core Data debugging on iOS 10/macOS 10.12 or later, see com.apple.CoreData.SQLDebug not working for more information.)

您将看到 SQL 语句绑定到的所有值.示例输出:

The you'll see all the values that the SQL statements are bound to. Example output:

test56[1588:c07] CoreData: sql: BEGIN EXCLUSIVE
test56[1588:c07] CoreData: sql: INSERT INTO ZEVENT(Z_PK, Z_ENT, Z_OPT, ZTIMESTAMP) VALUES(?, ?, ?, ?)
test56[1588:c07] CoreData: details: SQLite bind[0] = (int64)13
test56[1588:c07] CoreData: details: SQLite bind[1] = (int64)1
test56[1588:c07] CoreData: details: SQLite bind[2] = (int64)1
test56[1588:c07] CoreData: details: SQLite bind[3] = "368650709.435904"
test56[1588:c07] CoreData: sql: COMMIT

这篇关于如何打印 Core Data 调试值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆