1
INSERT INTO RefreshTokens(name, token) VALUES('googleFit', '1/ZxDpwJIxIYQb7TtxPMuYFpIoeE0urHd6LL3dY57ghsA') ON CONFLICT(name) DO UPDATE SET token=excluded.token;

Here is my sqlite command to upsert sqlite table in android. However, it is generating this error: android.database.sqlite.SQLiteException: near "ON": syntax error (Sqlite code 1): , while compiling

I have checked over and over and still cant find the error. What is wrong with the "on"?

Manh Nguyen
  • 373
  • 3
  • 12
  • refer this link : https://stackoverflow.com/questions/26058984/android-database-sqlite-sqliteexception-near-on-syntax-error-code-1 – Ali Jul 10 '18 at 13:25
  • @MohammadAli I have looked at your link. I don't think it is relevant to my case because my updated value is not default but will change – Manh Nguyen Jul 10 '18 at 13:32
  • 1
    Please refer to this link: https://stackoverflow.com/questions/418898/sqlite-upsert-not-insert-or-replace – Luis Cardoza Bird Jul 10 '18 at 13:41

2 Answers2

4

The issue could well be that the UPSERT syntax has only recently been added and is therefore not supported by the version of SQLite that you are using, as per :-

UPSERT is a special syntax addition to INSERT that causes the INSERT to behave as an UPDATE or a no-op if the INSERT would violate a uniqueness constraint. UPSERT is not standard SQL. UPSERT in SQLite follows the syntax established by PostgreSQL. UPSERT syntax was added to SQLite with version 3.24.0 (2018-06-04).

SQL As Understood By SQLite - upsert

MikeT
  • 51,415
  • 16
  • 49
  • 68
1

I have checked over and over and still cant find the error. What is wrong with the "on"

Nothing is wrong with "on", it's just SQLite standard (lib) doesn't have Conflict Clause.

You will have to run conflict clause queries via 'ContentValues' as below

ContentValues args = new ContentValues();
args.put("name", name);
args.put("token", token);
database.insertWithOnConflict("table_name", "name", args, SQLiteDatabase.CONFLICT_REPLACE)

Have a look at the following links, it will help you out.

SQLite Android Official

Link 2

Android Sample App

isamirkhaan1
  • 749
  • 7
  • 19