Home » Android » android – SQLite too many terms in compound SELECT

android – SQLite too many terms in compound SELECT

Posted by: admin June 16, 2020 Leave a comment

Questions:

In my Android SQLite databese query I have an INSERT INTO statement followed by about 600 (‘data1’),(‘data2’)… tags, generated by code.

After db.exec(sql) I got this error: “too many terms in compound SELECT (code1); while compiling INSERT INTO.. ”

Is there any way to increase this limitation?

How to&Answers:

The limit SQLITE_MAX_COMPOUND_SELECT cannot be raised at runtime,

So you need to split your inserts into batches of 500 rows each. This will be more efficient than inserting one row per query. For e.g.

BEGIN TRANSACTION
INSERT INTO tablename (data1,data2) VALUES ("data1","data2")
INSERT INTO tablename (data1,data2) VALUES ("data1","data2")
INSERT INTO tablename (data1,data2) VALUES ("data1","data2")
...
END TRANSACTION

Also see Insert Multiple Rows in SQLite