0
我給函數一個DAY和一個HOUR,我想在兩個文本非空列COLUMN_FROM1和COLUMN_TO1之間獲取COLUMN_DAY1 = day和HOUR。奇怪的是,如果我說小時7,並且FROM1和TO1分別包含6和9,它將返回一個肯定的搜索。如果我給12小時和FROM1和TO1 contain 11和17分別搜索工作。SQLite查詢混亂,小於大於
但是,當我給7和FROM1和TO1分別包含6和10搜索不起作用。我認爲這與10位是兩位數字有關,6位是一位數字或者是與這些行數有關的東西。 下面是我使用的遊標查詢請大家幫忙,我做錯了什麼?
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);
編輯:
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時COLUMN_FROM1包含6和COLUMN_TO1包含10
功能將數據寫入到SQLite數據庫也應該返回true ();功能:
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;
}
你的描述不清楚。應該返回哪些記錄? –
@ cl-我取得了一些進展,所以我完全編輯了這個問題。請再看一遍。 –
數據庫和變量中值的類型是什麼?請顯示插入from/to值的代碼。 –