elirigobeli
elirigobeli

Reputation: 1421

Maximum number of inserts per transaction

There is a maximum number of values that can be set in an insert statement using transaction?

Example of my Android aplication function:

public void addArray(ArrayList<MyObject> arrData) {

    this.mDb.beginTransaction();

    try {

        for(MyObject obj : arrData){

            ContentValues values = new ContentValues();
            values.put(KEY_ROW_ID, obj.getId());
            values.put(KEY_NAME  , obj.getName());
            values.put(KEY_ICON  , obj.getImage());

            //////// LIMIT HERE ?               
            this.mDb.insert(TABLE, null, values);
        }

        this.mDb.setTransactionSuccessful();

    }
    finally {
        this.mDb.endTransaction();
    }
}

Thanks

Upvotes: 0

Views: 1391

Answers (1)

mvp
mvp

Reputation: 116317

There is no practical limit on number of inserts per transaction.

You will probably hit disk space filling issues before you will see any problems with number of rows in unfinished transaction.

SQLite writes all insert intent into journal or wal file, and it could easily grow into gigabytes.

I have personally tried to insert as many as 100k rows in one transaction, and it was working just fine.

SQLite author D. Richard Hipp even suggests to open transaction upon program start, do whatever you need to do for long time, and only commit when you quit or explicitly save the state. This is basically cheap way to implement undo function - simply rollback current transaction.

Upvotes: 2

Related Questions