这个 SQLite 查询返回一个计数为 0 的游标...我知道它应该至少有 1。有人可以看一下吗? (真快)
public Cursor fetchIsOverride(String username) {
int override = 1;
Cursor cursor = mDb.query(true, OVERRIDE_TABLE, new String[] {KEY_ROWID, KEY_USERNAME, KEY_ISOVERRIDE, KEY_FIRSTNAME, KEY_LASTNAME, KEY_EMAIL, KEY_HOMEPHONE, KEY_WORKPHONE, KEY_PICTURE}, KEY_USERNAME + "= '" + username +"' " + "AND " + KEY_ISOVERRIDE + "=" + override, null, null, null, null, null);
return cursor;
}
我在表中有一行 KEY_ISOVERRIDE 值为 1,并且带有我正在查询的用户名。这是肯定的。谁能看出这个语法有什么问题吗?我确定它在 WHERE 子句中,但据我所知,它没问题。谢谢。
public Cursor fetchIsOverride(String username) {
int override = 1;
Cursor cursor = mDb.query(true, OVERRIDE_TABLE, new String[] {KEY_ROWID, KEY_USERNAME, KEY_ISOVERRIDE, KEY_FIRSTNAME, KEY_LASTNAME, KEY_EMAIL, KEY_HOMEPHONE, KEY_WORKPHONE, KEY_PICTURE}, KEY_USERNAME + "= '" + username +"' " + "AND " + KEY_ISOVERRIDE + "=" + override, null, null, null, null, null);
return cursor;
}
I have a row on the table with a KEY_ISOVERRIDE value of 1, and with the username I am querying. This is for certain. Can anyone see anything wrong with this syntax? I'm sure its in the WHERE clause, but as far as I can tell it's OK. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您的
用户名
或覆盖
字符串包含任何标点符号、空格或其他异常字符,则可能需要对其进行转义。最好使用参数绑定 API,而不是将字符串直接插入 SQL 语句中。If your
username
oroverride
string has any punctuation, spaces, or other unusual characters, it may need to be escaped. It's better to use the parameter binding apis instead of interpolating strings directly into the SQL statements.尝试在查询的条件部分中使用 double == 而不是 single ==,如下所示
try to use double == instead of single in the condition section of your query like this
我是个白痴,同时包括
moveToFirst()
;还有一个 while 循环:抱歉给您带来麻烦。但也许其他人也会以这种方式发现他们的错误。
I was being an idiot and including both
moveToFirst()
; AND a while loop like:Sorry for the trouble. But maybe someone else will catch their mistake this way too.
Cursor c=db.query("tbl_TEMP", new String[]{"sitename"+" as name",
"网站" +" 作为网站","类别" +" 作为类别" },
//"站点名称"+"=?", new String[]{"iPhoneAppDeveloper"}, null, null, null);
"sitename"+"=?", new String[] {"从 DB 中查找特定记录的字符串"} , null, null, null);
if (c.moveToFirst())
{
字符串名称、网站、类别;
int nameColumn = c.getColumnIndex("name");
int websiteColumn = c.getColumnIndex("网站");
int CategoryColumn = c.getColumnIndex("类别");
Cursor c=db.query("tbl_TEMP", new String[]{"sitename"+" as name",
"Website" +" as website","category" +" as category" },
//"sitename"+"=?", new String[]{"iPhoneAppDeveloper"}, null, null, null);
"sitename"+"=?", new String[] {"your string to find perticular record frm DB"} , null, null, null);
if (c.moveToFirst())
{
String name,website,categoty;
int nameColumn = c.getColumnIndex("name");
int websiteColumn = c.getColumnIndex("website");
int categoryColumn = c.getColumnIndex("category");