diff options
| author | 2024-10-19 15:19:55 -0700 | |
|---|---|---|
| committer | 2024-10-19 15:19:55 -0700 | |
| commit | 3d28d17497beeb52ad1b1892f3a59715da7aee66 (patch) | |
| tree | f2214ce4ddfe0b6a815c73fb021c2087ca88ad04 | |
| parent | 45c4fcbf863fcdbf07e5262ade2c3abe555e446c (diff) | |
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
4 files changed, 6 insertions, 81 deletions
diff --git a/core/java/android/database/DatabaseUtils.java b/core/java/android/database/DatabaseUtils.java index 3c4307c63cf7..0d583dedeb74 100644 --- a/core/java/android/database/DatabaseUtils.java +++ b/core/java/android/database/DatabaseUtils.java @@ -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. @@ -1577,49 +1575,6 @@ public class DatabaseUtils { } /** - * 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; - } + return categorizeStatement(getSqlStatementPrefixExtendedNoRegex(sql), sql); } /** diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java index 914aa51e5314..d77e6280d19c 100644 --- a/core/java/android/database/sqlite/SQLiteConnection.java +++ b/core/java/android/database/sqlite/SQLiteConnection.java @@ -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; - } + 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."); diff --git a/core/java/android/database/sqlite/flags.aconfig b/core/java/android/database/sqlite/flags.aconfig index 285f984faab7..d5a7db82d456 100644 --- a/core/java/android/database/sqlite/flags.aconfig +++ b/core/java/android/database/sqlite/flags.aconfig @@ -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" -} diff --git a/core/tests/coretests/src/android/database/sqlite/SQLiteDatabaseTest.java b/core/tests/coretests/src/android/database/sqlite/SQLiteDatabaseTest.java index 9d477094692a..d5479ea3310d 100644 --- a/core/tests/coretests/src/android/database/sqlite/SQLiteDatabaseTest.java +++ b/core/tests/coretests/src/android/database/sqlite/SQLiteDatabaseTest.java @@ -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; |