我正在使用UNION从多个表执行搜索界面。搜索单词被过滤的类是SimpleCursorAdapter形式,我的问题是当我点击搜索到的单词以获取其信息时,我看到的唯一的东西是白色空白页。
这是我的代码,用于检索“获取更多信息”字样。我认为问题出在WHERE条件下。请帮我。感谢。
commandId = getIntent().getIntExtra("COMMAND_ID", 0);
SQLiteDatabase db = (new DBHelper(this)).getWritableDatabase();
final String commandIdString = String.valueOf(commandId);
Cursor cursor = db.rawQuery("SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_acc WHERE _id = ? " +
"UNION SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_filems WHERE _id = ? " +
"UNION SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_psu WHERE _id = ? " +
"UNION SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_shells WHERE _id = ? " +
"UNION SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_sic WHERE _id = ? " +
"UNION SELECT _id AS _id,name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_stp WHERE _id = ?",
new String[]{commandIdString, commandIdString, commandIdString, commandIdString, commandIdString, commandIdString});
if (cursor.getCount() == 1)
{
cursor.moveToFirst();
commandName = (TextView) findViewById (R.id.commandName);
commandName.setText(cursor.getString(cursor.getColumnIndex("name")));
commandDesc = (TextView) findViewById (R.id.commandDesc);
commandDesc.setText(cursor.getString(cursor.getColumnIndex("desc")));
commandSyntax = (TextView) findViewById (R.id.commandSyntax);
commandSyntax.setText(cursor.getString(cursor.getColumnIndex("syntax")));
commandOption = (TextView) findViewById (R.id.commandOption);
commandOption.setText(cursor.getString(cursor.getColumnIndex("option")));
}
}
答案 0 :(得分:1)
对于您在原始查询中使用的每个参数,您必须将值设置为replace,所以
new String[]{""+commandId}
仅适用于列表中的第一个参数。替换为
final String commandIdString = String.valueOf(commandId);
new String[]{commandIdString, commandIdString, commandIdString, commandIdString, commandIdString, commandIdString}