HTC Desire 中的数据库锁定问题 [英] database lock issue in HTC Desire

查看:29
本文介绍了HTC Desire 中的数据库锁定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,一项服务是从服务器获取数据并将其插入到表 A.

In my application one service is getting data from server and inserting it to table A.

如果我转到特定的 UI,我需要从另一个 table B 中列出数据如果背景操作正在做它会产生数据库锁定异常.我有两个数据库操作在两个不同的表上并行完成.

If I go to particular UI, I need to list data from another table B if background operation is doing it will generate database locked exception. I got two database operation done in parallel each on two different table.

它在三星 gt15801 中运行良好.但是HTC希望它会生成数据库锁定错误.

It is working fine in samsung gt15801. But htc desire it will generate database locked error.

HTC 愿望 - 插入过程需要 91 秒.

HTC desire - insertion process takes 91 seconds.

三星 gt15801 - 插入过程需要 21 秒.

Samsung gt15801 - insertion process takes 21 seconds.

推荐答案

尝试使用一个 SqliteDatabaseHelper 并使其单实例. 之后不要完成操作后关闭 SqliteDatabase 实例.

Try to use one SqliteDatabaseHelper and make it single instance. After that don't close the SqliteDatabase instance after complete your operations.

您可以为此实现对数据库的锁定

You can implement lock on database for that see this

http://www.sqlite.org/lockingv3.html

当你启动一个有很多并发操作的数据库操作时,你必须使用

When you start a database operation which has many concurrent operation then you have to use

database.beginTransaction(); /* for start transaction */

完成对数据库的操作后就可以使用

and after completing operation on database you can use

database.setTransactionSuccessful();    
database.endTransaction();

但是如果您在事务之间出错,则不要设置 database.setTransactionSuccessful(); 以便事务将被回滚.

But if you give error in between transaction then don't set database.setTransactionSuccessful(); so that the transaction will be rollback.

您也可以在出错时通过 database.inTransaction(); 检查当前数据库是否在事务中;如果返回 true,则您在事务中,否则您不在事务中

Also you can check at the time of error whether currently the database is in transaction or not by database.inTransaction(); if it return true then you are in transaction else you are not in transaction

也可以通过调用

database.isDbLockedByCurrentThread();
database.isDbLockedByOtherThreads();

这将返回布尔值.

您也可以通过

database.setLockingEnabled(boolean);

以上删除的方法已被弃用,因此请不要使用.

Above deleted methods are deprecated so please do not use.

这篇关于HTC Desire 中的数据库锁定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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