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

Commit 19f78acb authored by Lee Shombert's avatar Lee Shombert Committed by Android (Google) Code Review
Browse files

Merge "Make new SQLite APIs public" into main

parents ead086f1 2150b725
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14351,11 +14351,13 @@ package android.database.sqlite {
    method public void execSQL(String, Object[]) throws android.database.SQLException;
    method public static String findEditTable(String);
    method public java.util.List<android.util.Pair<java.lang.String,java.lang.String>> getAttachedDbs();
    method public long getLastChangedRowCount();
    method public long getLastInsertRowId();
    method public long getMaximumSize();
    method public long getPageSize();
    method public String getPath();
    method @Deprecated public java.util.Map<java.lang.String,java.lang.String> getSyncedTables();
    method public long getTotalChangedRowCount();
    method public int getVersion();
    method public boolean inTransaction();
    method public long insert(String, String, android.content.ContentValues);
+2 −2
Original line number Diff line number Diff line
@@ -1875,7 +1875,7 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
     * statement
     * @hide
     */
    long getLastChangedRowsCount() {
    long getLastChangedRowCount() {
        try {
            return nativeChanges(mConnectionPtr);
        } finally {
@@ -1887,7 +1887,7 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
     * Return the total number of database changes made on the current connection.
     * @hide
     */
    long getTotalChangedRowsCount() {
    long getTotalChangedRowCount() {
        try {
            return nativeTotalChanges(mConnectionPtr);
        } finally {
+6 −8
Original line number Diff line number Diff line
@@ -2208,10 +2208,9 @@ public final class SQLiteDatabase extends SQLiteClosable {
     *
     * @return The number of rows changed by the most recent sql statement
     * @throws IllegalStateException if there is no current transaction.
     * @hide
     */
    public long getLastChangedRowsCount() {
        return getThreadSession().getLastChangedRowsCount();
    public long getLastChangedRowCount() {
        return getThreadSession().getLastChangedRowCount();
    }

    /**
@@ -2223,9 +2222,9 @@ public final class SQLiteDatabase extends SQLiteClosable {
     * <code><pre>
     *    database.beginTransaction();
     *    try {
     *        long initialValue = database.getTotalChangedRowsCount();
     *        long initialValue = database.getTotalChangedRowCount();
     *        // Execute SQL statements
     *        long changedRows = database.getTotalChangedRowsCount() - initialValue;
     *        long changedRows = database.getTotalChangedRowCount() - initialValue;
     *        // changedRows counts the total number of rows updated in the transaction.
     *    } finally {
     *        database.endTransaction();
@@ -2236,10 +2235,9 @@ public final class SQLiteDatabase extends SQLiteClosable {
     *
     * @return The number of rows changed on the current connection.
     * @throws IllegalStateException if there is no current transaction.
     * @hide
     */
    public long getTotalChangedRowsCount() {
        return getThreadSession().getTotalChangedRowsCount();
    public long getTotalChangedRowCount() {
        return getThreadSession().getTotalChangedRowCount();
    }

    /**
+4 −4
Original line number Diff line number Diff line
@@ -998,9 +998,9 @@ public final class SQLiteSession {
     * this connection.
     * @hide
     */
    long getLastChangedRowsCount() {
    long getLastChangedRowCount() {
        throwIfNoTransaction();
        return mConnection.getLastChangedRowsCount();
        return mConnection.getLastChangedRowCount();
    }

    /**
@@ -1008,9 +1008,9 @@ public final class SQLiteSession {
     * it was created.
     * @hide
     */
    long getTotalChangedRowsCount() {
    long getTotalChangedRowCount() {
        throwIfNoTransaction();
        return mConnection.getTotalChangedRowsCount();
        return mConnection.getTotalChangedRowCount();
    }

    /**
+21 −4
Original line number Diff line number Diff line
@@ -180,8 +180,8 @@ public class SQLiteDatabaseTest {
                    assertFalse(r);
                    s.reset();
                    assertEquals(i + 1, mDatabase.getLastInsertRowId());
                    assertEquals(1, mDatabase.getLastChangedRowsCount());
                    assertEquals(i + 2, mDatabase.getTotalChangedRowsCount());
                    assertEquals(1, mDatabase.getLastChangedRowCount());
                    assertEquals(i + 2, mDatabase.getTotalChangedRowCount());
                }
            }
            mDatabase.setTransactionSuccessful();
@@ -205,8 +205,8 @@ public class SQLiteDatabaseTest {
                    assertFalse(r);
                    s.reset();
                    assertEquals(size + i + 1, mDatabase.getLastInsertRowId());
                    assertEquals(1, mDatabase.getLastChangedRowsCount());
                    assertEquals(size + i + 2, mDatabase.getTotalChangedRowsCount());
                    assertEquals(1, mDatabase.getLastChangedRowCount());
                    assertEquals(size + i + 2, mDatabase.getTotalChangedRowCount());
                }
            }
            mDatabase.setTransactionSuccessful();
@@ -214,4 +214,21 @@ public class SQLiteDatabaseTest {
            mDatabase.endTransaction();
        }
    }

    @Test
    public void testAutomaticCountersOutsideTransactions() {
        try {
            mDatabase.getLastChangedRowCount();
            fail("getLastChangedRowCount() succeeded outside a transaction");
        } catch (IllegalStateException e) {
            // This exception is expected.
        }

        try {
            mDatabase.getTotalChangedRowCount();
            fail("getTotalChangedRowCount() succeeded outside a transaction");
        } catch (IllegalStateException e) {
            // This exception is expected.
        }
    }
}