我試圖檢索使用查詢從SQLite數據庫以前因爲某些原因沒有行populated..but查詢returnscursor數據..Sqllite查詢返回光標0行
因此,這裏的部分,其中我試圖檢索數據:
database.open();
Cursor cursor = database.getComponentData("CONTROLS", null, null);
int test = cursor.getCount();//This is the part where i test throught the eclipse debugger whelther there is any rows return
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
get.append("Video controls : "+cursor.getString(1)+" Audio Controls : "+cursor.getString(2)+" Reader controls : "+cursor.getString(3));
cursor.moveToNext();
}
cursor.close();
Cursor cursor1 = database.getComponentData("LIST", new String[]{"'URL'"},"AUDIO");
get.append("Video list : ");
cursor1.moveToFirst();
while (!cursor1.isAfterLast()) {
get.append(" "+cursor1.getString(1)+" "+cursor1.getString(2)+" "+cursor1.getString(3));
cursor1.moveToNext();
}
cursor1.close();
database.close();
這裏是我查詢的數據庫適配器的部分。
public Cursor getComponentData(String whichTable,String[] whichColumn,String whichSection) {
Cursor c = null;
if(whichSection!=null)
{
return database.query(whichTable, whichColumn,"SECTION = '"+whichSection+"'",null, null, null, null);
}
else{
return database.query(whichTable, whichColumn,null,null, null, null, null);
}
}
這是其中i插入到數據庫中先前的部分:
database.open();
ContentValues control = new ContentValues();
control.put("VIDEO_CONTROLS",video_control);
control.put("AUDIO_CONTROLS",audio_control);
control.put("READER_CONTROLS",book_control);
control_long =database.insertNewControl(control);
ContentValues temp_list = new ContentValues();
a_p=audio_playlist.split(",");
v_p=video_playlist.split(",");
b_p=booklist.split(",");
for(int i =0;i<a_p.length;i++){
temp_list.put("NAME", "test");
temp_list.put("URL", a_p[i]);
temp_list.put("SECTION", "AUDIO");
list_long= database.insertNewListRow(temp_list);
}
for(int i =0;i<v_p.length;i++){
temp_list.put("NAME", "test");
temp_list.put("URL", v_p[i]);
temp_list.put("SECTION", "VIDEO");
list_long= database.insertNewListRow(temp_list);
}
for(int i =0;i<b_p.length;i++){
temp_list.put("NAME", "test");
temp_list.put("URL", b_p[i]);
temp_list.put("SECTION", "READER");
list_long= database.insertNewListRow(temp_list);
}
database.close();
插入方法在適配器:
public Long insertNewControl(ContentValues controls_values) {
return database.insert("CONTROLS", null, controls_values);
}
public Long insertNewListRow(ContentValues list_values){
return database.insert("LIST", null, list_values);
}
感謝閱讀。
編輯: 忘記提到這一點,如果我是從數據庫中查詢()我已插入這些行之後,我將能夠得到行out.But我是來查詢這些行後我關閉()並再次打開(),遊標不返回任何行。
您確認數據是否在數據庫中(** BASICS **)? – JoxTraex 2012-08-16 03:15:31
與insert()是否返回非「-1」值一樣? – user1602020 2012-08-16 03:32:10
或使用eclipse中的sqlite工具檢查數據庫。 – JoxTraex 2012-08-16 03:32:53