Select 从 sqlite 订购的数据
Select data that is ordered from sqlite
我正在尝试获取按列排序的数据,但它不起作用。知道为什么吗?
public ArrayList<HashMap<String, String>> getMonthData(String month,String year, String name){
ArrayList<HashMap<String,String>> activityArrayList = new ArrayList<HashMap<String,String>>();
String selectQuery = "SELECT * FROM activity WHERE year='"+year+"' AND month='"+month+"' AND name=? ORDER BY day ASC";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery(selectQuery,new String[] { name });
if(cursor.moveToFirst()){
do{
HashMap<String, String> activityMap = new HashMap<String,String>();
activityMap.put("day",cursor.getString(2).toString());
activityArrayList.add(activityMap);
}while(cursor.moveToNext());
}
return activityArrayList;
}
解决方案是我将日期存储为文本,因此它是按字典顺序排列的。所以我必须把它变成真实的。使用 "CAST(day AS REAL)"。
我正在尝试获取按列排序的数据,但它不起作用。知道为什么吗?
public ArrayList<HashMap<String, String>> getMonthData(String month,String year, String name){
ArrayList<HashMap<String,String>> activityArrayList = new ArrayList<HashMap<String,String>>();
String selectQuery = "SELECT * FROM activity WHERE year='"+year+"' AND month='"+month+"' AND name=? ORDER BY day ASC";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery(selectQuery,new String[] { name });
if(cursor.moveToFirst()){
do{
HashMap<String, String> activityMap = new HashMap<String,String>();
activityMap.put("day",cursor.getString(2).toString());
activityArrayList.add(activityMap);
}while(cursor.moveToNext());
}
return activityArrayList;
}
解决方案是我将日期存储为文本,因此它是按字典顺序排列的。所以我必须把它变成真实的。使用 "CAST(day AS REAL)"。