Android的SQLite的:哪个查询("查询"或" rawQuery")更快?更快、SQLite、Android、rawQuery

2023-09-04 06:26:04 作者:听雨少年

我正在开发一款使用Android操作系统的数据库应用程序。我只是想知道哪个code执行速度更快,它们之间有什么区别呢?

查询 - 1 =

  db.rawQuery(SELECT * FROM USER_TABLE,其中user_ID的=+用户id,NULL);
 

查询 - 2 =

  db.query(USER_TABLE_NAME,ALL_COLUMNS,USER_ID =+用户id,NULL,NULL,NULL,NULL);
 

解决方案

看着SQLiteDatabase.java在Android源代码显示,查询(..)最终调用QueryBuilder的打造查询作为一个字符串,然后将其基本要求rawQuery()。他们应该是大体相当,假设你也做了同样的工作,以建立自己的声明。

android 查看sqlite数据库中内容的方法

I am developing one android database application . I just want to know which code execute faster and what is the difference between them?

Query - 1 =

db.rawQuery("select * from user_table where user_id =" + userId, null);

Query - 2 =

db.query(USER_TABLE_NAME, ALL_COLUMNS, "user_id = " + userId, null, null, null, null);

解决方案

Looking at SQLiteDatabase.java in the android source shows that the query(..) ends up calling the QueryBuilder to build the query as a single string and then it essentially calls rawQuery(). They should be roughly equivalent, assuming that you also did the same work to build your own statement.