0
如何根據當前時間從sqlite中獲取兩個時間點之間的數據。查詢從sqlite數據庫的兩個時間之間檢索數據?
我使用此查詢,但它不工作
final Cursor cView = db.rawQuery("SELECT * FROM proname WHERE FromTiming >= time('now', 'localtime')\n" + "" +
"AND ToTiming <= time('now', 'localtime')\n" + " ORDER BY FromTiming LIMIT 1", null);
我的OnCreate是:
public static final String[] titles = new String[]{"Akilam 360","Ipadikku Idhayam",
"Palsuvai Thoranam"};
public static final String[] fromtime = new String[]{"5:00:00","07:00:00","09:00:00"};
public static final String[] totime = new String[]{"6:59:59","08:59:59","10:59:59"};
public static final Integer[] images = {R.drawable.akilam_360,
R.drawable.ipadikku_idhayam, R.drawable.palsuvai_thoranam};
ListView listView;
List<Program> rowItems;
int iImageId;
String sTitle,sFrom,sTo ;
SQLiteDatabase db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dbcon);
Calendar c = Calendar.getInstance();
int seconds = c.get(Calendar.SECOND);
int minutes = c.get(Calendar.MINUTE);
int hour = c.get(Calendar.HOUR_OF_DAY);
String time = hour+":"+minutes+":"+seconds;
timer = (TextView) findViewById(R.id.timer);
timer.setText(time);
db =openOrCreateDatabase("MukilProgram", Context.MODE_PRIVATE,null);
db.execSQL("CREATE TABLE IF NOT EXISTS proname(ImageID INTEGER,Title TEXT,FromTiming INTEGER,ToTiming INTEGER);");
rowItems = new ArrayList<Program>();
for (int i = 0; i < titles.length; i++) {
Program item = new Program(images[i], titles[i],fromtime[i],totime[i]);
rowItems.add(item);
}
我恢復部分:
最後光標CVIEW = db.rawQuery(「SELECT *從代詞WHERE FromTiming> = time('now','localtime')\ n「+」「+ 」AND ToTiming < = time('now','localtime')\ n「+」ORDER BY FromTiming LIMIT 1 「, 空值); 如果(cView.getCount()> 0){
sImageID = new ArrayList<String>();
sName = new ArrayList<String>();
iFrom = new ArrayList<String>();
iTo = new ArrayList<String>();
while (cView.moveToNext()) {
sImageID.add(cView.getString(0));
sName.add(cView.getString(1));
iFrom.add(cView.getString(2));
iTo.add(cView.getString(3));
// sQuantity.add(cView.getString(2));
SQliteAdapter sqliteadapter = new SQliteAdapter(Databaseconnection.this, sImageID, sName,iFrom,iTo);
listView.setAdapter(sqliteadapter);
}
}
此查詢工作,但我沒有得到任何結果或錯誤,請幫我寫正確的查詢這一點。