rawQuery 对比数据库.查询
与查询生成器相比,使用 rawQuery 是否有任何优势(反之亦然)?
例如,查询生成器是否可以再次防止 SQL 注入攻击(虽然对于网站来说不是一个大问题,但 SQL 注入 + 内容提供程序可能是一个问题)?或者其中一个比另一个更快?
我对 SQL 相当满意(足以满足我需要做的事情),所以我倾向于使用 rawQuery (我可以更轻松地阅读源代码),但我只是想知道我是否遗漏了一些可能的东西有用。
Are their any advantages in using rawQuery over the Query Builder (or vice versa)?
Does the Query Builder, for example, protect again SQL Injection attacks (While not a big a problem as with web sites, SQL Injection + a content provider could be an issue)? or is one faster than the other?
I'm fairly happy with SQL (enough for what I need to do anyway) and so I tend to go for rawQuery (I can read the source code easier), but I'm just wondering if I'm missing something that could be useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过提供的方法构建查询绝对是首选。它不仅可以保护您免受 SQL 注入的侵害,还可以为您构建查询,这样您就可以避免出现一大堆字符串连接,这些连接会使查询字符串的可读性较差且更容易出错。就性能而言,我认为这没有太大区别。
It's definitely preferred to build a query through the methods provided. Not only does it protect you from SQL injections, it also builds the query for you so you can avoid having a whole bunch of string concatenations that will make the query string less readable and more error prone. Performance-wise I don't think it makes much difference.
可读性是 rawQuery 的一个优点。至少对我来说。
如您所知,根据帕累托原理,开发人员花费 80% 的时间阅读代码。因此,可读性是一个非常有力的论据。
尽管 QueryBuilder 还提供了使用占位符的方法(防止 SQL 注入)。
希望有帮助。
Readability is an advantage of the rawQuery. At least for me.
As you know, according to the Pareto principle developer spend 80% of its time reading the code. Therefore the readability is a very strong argument.
Though QueryBuilder also provides the way to use placeholders (protect from SQL injections).
Hope that helps.