我在Sqlite数据库中有5个表: 1.maths 2.boilogy 3.chemestry 4.physics 5.GK.
在所有表格中10问题。最后我们在测试页面中生成随机问题 那么什么是Sq lite数据库中的查询
public ArrayList<ExamModel> getRandomQuestion() {
ArrayList<ExamModel> list = new ArrayList<ExamModel>();
ExamModel model = null;
Cursor cursor = null;
cursor=myDataBase.query(tbl_MST_CA+","+tbl_MST_Exam+","+tbl_MST_Geography, null, null, null, null, null, "RANDOM()","15");
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++) {
model = new ExamModel();
model.setId(cursor.getInt(cursor.getColumnIndex("Id")));
model.setAns1(cursor.getString(cursor.getColumnIndex("Answer1")));
model.setAns2(cursor.getString(cursor.getColumnIndex("Answer2")));
model.setAns3(cursor.getString(cursor.getColumnIndex("Answer3")));
model.setAns4(cursor.getString(cursor.getColumnIndex("Answer4")));
model.setQuestion(cursor.getString(cursor
.getColumnIndex("Question")));
model.setTrueAnswer(cursor.getString(cursor
.getColumnIndex("TrueAnswer")));
model.setLevelId(cursor.getInt(cursor.getColumnIndex("LevelId")));
model.setExamId(cursor.getInt(cursor
.getColumnIndex("ExamIdRef")));
list.add(model);
cursor.moveToNext();
}
}
if (cursor != null)
cursor.close();
return list;
}