如何防止 Android SQLite 将堆栈跟踪转储到 logcat?

发布于 2024-12-18 21:12:13 字数 509 浏览 3 评论 0原文

在 Android 2.3.3 上,我正在使用 API 方法批量导入到我的 SQLite 表之一:

SQLiteDatabase.insert(String table, String nullColumnHack, ContentValues value)

它工作正常,但如果有任何数据库错误行(例如约束错误)将完整的堆栈跟踪写入 Android Logcat,它很快就会填满。

我怎样才能关闭这个堆栈跟踪?

我已经处理了抛出的任何异常,但 Logcat 正在从 SQLite 库代码中受到污染。

我担心移动设备上的性能。

  • 启用导入事务已经
  • 预加载数据库是不可能的,因为数据可能会改变

应该强制执行约束,我将处理违规,但 Logcat 中每个违规的 20 行堆栈跟踪乘以数百个违规是我想要关闭的。

不幸的是,我也无法使用 Android Froyo 引入的高级冲突处理,因为应用程序也必须在旧设备上运行。

干杯。

On Android 2.3.3 I'm doing a bulk import into one of my SQLite tables, using the API method:

SQLiteDatabase.insert(String table, String nullColumnHack, ContentValues values)

It works fine, but if there is a database error with any row (e.g. constraint error) a full stack trace is written to Android Logcat which quickly fills up.

How can I turn off this stack trace?

I already handle any Exception being thrown but the Logcat is being polluted from within the SQLite library code.

I am worried about performance on mobile devices.

  • transactions for import are enabled already
  • preloaded DB is impossible because data might change

Constraints should be enforced and I will handle violation, but 20 line stack traces in Logcat for each violation multiplied by hundreds of violations is what I want to turn off.

Unfortunately I also cannot use advanced conflict handling introduced with Android Froyo because app must also run on older devices.

Cheers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

反话 2024-12-25 21:12:13

好的,我刚刚找到了如下解决方案:

我必须使用不同的 API 方法(不是 SQLiteDatabase.insert()):

SQLiteDatabase.insertOrThrow(String table, String nullColumnHack, ContentValues values)

现在,异常从 SQLite 库中抛出,正如预期的那样,并且没有堆栈跟踪被转储。

OK, I just found the solution as follows:

I have to use a different API method (not SQLiteDatabase.insert()):

SQLiteDatabase.insertOrThrow(String table, String nullColumnHack, ContentValues values)

Now, the exception is thrown from the SQLite library, as expected and no stack trace is dumped.

留蓝 2024-12-25 21:12:13

只需根据标签或进程 ID 过滤掉您不感兴趣的任何内容即可。您可以在 Eclipse 中的 Logcat 查看器中轻松完成此操作,或者如果您在命令行上使用 Logcat 说明在这里

Just filter out any stuff you're not interested in, based on the tag or the process ID. You can do it easily in the Logcat viewer in Eclipse, or if you're using Logcat on the command line the instructions are here.

﹎☆浅夏丿初晴 2024-12-25 21:12:13

这不是污染。 LogCat 的目的是注册设备/模拟器上发生的所有事情。

如果您想过滤掉 LogCat,则可以在 Eclipse 中实现(您可以按日志标记、按 pid 或按日志级别进行过滤),从而提供一种从 LogCat 窗口“删除”不需要的异常的方法。

编辑如果问题是性能(根据您的评论),我认为您不必担心。

  • 如果您发现性能不佳,通过在批量插入上启用事务您将获得更多收益。
  • 另外,如果要为您的应用程序插入“起始数据”,您是否考虑过使用预加载的数据库来运送 apk?您无需在运行时插入所有内容,只需复制您自己准备的现有数据库即可。不再有约束问题,用户几乎可以立即启动。当然,如果是动态批量插入(基于用户输入或者运行时定义的外部参数),那就不可能了。

It's not pollution. It's the purpose of LogCat to register everything that's going on on the device / emulator.

If you want to filter out your LogCat, it's possible in Eclipse (you can filter by log tag, by pid, or by log level), thus providing a way to "remove" unwanted exceptions from a LogCat window.

EDIT If the issue is performance (according to your comments), I don't think you should worry.

  • If you find bad performances, you'll gain A LOT more by enabling transactions on your batch insert.
  • Also, if it's to insert "starting data" for your application, have you considered shipping the apk with a pre-loaded database? Instead of inserting everything at run-time, you could just copy an existing database that you prepared yourself. No constraint problem anymore, and almost instant start for your users. Of course, if it's dynamic batch insert (based on user entry or external parameters defined at runtime), it's not possible.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文