SQLite的.query()方法,WHERE子句仅采取双引号中的字符串 [英] SQLite .query() method, WHERE clause is only taking double quotes strings
问题描述
我有变量:
String owner="Mike";
String[] columns ={"quantity", "price","owner"}
我的光标正在试图获得
光标findEntry = db.query(sku_table,列所有者=+所有者,NULL,NULL,NULL,NULL);
My cursor is trying to get
Cursor findEntry = db.query("sku_table", columns, "owner="+owner, null, null, null, null);
我得到一个错误没有这样的列误差
I got an error no such column error
android.database.sqlite.SQLiteException: no such column: owner: , while compiling: SELECT quantity, price, owner, FROM sku_table WHERE owner=Mike
但是,如果我拿这个查询:
But if I take this query:
SELECT quantity, price, owner, FROM sku_table WHERE owner=Mike
和增加,
迈克,并在源码的浏览器,以执行查询测试,我不回去行。
工作查询看起来是这样的:
and add ""
to Mike, and tested in sqlite browsers to execute the query, I do get back the row.
The working query looks like this:
SELECT quantity, price, owner, FROM sku_table WHERE owner="Mike"
有人能下降约我如何将双引号一些启发?除了使用\ 谢谢!
Can somebody drop some insights about how do I incorporate double quotes? Other than use \" Thanks!
推荐答案
抱歉,这也正是为什么你应该用什么样的方式提供了理由! @Leandros和@Jake正在帮助在完全错误的方向!遗憾地说,...
Sorry, but that is exactly the reason why you should work with what the method offers! @Leandros and @Jake are helping in the totally wrong direction! Sorry to say that...
您应使用唯一的解决办法是这样的:
The only solution you should use is this:
Cursor findEntry = db.query("sku_table", columns, "owner=?", new String[] { owner }, null, null, null);
PS:是的,我倒投两个答案,因为它们可以工作,但条件是不应该使用的解决方案
ps: Yes I down voted both answers as they may work but providing a solution that shouldn't be used.
更新:
如果您需要多个条件的地方,只需添加像你会做一个正常的查询
If you need more than one where condition, just add it like you would do in a normal query
Cursor findEntry = db.query("sku_table", columns, "owner=? and price=?", new String[] { owner, price }, null, null, null);
的顺序?
和新的String [] {...}
元素必须是相同的!
The order of the ?
and the new String[] {...}
elements must be the same!
这篇关于SQLite的.query()方法,WHERE子句仅采取双引号中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!