Android: Bulk Insert, when InsertHelper is deprecated

前端 未结 4 622
慢半拍i
慢半拍i 2020-12-07 23:24

There is plenty answers and tutorials using InsertHelper to do fast bulk insert in SQLiteDatabase.
But InsertHelper is deprecated as of API 17.

What is now the f

4条回答
  •  独厮守ぢ
    2020-12-07 23:56

    I was facing the same issue and could not find how SQLiteStatement could easily replace DatabaseUtils.InsertHelper as you need to build the SQL query by hand.

    I ended up using SQLiteDatabase.insertOrThrow which can easily replace existing code. I only had to add sometimes a null column hack to handle cases where I insert empty ContentValues.

    Yes the statement is not compiled to be reused later but building a INSERT query by hand and binding all the parameters is too much pain. I would be interested to know how much this impact performance for large bulk insert data set (InsertHelper is only deprecated) in case you modify your code.

提交回复
热议问题