Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e0797bb authored by Fyodor Kupolov's avatar Fyodor Kupolov Committed by Android (Google) Code Review
Browse files

Merge "Distinguish ROLLBACK from ROLLBACK TO"

parents 488f1f2e 24929cd4
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1408,6 +1408,12 @@ public class DatabaseUtils {
        } else if (prefixSql.equals("END")) {
            return STATEMENT_COMMIT;
        } else if (prefixSql.equals("ROL")) {
            boolean isRollbackToSavepoint = sql.toUpperCase(Locale.ROOT).contains(" TO ");
            if (isRollbackToSavepoint) {
                Log.w(TAG, "Statement '" + sql
                        + "' may not work on API levels 16-27, use ';" + sql + "' instead");
                return STATEMENT_OTHER;
            }
            return STATEMENT_ABORT;
        } else if (prefixSql.equals("BEG")) {
            return STATEMENT_BEGIN;
+15 −0
Original line number Diff line number Diff line
@@ -1221,4 +1221,19 @@ public class DatabaseGeneralTest extends AndroidTestCase implements PerformanceT
                InstrumentationRegistry.getInstrumentation()).executeShellCommand(cmd);
    }

    @SmallTest
    public void testSavepointRollbacks() {
        try (SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(":memory:", null)) {
            db.execSQL("drop table if exists data");
            db.execSQL("create table if not exists data (id INTEGER PRIMARY KEY, val TEXT)");
            db.execSQL("begin deferred transaction");
            db.execSQL("insert into data (val) values('row 1')");
            db.execSQL("savepoint foo");
            db.execSQL("insert into data (val) values('row 2')");
            db.execSQL("rollback to foo");
            db.execSQL("commit transaction");
            long rowCount = DatabaseUtils.longForQuery(db, "select count(*) from data", null);
            assertEquals(1, rowCount);
        }
    }
}