SQLiteQueryBuilder.query()与SQLiteDatabase.query() [英] SQLiteQueryBuilder.query() vs SQLiteDatabase.query()

查看:1054
本文介绍了SQLiteQueryBuilder.query()与SQLiteDatabase.query()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是这两种方法之间的区别? 对我来说似乎SQLiteDatabase的唯一好处是它与不同的数据库的工作能力。我说得对?

What's the difference between these two approaches? For me it seems that the only benefit of SQLiteDatabase is its ability to work with different databases. Am I right?

推荐答案

的主要方法是 SQLiteDatabase#rawQuery()。无论 SQLiteDatabase#查询() SQLiteQueryBuilder 只是助手组成的SQL。

The primary method is SQLiteDatabase#rawQuery(). Both SQLiteDatabase#query() and SQLiteQueryBuilder are just helpers to compose the SQL.

SQLiteDatabase#查询()只能从一个表编写简单的查询。该 SQLiteQueryBuilder 可以创建连接,联合和这样的。由于 SQLiteQueryBuilder 是一个额外的对象,你只构造,如果你需要它的力量。

The SQLiteDatabase#query() can only compose simple queries from one table. The SQLiteQueryBuilder can create joins, unions and such. Since SQLiteQueryBuilder is an extra object, you'd only construct it if you need it's power.

我个人认为,任何不平凡的SQL更容易阅读的SQL比与助手这样的组成部分,所以我会使用 rawQuery SQLiteQueryBuilder ,但是这是一个爱好以及你如何知道SQL的问题。如果您有想要共同组成以不同的方式一些常见的子查询 SQLiteQueryBuilder 也可能是有用的。

Personally I think that any non-trivial SQL is easier to read as SQL than as pieces composed with helper like this, so I'd use rawQuery over SQLiteQueryBuilder, but that's a matter of taste and how well you know SQL. The SQLiteQueryBuilder might also be useful if you have some common subqueries that you want to compose together in different ways.

其实我也preFER(我使用SQLite主要是利用它的C API)使用prepared语句,因为SQL编译很慢相比,它的执行,但是我没有看到那个选项Java接口。

In fact I would prefer (I use sqlite mainly using it's C API) to use prepared statements, because compilation of SQL is slow compared to it's execution, but I don't see that option in the Java interface.

这篇关于SQLiteQueryBuilder.query()与SQLiteDatabase.query()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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