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

Commit 3d28d174 authored by Lee Shombert's avatar Lee Shombert
Browse files

Cleanup released sqlite flags

Remove the simple_sql_comment_scanner flag and any code that is
subsequently unreachable.  A few comments have been updated.

Remove the sqlite_allow_temp_tables flag.  Comments have been updated
to remove references to the flagging.

Flag: EXEMPT flag-cleanup
Test: atest
 * FrameworksCoreTests:android.database
 * CtsDatabaseTestCases
Bug: 347726805
Bug: 347725835
Change-Id: I56969e85e780c924a98700875253dd898452a608
parent 45c4fcbf
Loading
Loading
Loading
Loading
+1 −54
Original line number Diff line number Diff line
@@ -48,8 +48,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Static utility methods for dealing with databases and {@link Cursor}s.
@@ -1576,49 +1574,6 @@ public class DatabaseUtils {
        db.close();
    }

    /**
     * The legacy prefix matcher.
     */
    private static String getSqlStatementPrefixSimple(@NonNull String sql) {
        sql = sql.trim();
        if (sql.length() < 3) {
            return null;
        }
        return sql.substring(0, 3).toUpperCase(Locale.ROOT);
    }

    /**
     * A regular expression that matches the first three characters in a SQL statement, after
     * skipping past comments and whitespace.  PREFIX_GROUP_NUM is the regex group that contains
     * the matching prefix string.  If PREFIX_REGEX is changed, PREFIX_GROUP_NUM may require an
     * update too.
     */
    private static final String PREFIX_REGEX =
            "("                                         // Zero-or more...
            + "\\s+"                                    //   Leading space
            + "|"
            + "--.*?\n"                                 //   Line comment
            + "|"
            + "/\\*[\\w\\W]*?\\*/"                      //   Block comment
            + ")*"
            + "(\\w\\w\\w)";                            // Three word-characters
    private static final int PREFIX_GROUP_NUM = 2;
    private static final Pattern sPrefixPattern = Pattern.compile(PREFIX_REGEX);

    /**
     * Return the three-letter prefix of a SQL statement, skipping past whitespace and comments.
     * Comments either start with "--" and run to the end of the line or are C-style block
     * comments.  The function returns null if a prefix could not be found.
     */
    private static String getSqlStatementPrefixExtendedRegex(String sql) {
        Matcher m = sPrefixPattern.matcher(sql);
        if (m.lookingAt()) {
            return m.group(PREFIX_GROUP_NUM).toUpperCase(Locale.ROOT);
        } else {
            return null;
        }
    }

    /**
     * Return the index of the first character past comments and whitespace.  -1 is returned if
     * a comment is malformed.
@@ -1719,15 +1674,7 @@ public class DatabaseUtils {
     * @hide
     */
    public static int getSqlStatementTypeExtended(@NonNull String sql) {
        if (Flags.simpleSqlCommentScanner()) {
      return categorizeStatement(getSqlStatementPrefixExtendedNoRegex(sql), sql);
        } else {
            int type = categorizeStatement(getSqlStatementPrefixSimple(sql), sql);
            if (type == STATEMENT_COMMENT) {
                type = categorizeStatement(getSqlStatementPrefixExtendedRegex(sql), sql);
            }
            return type;
        }
    }

    /**
+5 −10
Original line number Diff line number Diff line
@@ -129,9 +129,6 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
    // Restrict this connection to read-only operations.
    private boolean mOnlyAllowReadOnlyOperations;

    // Allow this connection to treat updates to temporary tables as read-only operations.
    private boolean mAllowTempTableRetry = Flags.sqliteAllowTempTables();

    // The number of times attachCancellationSignal has been called.
    // Because SQLite statement execution can be reentrant, we keep track of how many
    // times we have attempted to attach a cancellation signal to the connection so that
@@ -1281,19 +1278,17 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen

    /**
     * Verify that the statement is read-only, if the connection only allows read-only
     * operations.  If the connection allows updates to temporary tables, then the statement is
     * read-only if the only updates are to temporary tables.
     * operations.  If the statement is not read-only, then check if the statement only modifies
     * temp tables, in which case it is treated the same as a read-only statement and is allowed.
     * @param statement The statement to check.
     * @throws SQLiteException if the statement could update the database inside a read-only
     * transaction.
     */
    void throwIfStatementForbidden(PreparedStatement statement) {
        if (mOnlyAllowReadOnlyOperations && !statement.mReadOnly) {
            if (mAllowTempTableRetry) {
            statement.mReadOnly =
                  nativeUpdatesTempOnly(mConnectionPtr, statement.mStatementPtr);
            if (statement.mReadOnly) return;
            }

            throw new SQLiteException("Cannot execute this statement because it "
                    + "might modify the database but the connection is read-only.");
+0 −16
Original line number Diff line number Diff line
@@ -9,19 +9,3 @@ flag {
     description: "SQLite APIs held back for Android 15"
     bug: "279043253"
}

flag {
     name: "sqlite_allow_temp_tables"
     namespace: "system_performance"
     is_fixed_read_only: true
     description: "Permit updates to TEMP tables in read-only transactions"
     bug: "317993835"
}

flag {
     name: "simple_sql_comment_scanner"
     namespace: "system_performance"
     is_fixed_read_only: true
     description: "Scan SQL comments by hand instead of with a regex"
     bug: "329118560"
}
+0 −1
Original line number Diff line number Diff line
@@ -358,7 +358,6 @@ public class SQLiteDatabaseTest {
        assertTrue("ReadThread failed with errors: " + errors, errors.isEmpty());
    }

    @RequiresFlagsEnabled(Flags.FLAG_SQLITE_ALLOW_TEMP_TABLES)
    @Test
    public void testTempTable() {
        boolean allowed;