如何删除 CURRENT_TIMESTAMP 列?

How to perform delete on a CURRENT_TIMESTAMP column?

问题:

SQLITE TABLE:

  String create_sql3 = "CREATE TABLE IF NOT EXISTS " + Tablename3 + "("
                    + SNO + " INTEGER NOT NULL," + ITEM + " INTEGER NOT NULL,"
                    + DATETIMESTAMP + " INTEGER DEFAULT CURRENT_TIMESTAMP )";

删除查询:

db.execSQL("DELETE FROM " + Tablename3 + " WHERE DATETIMESTAMP = " + Integer.parseInt(deltimestamp.get(y))  + ";");

异常记录:

android.database.sqlite.SQLiteException:
unrecognized token: "01T17" (code 1):,while compiling: DELETE
FROM INFOTABLE WHERE DATATIMESTAMP = 2020-01-01T17:45:31.127452+03:00[Asia/Riyadh];

此处 deltimestamp 是一个字符串数组列表,其中日期时间戳为字符串。感谢有关 CURRENT_TIMESTAMP 列的删除查询更正的帮助!

将table保存为timestamp(Long Value : 1231413123) 这样您在删除过程中查询相关值会更方便

样本Table;

CREATE TABLE MyTable(
        ID INTEGER PRIMARY KEY,
        Foo TEXT,
        Bar TEXT,
        Timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
    );

已解决问题![​​=25=]

查询(错误):

db.execSQL("DELETE FROM " + Tablename3 + " WHERE DATETIMESTAMP = " + Integer.parseInt(deltimestamp.get(y))  + ";");

查询(固定):

db.execSQL("DELETE FROM " + Tablename3 + " WHERE DATETIMESTAMP = " + "'" + deltimestamp.get(y)  + "'" + ";");

db.execSQL("DELETE FROM " + Tablename3 + " WHERE DATETIMESTAMP = "+ "'" + cursor.getString(7) + "'" + ";");