Android的SQLite数据库的setlocale是同时打开分贝太慢。如何解决? [英] android sqlite database setlocale is too slow while opening db. How to solve?

查看:850
本文介绍了Android的SQLite数据库的setlocale是同时打开分贝太慢。如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的方法进行读/写DB:

I use the following method for reading/writing db:

1)数据库位于/data/data/{packagename}/databases/Database.db 由于数据库是大于3MB,我们发现了一个特定的soulution把它复制那里,要把它填入相应的数据。

1) Database is located at /data/data/{packagename}/databases/Database.db Since the database is greater than 3Mb we found a specific soulution to have it copied there and to have it populated with appropriate data.

2)以下是类实现的任务来获得打开的数据库。这个类是一个单身。

2) Following is the class implementing the task to get the opened database. This class is a singleton.

public class DatabaseHelper extends SQLiteOpenHelper

3)打开,我们用下面的方法数据库:

3) to open the database we use the following method:

SQLiteDatabase db = DatabaseHelper.getInsance().getReadableDatabase();

4)比rawquery用于queriing分贝:

4) Than rawquery is used for queriing the db:

Cursor cursor = db.rawQuery(query, null);

5)比最合适我们的宗旨,我们获取的数据库中的数据到内存在不同的结果集实例:

5) Than best fitting to our purposes we fetch the database data into memory in different resultset instances:

while (cursor.moveToNext()) {
 ResultSet rs = new ResultSet();
 rs.setThis(cursor.getInt(0));
 rs.setThat(cursor.getString(1));
 // and so on.. this is just an example
 ResultList.add(rs);
}

6)最后:

6) Finally:

cursor.close();
db.close();

7)设提,如果neccessary,事务也使用过,但使用事务没有导致加速

7) Let mention, if neccessary, transaction is used also, but using transaction didn't lead to speed-up.

对于每一个查询,上面的图案是(相当)紧随其后。但可惜的是这个解决方案似乎很慢。因此,一些分析方法是由它来清除,这源码的setlocale是在getReadableDatabase()始终运行(这是创造的!不要忘了),而且方法采用的大部分时间。单独卑贱40%。

For every single query the pattern above is (quite) followed. But unfortunatelly this solution seems very slow. So some method profiling is made and it came to clear, that sqlite setlocale is always run at getReadableDatabase() (which is created! don't forget) and that method takes the most of the time. Meanly 40% alone..

请指点如何解决这个问题!或者,也许请提供一个其他模式来满足我们的需要!

Please advice how to solve this problem! Or maybe please offer an other pattern to satisfy our needs!

在此先感谢

推荐答案

由于在这里提出的问题(<一href="http://stackoverflow.com/questions/22176445/sqlcipher-for-android-getreadabledatabase-overherad">SQLCipher为Android getReadableDatabase()Overherad ),您所看到的性能问题可能是由于SQLCipher密钥派生。打开数据库性能是故意缓慢的,因为密钥派生。你应该缓存数据库连接,以便它可以而不必打开并多次键入数据库中多次使用。如果这是可能的,在启动时打开数据库一次是pferred的行动方针的$ P $。在同一个数据库句柄的后续访问将不会触发密钥推导,所以性能会快很多。

As with the question posed here (SQLCipher for Android getReadableDatabase() Overherad) the performance issue you are seeing is likely due to SQLCipher key derivation. Performance for opening a database is deliberately slow due to key derivation. You should cache the database connection so that it can be used multiple times without having to open and key the database repeatedly. If this is possible, opening the database once during startup is the preferred course of action. Subsequent access on the same database handle will not trigger key derivation, so performance will be much faster.

这篇关于Android的SQLite数据库的setlocale是同时打开分贝太慢。如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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