Improve INSERT-per-second performance of SQLite

后端 未结 10 2281
忘掉有多难
忘掉有多难 2020-11-21 04:41

Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second!

Background:

10条回答
  •  猫巷女王i
    2020-11-21 05:28

    Use ContentProvider for inserting the bulk data in db. The below method used for inserting bulk data in to database. This should Improve INSERT-per-second performance of SQLite.

    private SQLiteDatabase database;
    database = dbHelper.getWritableDatabase();
    
    public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    
    database.beginTransaction();
    
    for (ContentValues value : values)
     db.insert("TABLE_NAME", null, value);
    
    database.setTransactionSuccessful();
    database.endTransaction();
    
    }
    

    Call bulkInsert method :

    App.getAppContext().getContentResolver().bulkInsert(contentUriTable,
                contentValuesArray);
    

    Link: https://www.vogella.com/tutorials/AndroidSQLite/article.html check Using ContentProvider Section for more details

提交回复
热议问题