1

I'm getting this RuntimeException when executing an AsyncTask:

Caused by: android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: INSERT INTO 'infrastructure' (lift,name,type,status,_id) VALUES ('2130837612','none','-','2130837600',0),('2130837612','none','-','2130837600',1),('2130837612','none','-','2130837600',2),('2130837612','none','-','2130837600',3),('2130837612','none','-','2130837600',4),('2130837612','none','-','2130837600',5)

All columns except _id are "text", _id is an integer and primary key.

This is where it crashes:

Cursor curtsr = db.rawQuery("SELECT COUNT(*) FROM 'Infrastructure'", null);
if (curtsr != null) {
    curtsr.moveToFirst();                      // Always one row returned.
    if (curtsr.getInt(0) == 0) {               // Zero count means empty table.
        String INSERT_INFRA_VALUES = "INSERT INTO 'Infrastructure' (lift,name,type,status,_id) VALUES ('2130837612','none','-','2130837600',0),('2130837612','none','-','2130837600',1),('2130837612','none','-','2130837600',2),('2130837612','none','-','2130837600',3),('2130837612','none','-','2130837600',4),('2130837612','none','-','2130837600',5)";
        db.execSQL(INSERT_INFRA_VALUES);
    }
    curtsr.close();
}

I can't find the reason why it's crashing.

Online SQLite lint tool https://sqliteonline.com/ isn't throwing any errors.

2
  • 4
    Do not use single quotes for table and column names. I vote to close such questions as simple typographical errors. Commented Oct 29, 2017 at 13:46
  • @GordonLinoff removing the quotes from the table name doesn't change a single thing. Commented Oct 29, 2017 at 14:02

1 Answer 1

3

Comma-separated multiple VALUES insert was only introduced in sqlite 3.7.11 and chances are you are running on a device with older sqlite version.

Sign up to request clarification or add additional context in comments.

1 Comment

Well, that explains a lot. I'm using API level 15. 3.7.11 is for API 16+

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.