Android Effectuer une transaction


Les transactions peuvent être utilisées pour apporter plusieurs modifications à la base de données de manière atomique. Toute transaction normale suit ce modèle:

// You need a writable database to perform transactions
final SQLiteDatabase database = openHelper.getWritableDatabase();

// This call starts a transaction

// Using try/finally is essential to reliably end transactions even 
// if exceptions or other problems occur.
try {

    // Here you can make modifications to the database
    database.insert(TABLE_CARS, null, productValues);
    database.update(TABLE_BUILDINGS, buildingValues, COLUMN_ID + " = ?", new String[] { String.valueOf(buildingId) });
    // This call marks a transaction as successful. 
    // This causes the changes to be written to the database once the transaction ends.  
} finally {
    // This call ends a transaction.
    // If setTransactionSuccessful() has not been called then all changes 
    // will be rolled back and the database will not be modified.

L'appel de beginTransaction() intérieur d'une transaction active n'a aucun effet.