0
我有這樣的SQLite查詢:android sqlite聯盟,如何從表中檢索結果?
Cursor orgiCursor = orgiDb.rawQuery("select task,taskDate from meeting where exists
(select `meeting.taskId from Task, meeting where meeting.taskId = Task.taskId and task.name='"+profName+"')
UNION SELECT subject,date from taskDeadline where exists (select taskDeadline.taskId from taskDeadline,Task where taskDeadline.taskId=Task.taskId and Task.name='"+profName+"') union select
specificOccassion,setDate from AnnualTask where exists (select taskId from Task,AnnualTask where Task.taskId = AnnualTask.taskId and Task.name = '"+profName+"' and AnnualTask.setDate<>'--')", null);
這是相當長的真的,但它完美的作品在SQLite的經理。我的問題是我在檢索數據時遇到錯誤。這是我的代碼片段:
try {
if (orgiCursor != null) {
if (orgiCursor.moveToFirst()) {
do {
String annualTask = orgiCursor.getString(orgiCursor.getColumnIndex("specificOccassion"));
String annualDate = orgiCursor.getString(orgiCursor.getColumnIndex("setDate"));
String meetingTask = orgiCursor.getString(orgiCursor.getColumnIndex("task"));
String meetingDate = orgiCursor.getString(orgiCursor.getColumnIndex("taskDate"));
String deadlineTask = orgiCursor.getString(orgiCursor.getColumnIndex("subject"));
String deadlineDate = orgiCursor.getString(orgiCursor.getColumnIndex("date"));
SearchResults sr2=new SearchResults();
sr2.setName(meetingTask);
sr2.settDate(meetingDate);
results.add(sr2);
SearchResults sr3 = new SearchResults();
sr3.setName(deadlineTask);
sr3.settDate(deadlineDate);
results.add(sr3);
SearchResults sr1 = new SearchResults();
sr1.setName(annualTask);
sr1.settDate(annualDate);
Log.i("Home","added"+annualTask + " & " +annualDate);
results.add(sr1);
} while (orgiCursor.moveToNext());
}
}
} catch (SQLiteException se) {
displayError1(se.toString());
Log.e(getClass().getSimpleName(), se.toString());
} finally {
if (orgiDb != null) {
orgiDb.close();
Log.e(getClass().getSimpleName(),"orgiDB closed()");
}
}
return results;
它返回此錯誤。 :(請幫我
02-12 19:28:00.809: INFO/Database(14515): sqlite returned: error code = 1, msg = ambiguous column name: taskId
02-12 19:28:00.849: ERROR/AndroidRuntime(14515): Caused by: android.database.sqlite.SQLiteException: ambiguous column name: taskId: , while compiling: select task,taskDate from meeting where exists (select meeting.taskId from Task, meeting where meeting.taskId = Task.taskId and task.name='Maria Ozawa')UNION SELECT subject,date from taskDeadline where exists (select taskDeadline.taskId from taskDeadline,Task where taskDeadline.taskId=Task.taskId and Task.name='Maria Ozawa') union select specificOccassion,setDate from AnnualTask where exists (select taskId from Task,AnnualTask where Task.taskId = AnnualTask.taskId and Task.name = 'Maria Ozawa' and AnnualTask.setDate<>'--')
02-12 19:28:01.059: ERROR/Database(14515): close() was never explicitly called on database '/data/data/orgy.organizer.home/databases/orgi'
02-12 19:28:01.059: ERROR/Database(14515): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
任何幫助將不勝感激... :( 所以我的問題是:
1.哪些部分的代碼我正好需要關閉連接/光標?
2.爲什麼Eclipse的給我這個錯誤?我試圖在SQLite的管理運行相同的語句,它給了我完美無瑕的結果。
謝謝。今天我會嘗試。 :) – kreigh 2011-02-13 03:13:04