私は自分のデータベースにクエリを実行しています。選択部分にintを使用すると、必要な情報が返されます。選択に文字列を使用すると、何も返されません。文字列を使用するときにクエリを実行する別の方法はありますか、それとも何か間違ったことをしていますか?この関数は、intを渡したときに機能しましたが、文字列を渡したときに機能しません。ブレークポイントを使用しましたが、関数に入るパラメーターは正しいのですが、データベースからデータを取得しません。
これがコードです
public String childFound(String item_name)throws Exception
{
Cursor c = db.query(DB_TABLE, new String[] { KEY_INSPECTION_ID, KEY_ITEM_NAME},
"item_name="+ item_name, null, null, null, null);
int id=c.getColumnIndex(KEY_ITEM_NAME);
c.moveToFirst();
String result=c.getString(id);
c.close();
return result;
}
文字列item_nameをintinspectionItemに変更すると、機能します。また、dbの変数を宣言した場所も含まれています。
public class InspectionRecordsTableDBAdapter {
private static final String KEY_ROWID = "_id";
private static final String KEY_INSPECTION_ID = "inspection_id";
private static final String KEY_PARENT_NAME = "parent_name";
private static final String KEY_ITEM_NAME = "item_name";
private static final String KEY_COMMENT = "comment";
private static final String KEY_STATUS = "status";
private static final String DB_TABLE = "inspection_records";
private Context context;
private SignalSetDBHelper dbHelper;
private SQLiteDatabase db;
private SQLiteOpenHelper openHelper;
さらにコードが必要な場合はお知らせください。