Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 比较ZoneDateTime以删除SQLite中的记录?_Android_Sqlite_Localdate_Zoneddatetime_Localdatetime - Fatal编程技术网

Android 比较ZoneDateTime以删除SQLite中的记录?

Android 比较ZoneDateTime以删除SQLite中的记录?,android,sqlite,localdate,zoneddatetime,localdatetime,Android,Sqlite,Localdate,Zoneddatetime,Localdatetime,问题: 我在SQLITE DB中有一列存储ZoneDateTime。我需要使用此ZonedDateTimetimestamp列删除早于特定日期的记录 到目前为止已完成: 试图查询记录并从中提取LocalDate,以比较日期早于特定日期 但是,这只会创建一个LocalDate而不是ZonedDateTime的列表,以便我可以比较这些循环的ZonedDateTime来删除记录。谢谢你的帮助 通过 public ArrayList<String> CompareZDT(String st

问题: 我在SQLITE DB中有一列存储
ZoneDateTime
。我需要使用此
ZonedDateTime
timestamp列删除早于特定日期的记录

到目前为止已完成:

  • 试图查询记录并从中提取
    LocalDate
    ,以比较日期早于特定日期
  • 但是,这只会创建一个
    LocalDate
    而不是
    ZonedDateTime
    的列表,以便我可以比较这些循环的
    ZonedDateTime
    来删除记录。谢谢你的帮助
通过

public ArrayList<String> CompareZDT(String st) {

    ArrayList<String> ZDTtodelete;
    ArrayList<String> ZDTrejected;
    ZDTtodelete = new ArrayList<String>();
    ZDTtoavoid = new ArrayList<String>();

    LocalDate todaysDate = LocalDate.now(ZoneId.of("Asia/Riyadh"));
    LocalDate checkDate = todaysDate.minusDays(120);

    String selectQuery = "SELECT * FROM " + Tablename + ";";

    SQLiteDatabase database = dbHelper.getWritableDatabase();
    Cursor cursor = database.rawQuery(selectQuery, null);
    if (cursor.moveToFirst()) {
        do {

            if(ZonedDateTime.parse(cursor.getString(5)).toLocalDate().isBefore(checkDate)) {
                ZDTtodelete.add(cursor.getString(7));
            }else
            {
                ZDTrejected.add(cursor.getString(7));
            }

        } while (cursor.moveToNext());
    }
    cursor.close();

    if (st.equals("DELETE"))
    {
        return ZDTtodelete;
    }else
    {
        return ZDTrejected;
    }

}
public ArrayList CompareZDT(String st){
删除ArrayList;
ArrayList Zdtreed;
ZDTODelete=新的ArrayList();
ZdtoAvoid=新的ArrayList();
LocalDate todaysDate=LocalDate.now(亚洲/利雅得地区);
LocalDate checkDate=todaysDate.minusDays(120);
String selectQuery=“SELECT*FROM”+Tablename+;”;
SQLiteDatabase=dbHelper.getWritableDatabase();
Cursor=database.rawQuery(selectQuery,null);
if(cursor.moveToFirst()){
做{
if(ZonedDateTime.parse(cursor.getString(5)).toLocalDate().isBefore(checkDate)){
zdtodele.add(cursor.getString(7));
}否则
{
添加(cursor.getString(7));
}
}while(cursor.moveToNext());
}
cursor.close();
如果(st.equals(“删除”))
{
返回并删除;
}否则
{
返回到树上;
}
}

使用arraylist[ZDTODelete],循环并检查数据库中的时间戳列,从而可以执行删除操作。

通过

public ArrayList<String> CompareZDT(String st) {

    ArrayList<String> ZDTtodelete;
    ArrayList<String> ZDTrejected;
    ZDTtodelete = new ArrayList<String>();
    ZDTtoavoid = new ArrayList<String>();

    LocalDate todaysDate = LocalDate.now(ZoneId.of("Asia/Riyadh"));
    LocalDate checkDate = todaysDate.minusDays(120);

    String selectQuery = "SELECT * FROM " + Tablename + ";";

    SQLiteDatabase database = dbHelper.getWritableDatabase();
    Cursor cursor = database.rawQuery(selectQuery, null);
    if (cursor.moveToFirst()) {
        do {

            if(ZonedDateTime.parse(cursor.getString(5)).toLocalDate().isBefore(checkDate)) {
                ZDTtodelete.add(cursor.getString(7));
            }else
            {
                ZDTrejected.add(cursor.getString(7));
            }

        } while (cursor.moveToNext());
    }
    cursor.close();

    if (st.equals("DELETE"))
    {
        return ZDTtodelete;
    }else
    {
        return ZDTrejected;
    }

}
public ArrayList CompareZDT(String st){
删除ArrayList;
ArrayList Zdtreed;
ZDTODelete=新的ArrayList();
ZdtoAvoid=新的ArrayList();
LocalDate todaysDate=LocalDate.now(亚洲/利雅得地区);
LocalDate checkDate=todaysDate.minusDays(120);
String selectQuery=“SELECT*FROM”+Tablename+;”;
SQLiteDatabase=dbHelper.getWritableDatabase();
Cursor=database.rawQuery(selectQuery,null);
if(cursor.moveToFirst()){
做{
if(ZonedDateTime.parse(cursor.getString(5)).toLocalDate().isBefore(checkDate)){
zdtodele.add(cursor.getString(7));
}否则
{
添加(cursor.getString(7));
}
}while(cursor.moveToNext());
}
cursor.close();
如果(st.equals(“删除”))
{
返回并删除;
}否则
{
返回到树上;
}
}
使用arraylist[ZDTODelete],循环并检查DB中的TIMESTAMP列,从而可以执行删除操作