Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – How to perform delete on a CURRENT_TIMESTAMP column?

Posted on November 14, 2022

Solution 1 :

Save the table as timestamp(Long Value : 1231413123) It will be easier for you to query the relevant values ​​during the deletion process.

Sample Table;

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

Solution 2 :

Fixed the issue!

QUERY (ERROR):

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

QUERY (FIXED):

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

OR

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

Problem :

ISSUE:

  • I have table [ INFOTABLE ] with a timestamp column named DATETIMESTAMP [INTEGER] datatype.
  • I need to delete records using this column but delete query throws error.
  • It is mainly because of the T [TIME indicator] inbetween the timestamp captured. [Eg:] 2020-01-01T17:45:31.127452+03:00[Asia/Riyadh]

SQLITE TABLE:

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

DELETE QUERY:

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

EXCEPTION LOGGED:

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];

Here deltimestamp is a String Arraylist which has datetimestamps as String. Appreciate help on Delete query correction for CURRENT_TIMESTAMP column!

Comments

Comment posted by Arda Kazancı

Save the table as timestamp(Long Value : 1231413123) It will be easier for you to query the relevant values ​​during the deletion process.

Comment posted by Gladiator

Hi @kzncrda! This one you say uses Java.time?

Comment posted by Arda Kazancı

yes. Timestamp timestamp = new Timestamp(System.currentTimeMillis()); System.out.println(timestamp.getTime());

Comment posted by Gladiator

@kzncrda timestamp is from java.sql. What I store in table is zoneddatetime [Java.time].

READ  [ANSWERED] react native - Facebook login on Android always returns isCancelled = true when asking for email (second time)
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress