SQLite 查询返回 null
我所做的
我有一个 Gridview,它用 imageID 填充了我的数据库。现在我设置了一个 onItemClickListner 来获取 imageID ->这有效!现在我想用该 imageID 搜索我的数据库,但它总是返回“null”,但这不应该是因为如果用这些 imageID 完全填充我的数据库。 表的结构是: RowID | RowID来源 |信息 在 Info 中,我存储了 imageID 的
问题
我必须如何更改光标才能通过 INFO 获取条目。 在这里您可以找到我的光标的代码:
代码:
//Es wird nach der ID des smiley gesucht.
public Cursor getSmiley(String info) throws SQLException {
Cursor mCursor =
this.mDb.query(true, DATABASE_TABLE, new String[] { INFO, SOURCE,
}, INFO + "=" + info, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
如何获取 imageID-back
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(SFilterConfigActivity.this, "" + position, Toast.LENGTH_SHORT).show();
//Hier wird herrausgefunden welche ID das Bild hat und in den jeweiligen String gespeichert
source = String.valueOf(v.getId());
Log.v("IMAGEID", source);
SmileyHelper.open();
Cursor c = SmileyHelper.getSmiley(source);
startManagingCursor(c);
if (c != null){
String size = String.valueOf(c.getCount());
Log.v("WhatsInC", size);
}
if (c.moveToFirst()) {
do {
text = c.getString(c.getColumnIndex(SmileyDBAdapter.SOURCE));
Log.v("WHATINTEXT", text);
smiley = c.getString(c.getColumnIndex(SmileyDBAdapter.INFO));
Log.v("WHATINSMILEY", smiley);
} while (c.moveToNext());
SmileyHelper.close();
其他信息:
- WhatIsInC,返回“0”。
如果您需要更多代码,请告诉我 提前感谢您的帮助! 此致 游猎
What I've done
I have a Gridview which is filled over my Database with the imageID's. Now I setted up a onItemClickListner with that I get the imageID -> this works!. Now I'd like to search my DB with that imageID, but it allways returns "null", but that shouldn't be because if filled my DB exactly with those imageID's.
The Structure of the Table is that: RowID | SOURCE | INFO
In Info i stored the imageID's
Question
How do I have to change Cursor that I can get the entries over INFO.
Down here you find the Code of my Cursor:
Code:
//Es wird nach der ID des smiley gesucht.
public Cursor getSmiley(String info) throws SQLException {
Cursor mCursor =
this.mDb.query(true, DATABASE_TABLE, new String[] { INFO, SOURCE,
}, INFO + "=" + info, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
How I get the imageID-back
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(SFilterConfigActivity.this, "" + position, Toast.LENGTH_SHORT).show();
//Hier wird herrausgefunden welche ID das Bild hat und in den jeweiligen String gespeichert
source = String.valueOf(v.getId());
Log.v("IMAGEID", source);
SmileyHelper.open();
Cursor c = SmileyHelper.getSmiley(source);
startManagingCursor(c);
if (c != null){
String size = String.valueOf(c.getCount());
Log.v("WhatsInC", size);
}
if (c.moveToFirst()) {
do {
text = c.getString(c.getColumnIndex(SmileyDBAdapter.SOURCE));
Log.v("WHATINTEXT", text);
smiley = c.getString(c.getColumnIndex(SmileyDBAdapter.INFO));
Log.v("WHATINSMILEY", smiley);
} while (c.moveToNext());
SmileyHelper.close();
Additional Information:
- WhatIsInC, returns "0".
If you need more Code, just tell me
Thx for your help in advance!
Best Regards
safari
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
db.query 具有以下参数:
因此,在您的查询中,
或
The db.query has the following parameters:
So, in your query,
or