0

I'm trying to copy a row in a SQLite table, but I get a syntax error:

   android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: INSERT INTO tokens(colour, power, ts) SELECT (colour, power, ts) FROM tokens WHERE _id = 1

My query looks like this:

db.execSQL("INSERT INTO " + TABLE_TOKENS + "(" + COLUMN_COLOUR + ", " + COLUMN_POWER + ", " + COLUMN_TS + ")" +
            " SELECT (" + COLUMN_COLOUR + ", " + COLUMN_POWER + ", " + COLUMN_TS + ")" +
            " FROM " + TABLE_TOKENS +
            " WHERE _id = " + id);

For me it looks fine and I guess it wouldn't work without commas...

1 Answers1

1

The select projection is syntactically not correct. Change SELECT (colour, power, ts) to SELECT colour, power, ts.

laalto
  • 150,114
  • 66
  • 286
  • 303
  • I went through many threads regarding copying a row and in every one of them there were these brackets. Can't believe no one pointed that out. It works now, thanks! – Rafał Mądry May 10 '17 at 20:47