関数に DAY と HOUR を指定し、2 つの text-not-null 列 COLUMN_FROM1 と COLUMN_TO1 の間で COLUMN_DAY1=day と HOUR をフェッチしたいと考えています。奇妙なことに、7 時間を指定すると、FROM1 と TO1 にそれぞれ 6 と 9 が含まれている場合、肯定的な検索が返されます。12 時間を指定し、FROM1 と TO1 にそれぞれ 11 と 17 を指定すると、検索が機能します。
しかし、7 を指定し、FROM1 と TO1 にそれぞれ 6 と 10 が含まれていると、検索が機能しません。10 が 2 桁で 6 が 1 桁、またはこれらの線に沿った何かに関連していると思います。以下は、私が使用しているカーソルクエリです。助けてください。何が間違っていますか?
Cursor cursor = database.query(MySQLiteHelper.TABLE_COMMENTS,
allColumns, MySQLiteHelper.COLUMN_DAY1 +" ='" + Day+
"' AND " +MySQLiteHelper.COLUMN_FROM1 + " <=" + Hour+
" AND " +MySQLiteHelper.COLUMN_TO1+ " >" +Hour
, null, null, null, null);
編集: COLUMN_FROM1 に 6 が含まれ、COLUMN_TO1 に 10 が含まれている場合にも true を返す必要があります。
SQLite データベースにデータを書き込む関数:
InputStream is =getResources().openRawResource(R.raw.ems_data);
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
byte[] myData = baf.toByteArray();
String dataInString = new String(myData);
String[] lines = dataInString.split("\n");
for (int i=0; i<lines.length; i++){
comment = datasource.createComment(lines[i]);
// adapter.add(comment);
}
編集:
createComment(); 関数:
public Comment createComment(String comment) {
ContentValues values = new ContentValues();
//parse data in string comment
String[] words = comment.split("\\t");
values.put(MySQLiteHelper.COLUMN_COMMENT, comment);
values.put(MySQLiteHelper.COLUMN_NAME, words[0]); //adds to column "name"
values.put(MySQLiteHelper.COLUMN_CONTACT, words[1]);
values.put(MySQLiteHelper.COLUMN_DAY1, words[2]);
values.put(MySQLiteHelper.COLUMN_FROM1, words[3]);
values.put(MySQLiteHelper.COLUMN_TO1, words[4]);
values.put(MySQLiteHelper.COLUMN_DAY2, words[5]);
values.put(MySQLiteHelper.COLUMN_FROM2, words[6]);
values.put(MySQLiteHelper.COLUMN_TO2, words[7]);
//expected error above after DAY2 since it can be NULL
long insertId = database.insert(MySQLiteHelper.TABLE_COMMENTS, null,
values);
Cursor cursor = database.query(MySQLiteHelper.TABLE_COMMENTS,
allColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
Comment newComment = cursorToComment(cursor);
cursor.close();
return newComment;
}