Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Comment: | Add the original versions of all the Android files imported and modified in this project. The versions imported are from commit e819e49b31dc0bc82dd617700299ad13ff6fd7f8 on the master branch of the git repository here: https://android.googlesource.com/platform/frameworks/base/ |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | base |
Files: | files | file ages | folders |
SHA1: |
bd482c8af619343fdd0e14ad9989139e |
User & Date: | dan 2017-11-27 20:06:31 |
2017-11-27
| ||
20:21 | Add script to import files from a git checkout. (Leaf check-in: 51cdfe5c9a user: dan tags: base) | |
20:06 | Add the original versions of all the Android files imported and modified in this project. The versions imported are from commit e819e49b31dc0bc82dd617700299ad13ff6fd7f8 on the master branch of the git repository here: https://android.googlesource.com/platform/frameworks/base/ (check-in: bd482c8af6 user: dan tags: base) | |
19:22 | Remove out of date "package.html" files. (check-in: e9352bdf96 user: dan tags: trunk) | |
Changes to sqlite3/src/main/java/org/sqlite/database/DatabaseErrorHandler.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | < | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database; import android.database.sqlite.SQLiteDatabase; /** * An interface to let apps define an action to take when database corruption is detected. */ public interface DatabaseErrorHandler { /** * The method invoked when database corruption is detected. * @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption * is detected. */ void onCorruption(SQLiteDatabase dbObj); } |
Changes to sqlite3/src/main/java/org/sqlite/database/DatabaseUtils.java.
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | | | | | | | | | | < < | < < < | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database; import android.content.ContentValues; import android.content.Context; import android.content.OperationApplicationException; import android.database.sqlite.SQLiteAbortException; import android.database.sqlite.SQLiteConstraintException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabaseCorruptException; import android.database.sqlite.SQLiteDiskIOException; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteFullException; import android.database.sqlite.SQLiteProgram; import android.database.sqlite.SQLiteStatement; import android.os.OperationCanceledException; import android.os.Parcel; import android.os.ParcelFileDescriptor; import android.text.TextUtils; import android.util.Log; import java.io.FileNotFoundException; import java.io.PrintStream; import java.text.Collator; import java.util.HashMap; import java.util.Locale; import java.util.Map; |
︙ | ︙ | |||
129 130 131 132 133 134 135 | * a parcel, to be used after receiving the result of a transaction. This * will throw the exception for you if it had been written to the Parcel, * otherwise return and let you read the normal result data from the Parcel. * @param reply Parcel to read from * @see Parcel#writeNoException * @see Parcel#readException */ | | | | | | > | < | | | | | | | | | > > | < < | | | | | | | | | < < > > | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | * a parcel, to be used after receiving the result of a transaction. This * will throw the exception for you if it had been written to the Parcel, * otherwise return and let you read the normal result data from the Parcel. * @param reply Parcel to read from * @see Parcel#writeNoException * @see Parcel#readException */ public static final void readExceptionFromParcel(Parcel reply) { int code = reply.readExceptionCode(); if (code == 0) return; String msg = reply.readString(); DatabaseUtils.readExceptionFromParcel(reply, msg, code); } public static void readExceptionWithFileNotFoundExceptionFromParcel( Parcel reply) throws FileNotFoundException { int code = reply.readExceptionCode(); if (code == 0) return; String msg = reply.readString(); if (code == 1) { throw new FileNotFoundException(msg); } else { DatabaseUtils.readExceptionFromParcel(reply, msg, code); } } public static void readExceptionWithOperationApplicationExceptionFromParcel( Parcel reply) throws OperationApplicationException { int code = reply.readExceptionCode(); if (code == 0) return; String msg = reply.readString(); if (code == 10) { throw new OperationApplicationException(msg); } else { DatabaseUtils.readExceptionFromParcel(reply, msg, code); } } private static final void readExceptionFromParcel(Parcel reply, String msg, int code) { switch (code) { case 2: throw new IllegalArgumentException(msg); case 3: throw new UnsupportedOperationException(msg); |
︙ | ︙ | |||
1362 1363 1364 1365 1366 1367 1368 | * @param dbVersion the version to set on the db * @param sqlStatements the statements to use to populate the db. This should be a single string * of the form returned by sqlite3's <tt>.dump</tt> command (statements separated by * semicolons) */ static public void createDbFromSqlStatements( Context context, String dbName, int dbVersion, String sqlStatements) { | < < < | < | 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 | * @param dbVersion the version to set on the db * @param sqlStatements the statements to use to populate the db. This should be a single string * of the form returned by sqlite3's <tt>.dump</tt> command (statements separated by * semicolons) */ static public void createDbFromSqlStatements( Context context, String dbName, int dbVersion, String sqlStatements) { SQLiteDatabase db = context.openOrCreateDatabase(dbName, 0, null); // TODO: this is not quite safe since it assumes that all semicolons at the end of a line // terminate statements. It is possible that a text field contains ;\n. We will have to fix // this if that turns out to be a problem. String[] statements = TextUtils.split(sqlStatements, ";\n"); for (String statement : statements) { if (TextUtils.isEmpty(statement)) continue; db.execSQL(statement); |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/DefaultDatabaseErrorHandler.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < < | | | | | | | < < < < | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database; import java.io.File; import java.util.List; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.util.Log; import android.util.Pair; /** * Default class used to define the action to take when database corruption is reported * by sqlite. * <p> * An application can specify an implementation of {@link DatabaseErrorHandler} on the * following: * <ul> * <li>{@link SQLiteDatabase#openOrCreateDatabase(String, * android.database.sqlite.SQLiteDatabase.CursorFactory, DatabaseErrorHandler)}</li> * <li>{@link SQLiteDatabase#openDatabase(String, * android.database.sqlite.SQLiteDatabase.CursorFactory, int, DatabaseErrorHandler)}</li> * </ul> * The specified {@link DatabaseErrorHandler} is used to handle database corruption errors, if they * occur. * <p> * If null is specified for the DatabaseErrorHandler param in the above calls, this class is used * as the default {@link DatabaseErrorHandler}. */ public final class DefaultDatabaseErrorHandler implements DatabaseErrorHandler { private static final String TAG = "DefaultDatabaseErrorHandler"; /** * defines the default method to be invoked when database corruption is detected. * @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption * is detected. */ public void onCorruption(SQLiteDatabase dbObj) { Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath()); // is the corruption detected even before database could be 'opened'? if (!dbObj.isOpen()) { // database files are not even openable. delete this database file. // NOTE if the database has attached databases, then any of them could be corrupt. // and not deleting all of them could cause corrupted database file to remain and // make the application crash on database open operation. To avoid this problem, // the application should provide its own {@link DatabaseErrorHandler} impl class |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/SQLException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database; /** * An exception that indicates there was an error with SQL parsing or execution. */ public class SQLException extends RuntimeException { public SQLException() { } |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/DatabaseObjectNotClosedException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * An exception that indicates that garbage-collector is finalizing a database object * that is not explicitly closed * @hide */ public class DatabaseObjectNotClosedException extends RuntimeException { |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteAbortException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * An exception that indicates that the SQLite program was aborted. * This can happen either through a call to ABORT in a trigger, * or as the result of using the ABORT conflict clause. */ public class SQLiteAbortException extends SQLiteException { |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteAccessPermException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * This exception class is used when sqlite can't access the database file * due to lack of permissions on the file. */ public class SQLiteAccessPermException extends SQLiteException { public SQLiteAccessPermException() {} |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteBindOrColumnIndexOutOfRangeException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * Thrown if the the bind or column parameter index is out of range */ public class SQLiteBindOrColumnIndexOutOfRangeException extends SQLiteException { public SQLiteBindOrColumnIndexOutOfRangeException() {} |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteBlobTooBigException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; public class SQLiteBlobTooBigException extends SQLiteException { public SQLiteBlobTooBigException() {} public SQLiteBlobTooBigException(String error) { super(error); } |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteCantOpenDatabaseException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; public class SQLiteCantOpenDatabaseException extends SQLiteException { public SQLiteCantOpenDatabaseException() {} public SQLiteCantOpenDatabaseException(String error) { super(error); } |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteClosable.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import java.io.Closeable; /** * An object created from a SQLiteDatabase that can be closed. * * This class implements a primitive reference counting scheme for database objects. |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteConnection.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | | | | > > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import dalvik.system.BlockGuard; import dalvik.system.CloseGuard; import android.database.Cursor; import android.database.CursorWindow; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDebug.DbStats; import android.os.CancellationSignal; import android.os.OperationCanceledException; import android.os.ParcelFileDescriptor; import android.os.SystemClock; import android.os.Trace; import android.util.Log; import android.util.LruCache; import android.util.Printer; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; |
︙ | ︙ | |||
91 92 93 94 95 96 97 | public final class SQLiteConnection implements CancellationSignal.OnCancelListener { private static final String TAG = "SQLiteConnection"; private static final boolean DEBUG = false; private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; | < < | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | public final class SQLiteConnection implements CancellationSignal.OnCancelListener { private static final String TAG = "SQLiteConnection"; private static final boolean DEBUG = false; private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; private final CloseGuard mCloseGuard = CloseGuard.get(); private final SQLiteConnectionPool mPool; private final SQLiteDatabaseConfiguration mConfiguration; private final int mConnectionId; private final boolean mIsPrimaryConnection; private final boolean mIsReadOnlyConnection; |
︙ | ︙ | |||
151 152 153 154 155 156 157 | private static native String nativeExecuteForString(long connectionPtr, long statementPtr); private static native int nativeExecuteForBlobFileDescriptor( long connectionPtr, long statementPtr); private static native int nativeExecuteForChangedRowCount(long connectionPtr, long statementPtr); private static native long nativeExecuteForLastInsertedRowId( long connectionPtr, long statementPtr); private static native long nativeExecuteForCursorWindow( | | < < < | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | private static native String nativeExecuteForString(long connectionPtr, long statementPtr); private static native int nativeExecuteForBlobFileDescriptor( long connectionPtr, long statementPtr); private static native int nativeExecuteForChangedRowCount(long connectionPtr, long statementPtr); private static native long nativeExecuteForLastInsertedRowId( long connectionPtr, long statementPtr); private static native long nativeExecuteForCursorWindow( long connectionPtr, long statementPtr, long windowPtr, int startPos, int requiredPos, boolean countAllRows); private static native int nativeGetDbLookaside(long connectionPtr); private static native void nativeCancel(long connectionPtr); private static native void nativeResetCancel(long connectionPtr, boolean cancelable); private SQLiteConnection(SQLiteConnectionPool pool, SQLiteDatabaseConfiguration configuration, int connectionId, boolean primaryConnection) { mPool = pool; mConfiguration = new SQLiteDatabaseConfiguration(configuration); mConnectionId = connectionId; mIsPrimaryConnection = primaryConnection; |
︙ | ︙ | |||
215 216 217 218 219 220 221 222 | private void open() { mConnectionPtr = nativeOpen(mConfiguration.path, mConfiguration.openFlags, mConfiguration.label, SQLiteDebug.DEBUG_SQL_STATEMENTS, SQLiteDebug.DEBUG_SQL_TIME); setPageSize(); setForeignKeyModeFromConfiguration(); setJournalSizeLimit(); | > | < | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | private void open() { mConnectionPtr = nativeOpen(mConfiguration.path, mConfiguration.openFlags, mConfiguration.label, SQLiteDebug.DEBUG_SQL_STATEMENTS, SQLiteDebug.DEBUG_SQL_TIME); setPageSize(); setForeignKeyModeFromConfiguration(); setWalModeFromConfiguration(); setJournalSizeLimit(); setAutoCheckpointInterval(); setLocaleFromConfiguration(); // Register custom functions. final int functionCount = mConfiguration.customFunctions.size(); for (int i = 0; i < functionCount; i++) { SQLiteCustomFunction function = mConfiguration.customFunctions.get(i); nativeRegisterCustomFunction(mConnectionPtr, function); |
︙ | ︙ | |||
398 399 400 401 402 403 404 | } } catch (RuntimeException ex) { throw new SQLiteException("Failed to change locale for db '" + mConfiguration.label + "' to '" + newLocale + "'.", ex); } } | < < < < < < | 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | } } catch (RuntimeException ex) { throw new SQLiteException("Failed to change locale for db '" + mConfiguration.label + "' to '" + newLocale + "'.", ex); } } // Called by SQLiteConnectionPool only. void reconfigure(SQLiteDatabaseConfiguration configuration) { mOnlyAllowReadOnlyOperations = false; // Register custom functions. final int functionCount = configuration.customFunctions.size(); for (int i = 0; i < functionCount; i++) { |
︙ | ︙ | |||
428 429 430 431 432 433 434 | & SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0; boolean localeChanged = !configuration.locale.equals(mConfiguration.locale); // Update configuration parameters. mConfiguration.updateParametersFrom(configuration); // Update prepared statement cache size. | | | 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | & SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0; boolean localeChanged = !configuration.locale.equals(mConfiguration.locale); // Update configuration parameters. mConfiguration.updateParametersFrom(configuration); // Update prepared statement cache size. mPreparedStatementCache.resize(configuration.maxSqlCacheSize); // Update foreign key mode. if (foreignKeyModeChanged) { setForeignKeyModeFromConfiguration(); } // Update WAL. |
︙ | ︙ | |||
852 853 854 855 856 857 858 | try { throwIfStatementForbidden(statement); bindArguments(statement, bindArgs); applyBlockGuardPolicy(statement); attachCancellationSignal(cancellationSignal); try { final long result = nativeExecuteForCursorWindow( | | | 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | try { throwIfStatementForbidden(statement); bindArguments(statement, bindArgs); applyBlockGuardPolicy(statement); attachCancellationSignal(cancellationSignal); try { final long result = nativeExecuteForCursorWindow( mConnectionPtr, statement.mStatementPtr, window.mWindowPtr, startPos, requiredPos, countAllRows); actualPos = (int)(result >> 32); countedRows = (int)result; filledRows = window.getNumRows(); window.setStartPosition(actualPos); return countedRows; } finally { |
︙ | ︙ | |||
1045 1046 1047 1048 1049 1050 1051 | || statementType == DatabaseUtils.STATEMENT_SELECT) { return true; } return false; } private void applyBlockGuardPolicy(PreparedStatement statement) { | | | | | | < < > > | 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | || statementType == DatabaseUtils.STATEMENT_SELECT) { return true; } return false; } private void applyBlockGuardPolicy(PreparedStatement statement) { if (!mConfiguration.isInMemoryDb()) { if (statement.mReadOnly) { BlockGuard.getThreadPolicy().onReadFromDisk(); } else { BlockGuard.getThreadPolicy().onWriteToDisk(); } } } /** * Dumps debugging information about this connection. * * @param printer The printer to receive the dump, not null. * @param verbose True to dump more verbose information. |
︙ | ︙ | |||
1212 1213 1214 1215 1216 1217 1218 | private void recyclePreparedStatement(PreparedStatement statement) { statement.mSql = null; statement.mPoolNext = mPreparedStatementPool; mPreparedStatementPool = statement; } private static String trimSqlForDisplay(String sql) { | > > > > | | 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 | private void recyclePreparedStatement(PreparedStatement statement) { statement.mSql = null; statement.mPoolNext = mPreparedStatementPool; mPreparedStatementPool = statement; } private static String trimSqlForDisplay(String sql) { // Note: Creating and caching a regular expression is expensive at preload-time // and stops compile-time initialization. This pattern is only used when // dumping the connection, which is a rare (mainly error) case. So: // DO NOT CACHE. return sql.replaceAll("[\\s]*\\n+[\\s]*", " "); } /** * Holder type for a prepared statement. * * Although this object holds a pointer to a native statement object, it * does not have a finalizer. This is deliberate. The {@link SQLiteConnection} |
︙ | ︙ | |||
1317 1318 1319 1320 1321 1322 1323 | } else { operation.mFinished = false; operation.mException = null; if (operation.mBindArgs != null) { operation.mBindArgs.clear(); } } | > | > > > > | 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 | } else { operation.mFinished = false; operation.mException = null; if (operation.mBindArgs != null) { operation.mBindArgs.clear(); } } operation.mStartWallTime = System.currentTimeMillis(); operation.mStartTime = SystemClock.uptimeMillis(); operation.mKind = kind; operation.mSql = sql; if (bindArgs != null) { if (operation.mBindArgs == null) { operation.mBindArgs = new ArrayList<Object>(); } else { operation.mBindArgs.clear(); } for (int i = 0; i < bindArgs.length; i++) { final Object arg = bindArgs[i]; if (arg != null && arg instanceof byte[]) { // Don't hold onto the real byte array longer than necessary. operation.mBindArgs.add(EMPTY_BYTE_ARRAY); } else { operation.mBindArgs.add(arg); } } } operation.mCookie = newOperationCookieLocked(index); if (Trace.isTagEnabled(Trace.TRACE_TAG_DATABASE)) { Trace.asyncTraceBegin(Trace.TRACE_TAG_DATABASE, operation.getTraceMethodName(), operation.mCookie); } mIndex = index; return operation.mCookie; } } public void failOperation(int cookie, Exception ex) { synchronized (mOperations) { |
︙ | ︙ | |||
1374 1375 1376 1377 1378 1379 1380 | logOperationLocked(cookie, detail); } } private boolean endOperationDeferLogLocked(int cookie) { final Operation operation = getOperationLocked(cookie); if (operation != null) { | > > > > | | 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 | logOperationLocked(cookie, detail); } } private boolean endOperationDeferLogLocked(int cookie) { final Operation operation = getOperationLocked(cookie); if (operation != null) { if (Trace.isTagEnabled(Trace.TRACE_TAG_DATABASE)) { Trace.asyncTraceEnd(Trace.TRACE_TAG_DATABASE, operation.getTraceMethodName(), operation.mCookie); } operation.mEndTime = SystemClock.uptimeMillis(); operation.mFinished = true; return SQLiteDebug.DEBUG_LOG_SLOW_QUERIES && SQLiteDebug.shouldLogSlowQuery( operation.mEndTime - operation.mStartTime); } return false; } |
︙ | ︙ | |||
1446 1447 1448 1449 1450 1451 1452 | printer.println(" <none>"); } } } } private static final class Operation { | > > > > | < > | | | | 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 | printer.println(" <none>"); } } } } private static final class Operation { // Trim all SQL statements to 256 characters inside the trace marker. // This limit gives plenty of context while leaving space for other // entries in the trace buffer (and ensures atrace doesn't truncate the // marker for us, potentially losing metadata in the process). private static final int MAX_TRACE_METHOD_NAME_LEN = 256; public long mStartWallTime; // in System.currentTimeMillis() public long mStartTime; // in SystemClock.uptimeMillis(); public long mEndTime; // in SystemClock.uptimeMillis(); public String mKind; public String mSql; public ArrayList<Object> mBindArgs; public boolean mFinished; public Exception mException; public int mCookie; public void describe(StringBuilder msg, boolean verbose) { msg.append(mKind); if (mFinished) { msg.append(" took ").append(mEndTime - mStartTime).append("ms"); } else { msg.append(" started ").append(System.currentTimeMillis() - mStartWallTime) .append("ms ago"); } msg.append(" - ").append(getStatus()); if (mSql != null) { msg.append(", sql=\"").append(trimSqlForDisplay(mSql)).append("\""); } if (verbose && mBindArgs != null && mBindArgs.size() != 0) { |
︙ | ︙ | |||
1501 1502 1503 1504 1505 1506 1507 1508 1509 | private String getStatus() { if (!mFinished) { return "running"; } return mException != null ? "failed" : "succeeded"; } private String getFormattedStartTime() { | > > > > > > > > > > > | | 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 | private String getStatus() { if (!mFinished) { return "running"; } return mException != null ? "failed" : "succeeded"; } private String getTraceMethodName() { String methodName = mKind + " " + mSql; if (methodName.length() > MAX_TRACE_METHOD_NAME_LEN) return methodName.substring(0, MAX_TRACE_METHOD_NAME_LEN); return methodName; } private String getFormattedStartTime() { // Note: SimpleDateFormat is not thread-safe, cannot be compile-time created, and is // relatively expensive to create during preloading. This method is only used // when dumping a connection, which is a rare (mainly error) case. So: // DO NOT CACHE. return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(mStartWallTime)); } } } |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteConnectionPool.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import dalvik.system.CloseGuard; import android.database.sqlite.SQLiteDebug.DbStats; import android.os.CancellationSignal; import android.os.OperationCanceledException; import android.os.SystemClock; import android.util.Log; import android.util.PrefixPrinter; import android.util.Printer; import java.io.Closeable; import java.util.ArrayList; import java.util.Map; import java.util.WeakHashMap; import java.util.concurrent.atomic.AtomicBoolean; |
︙ | ︙ | |||
992 993 994 995 996 997 998 | waiter.mSql = null; waiter.mAssignedConnection = null; waiter.mException = null; waiter.mNonce += 1; mConnectionWaiterPool = waiter; } | < < < < < < < < < < < < | | 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | waiter.mSql = null; waiter.mAssignedConnection = null; waiter.mException = null; waiter.mNonce += 1; mConnectionWaiterPool = waiter; } /** * Dumps debugging information about this connection pool. * * @param printer The printer to receive the dump, not null. * @param verbose True to dump more verbose information. */ public void dump(Printer printer, boolean verbose) { Printer indentedPrinter = PrefixPrinter.create(printer, " "); synchronized (mLock) { printer.println("Connection pool for " + mConfiguration.path + ":"); printer.println(" Open: " + mIsOpen); printer.println(" Max connections: " + mMaxConnectionPoolSize); printer.println(" Available primary connection:"); if (mAvailablePrimaryConnection != null) { |
︙ | ︙ | |||
1062 1063 1064 1065 1066 1067 1068 | + ", priority=" + waiter.mPriority + ", sql='" + waiter.mSql + "'"); } } else { indentedPrinter.println("<none>"); } } | < | 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 | + ", priority=" + waiter.mPriority + ", sql='" + waiter.mSql + "'"); } } else { indentedPrinter.println("<none>"); } } } @Override public String toString() { return "SQLiteConnectionPool: " + mConfiguration.path; } |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteConstraintException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * An exception that indicates that an integrity constraint was violated. */ public class SQLiteConstraintException extends SQLiteException { public SQLiteConstraintException() {} |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteCursor.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.database.AbstractWindowedCursor; import android.database.CursorWindow; import android.database.DatabaseUtils; import android.os.StrictMode; import android.util.Log; import java.util.HashMap; import java.util.Map; /** |
︙ | ︙ | |||
96 97 98 99 100 101 102 | * @param editTable the name of the table used for this query * @param query the {@link SQLiteQuery} object associated with this cursor object. */ public SQLiteCursor(SQLiteCursorDriver driver, String editTable, SQLiteQuery query) { if (query == null) { throw new IllegalArgumentException("query object cannot be null"); } | | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | * @param editTable the name of the table used for this query * @param query the {@link SQLiteQuery} object associated with this cursor object. */ public SQLiteCursor(SQLiteCursorDriver driver, String editTable, SQLiteQuery query) { if (query == null) { throw new IllegalArgumentException("query object cannot be null"); } if (StrictMode.vmSqliteObjectLeaksEnabled()) { mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace(); } else { mStackTrace = null; } mDriver = driver; mEditTable = editTable; mColumnNameMap = null; |
︙ | ︙ | |||
136 137 138 139 140 141 142 | public int getCount() { if (mCount == NO_COUNT) { fillWindow(0); } return mCount; } | < < < < < < < < < < < < < < < < < < < | | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | public int getCount() { if (mCount == NO_COUNT) { fillWindow(0); } return mCount; } private void fillWindow(int requiredPos) { clearOrCreateWindow(getDatabase().getPath()); try { if (mCount == NO_COUNT) { int startPos = DatabaseUtils.cursorPickFillWindowStartPosition(requiredPos, 0); mCount = mQuery.fillWindow(mWindow, startPos, requiredPos, true); mCursorWindowCapacity = mWindow.getNumRows(); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "received count(*) from native_fill_window: " + mCount); } } else { int startPos = DatabaseUtils.cursorPickFillWindowStartPosition(requiredPos, mCursorWindowCapacity); mQuery.fillWindow(mWindow, startPos, requiredPos, false); } } catch (RuntimeException ex) { // Close the cursor window if the query failed and therefore will // not produce any results. This helps to avoid accidentally leaking // the cursor window if the client does not correctly handle exceptions // and fails to close the cursor. closeWindow(); throw ex; } } @Override public int getColumnIndex(String columnName) { // Create mColumnNameMap on demand |
︙ | ︙ | |||
280 281 282 283 284 285 286 | * Release the native resources, if they haven't been released yet. */ @Override protected void finalize() { try { // if the cursor hasn't been closed yet, close it first if (mWindow != null) { | < < | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | * Release the native resources, if they haven't been released yet. */ @Override protected void finalize() { try { // if the cursor hasn't been closed yet, close it first if (mWindow != null) { if (mStackTrace != null) { String sql = mQuery.getSql(); int len = sql.length(); StrictMode.onSqliteObjectLeaked( "Finalizing a Cursor that has not been deactivated or closed. " + "database = " + mQuery.getDatabase().getLabel() + ", table = " + mEditTable + ", query = " + sql.substring(0, (len > 1000) ? 1000 : len), mStackTrace); } close(); } } finally { super.finalize(); } } } |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteCursorDriver.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase.CursorFactory; /** * A driver for SQLiteCursors that is used to create them and gets notified * by the cursors it creates on significant events in their lifetimes. */ public interface SQLiteCursorDriver { /** |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteCustomFunction.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * Describes a custom SQL function. * * @hide */ public final class SQLiteCustomFunction { |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDatabase.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | > > | | | | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.ContentValues; import android.database.Cursor; import android.database.DatabaseErrorHandler; import android.database.DatabaseUtils; import android.database.DefaultDatabaseErrorHandler; import android.database.SQLException; import android.database.sqlite.SQLiteDebug.DbStats; import android.os.CancellationSignal; import android.os.Looper; import android.os.OperationCanceledException; import android.text.TextUtils; import android.util.EventLog; import android.util.Log; import android.util.Pair; import android.util.Printer; import dalvik.system.CloseGuard; import java.io.File; import java.io.FileFilter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; |
︙ | ︙ | |||
738 739 740 741 742 743 744 | deleted |= new File(file.getPath() + "-journal").delete(); deleted |= new File(file.getPath() + "-shm").delete(); deleted |= new File(file.getPath() + "-wal").delete(); File dir = file.getParentFile(); if (dir != null) { final String prefix = file.getName() + "-mj"; | | | > | | > | 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 | deleted |= new File(file.getPath() + "-journal").delete(); deleted |= new File(file.getPath() + "-shm").delete(); deleted |= new File(file.getPath() + "-wal").delete(); File dir = file.getParentFile(); if (dir != null) { final String prefix = file.getName() + "-mj"; File[] files = dir.listFiles(new FileFilter() { @Override public boolean accept(File candidate) { return candidate.getName().startsWith(prefix); } }); if (files != null) { for (File masterJournal : files) { deleted |= masterJournal.delete(); } } } return deleted; } /** * Reopens the database in read-write mode. |
︙ | ︙ | |||
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 | public long insertOrThrow(String table, String nullColumnHack, ContentValues values) throws SQLException { return insertWithOnConflict(table, nullColumnHack, values, CONFLICT_NONE); } /** * Convenience method for replacing a row in the database. * * @param table the table in which to replace the row * @param nullColumnHack optional; may be <code>null</code>. * SQL doesn't allow inserting a completely empty row without * naming at least one column name. If your provided <code>initialValues</code> is * empty, no column names are known and an empty row can't be inserted. * If not set to null, the <code>nullColumnHack</code> parameter * provides the name of nullable column name to explicitly insert a NULL into * in the case where your <code>initialValues</code> is empty. * @param initialValues this map contains the initial column values for | > | > | | 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 | public long insertOrThrow(String table, String nullColumnHack, ContentValues values) throws SQLException { return insertWithOnConflict(table, nullColumnHack, values, CONFLICT_NONE); } /** * Convenience method for replacing a row in the database. * Inserts a new row if a row does not already exist. * * @param table the table in which to replace the row * @param nullColumnHack optional; may be <code>null</code>. * SQL doesn't allow inserting a completely empty row without * naming at least one column name. If your provided <code>initialValues</code> is * empty, no column names are known and an empty row can't be inserted. * If not set to null, the <code>nullColumnHack</code> parameter * provides the name of nullable column name to explicitly insert a NULL into * in the case where your <code>initialValues</code> is empty. * @param initialValues this map contains the initial column values for * the row. The keys should be the column names and the values the column values. * @return the row ID of the newly inserted row, or -1 if an error occurred */ public long replace(String table, String nullColumnHack, ContentValues initialValues) { try { return insertWithOnConflict(table, nullColumnHack, initialValues, CONFLICT_REPLACE); } catch (SQLException e) { Log.e(TAG, "Error inserting " + initialValues, e); return -1; } } /** * Convenience method for replacing a row in the database. * Inserts a new row if a row does not already exist. * * @param table the table in which to replace the row * @param nullColumnHack optional; may be <code>null</code>. * SQL doesn't allow inserting a completely empty row without * naming at least one column name. If your provided <code>initialValues</code> is * empty, no column names are known and an empty row can't be inserted. * If not set to null, the <code>nullColumnHack</code> parameter * provides the name of nullable column name to explicitly insert a NULL into * in the case where your <code>initialValues</code> is empty. * @param initialValues this map contains the initial column values for * the row. The keys should be the column names and the values the column values. * @throws SQLException * @return the row ID of the newly inserted row, or -1 if an error occurred */ public long replaceOrThrow(String table, String nullColumnHack, ContentValues initialValues) throws SQLException { return insertWithOnConflict(table, nullColumnHack, initialValues, CONFLICT_REPLACE); |
︙ | ︙ | |||
1427 1428 1429 1430 1431 1432 1433 | * If not set to null, the <code>nullColumnHack</code> parameter * provides the name of nullable column name to explicitly insert a NULL into * in the case where your <code>initialValues</code> is empty. * @param initialValues this map contains the initial column values for the * row. The keys should be the column names and the values the * column values * @param conflictAlgorithm for insert conflict resolver | | < | | | | 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 | * If not set to null, the <code>nullColumnHack</code> parameter * provides the name of nullable column name to explicitly insert a NULL into * in the case where your <code>initialValues</code> is empty. * @param initialValues this map contains the initial column values for the * row. The keys should be the column names and the values the * column values * @param conflictAlgorithm for insert conflict resolver * @return the row ID of the newly inserted row OR <code>-1</code> if either the * input parameter <code>conflictAlgorithm</code> = {@link #CONFLICT_IGNORE} * or an error occurred. */ public long insertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues, int conflictAlgorithm) { acquireReference(); try { StringBuilder sql = new StringBuilder(); sql.append("INSERT"); sql.append(CONFLICT_VALUES[conflictAlgorithm]); sql.append(" INTO "); sql.append(table); sql.append('('); Object[] bindArgs = null; int size = (initialValues != null && !initialValues.isEmpty()) ? initialValues.size() : 0; if (size > 0) { bindArgs = new Object[size]; int i = 0; for (String colName : initialValues.keySet()) { sql.append((i > 0) ? "," : ""); sql.append(colName); |
︙ | ︙ | |||
1536 1537 1538 1539 1540 1541 1542 | * will be replaced by the values from whereArgs. The values * will be bound as Strings. * @param conflictAlgorithm for update conflict resolver * @return the number of rows affected */ public int updateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs, int conflictAlgorithm) { | | | 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 | * will be replaced by the values from whereArgs. The values * will be bound as Strings. * @param conflictAlgorithm for update conflict resolver * @return the number of rows affected */ public int updateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs, int conflictAlgorithm) { if (values == null || values.isEmpty()) { throw new IllegalArgumentException("Empty values"); } acquireReference(); try { StringBuilder sql = new StringBuilder(120); sql.append("UPDATE "); |
︙ | ︙ | |||
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 | } finally { statement.close(); } } finally { releaseReference(); } } /** * Returns true if the database is opened as read only. * * @return True if database is opened as read only. */ public boolean isReadOnly() { | > > > > > > > > > > > > > > > | 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 | } finally { statement.close(); } } finally { releaseReference(); } } /** * Verifies that a SQL SELECT statement is valid by compiling it. * If the SQL statement is not valid, this method will throw a {@link SQLiteException}. * * @param sql SQL to be validated * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * If the operation is canceled, then {@link OperationCanceledException} will be thrown * when the query is executed. * @throws SQLiteException if {@code sql} is invalid */ public void validateSql(@NonNull String sql, @Nullable CancellationSignal cancellationSignal) { getThreadSession().prepare(sql, getThreadDefaultConnectionFlags(/* readOnly =*/ true), cancellationSignal, null); } /** * Returns true if the database is opened as read only. * * @return True if database is opened as read only. */ public boolean isReadOnly() { |
︙ | ︙ | |||
1722 1723 1724 1725 1726 1727 1728 | } } /** * Returns true if the new version code is greater than the current database version. * * @param newVersion The new version code. | | | 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 | } } /** * Returns true if the new version code is greater than the current database version. * * @param newVersion The new version code. * @return True if the new version code is greater than the current database version. */ public boolean needUpgrade(int newVersion) { return newVersion > getVersion(); } /** * Gets the path to the database file. |
︙ | ︙ | |||
2190 2191 2192 2193 2194 2195 2196 | * This can be used to create a function that can be called from * sqlite3 database triggers. * @hide */ public interface CustomFunction { public void callback(String[] args); } | | < < < < < < < < | 2206 2207 2208 2209 2210 2211 2212 2213 | * This can be used to create a function that can be called from * sqlite3 database triggers. * @hide */ public interface CustomFunction { public void callback(String[] args); } } |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDatabaseConfiguration.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import java.util.ArrayList; import java.util.Locale; import java.util.regex.Pattern; /** * Describes how to configure a database. |
︙ | ︙ | |||
157 158 159 160 161 162 163 | * @return True if the database is in-memory. */ public boolean isInMemoryDb() { return path.equalsIgnoreCase(MEMORY_DB_PATH); } private static String stripPathForLogs(String path) { | < < < < < < | 153 154 155 156 157 158 159 160 161 162 163 164 165 | * @return True if the database is in-memory. */ public boolean isInMemoryDb() { return path.equalsIgnoreCase(MEMORY_DB_PATH); } private static String stripPathForLogs(String path) { if (path.indexOf('@') == -1) { return path; } return EMAIL_IN_DB_PATTERN.matcher(path).replaceAll("XX@YY"); } } |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDatabaseCorruptException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * An exception that indicates that the SQLite database file is corrupt. */ public class SQLiteDatabaseCorruptException extends SQLiteException { public SQLiteDatabaseCorruptException() {} |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDatabaseLockedException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * Thrown if the database engine was unable to acquire the * database locks it needs to do its job. If the statement is a [COMMIT] * or occurs outside of an explicit transaction, then you can retry the * statement. If the statement is not a [COMMIT] and occurs within a * explicit transaction then you should rollback the transaction before |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDatatypeMismatchException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; public class SQLiteDatatypeMismatchException extends SQLiteException { public SQLiteDatatypeMismatchException() {} public SQLiteDatatypeMismatchException(String error) { super(error); } |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDebug.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import java.util.ArrayList; import android.os.Build; import android.os.SystemProperties; import android.util.Log; import android.util.Printer; /** * Provides debugging info about all SQLite databases running in the current process. * * {@hide} |
︙ | ︙ | |||
60 61 62 63 64 65 66 | public static final boolean DEBUG_SQL_TIME = Log.isLoggable("SQLiteTime", Log.VERBOSE); /** * True to enable database performance testing instrumentation. * @hide */ | | | | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | public static final boolean DEBUG_SQL_TIME = Log.isLoggable("SQLiteTime", Log.VERBOSE); /** * True to enable database performance testing instrumentation. * @hide */ public static final boolean DEBUG_LOG_SLOW_QUERIES = Build.IS_DEBUGGABLE; private SQLiteDebug() { } /** * Determines whether a query should be logged. * * Reads the "db.log.slow_query_threshold" system property, which can be changed * by the user at any time. If the value is zero, then all queries will * be considered slow. If the value does not exist or is negative, then no queries will * be considered slow. * * This value can be changed dynamically while the system is running. * For example, "adb shell setprop db.log.slow_query_threshold 200" will * log all queries that take 200ms or longer to run. * @hide */ public static final boolean shouldLogSlowQuery(long elapsedTimeMillis) { int slowQueryMillis = SystemProperties.getInt("db.log.slow_query_threshold", -1); return slowQueryMillis >= 0 && elapsedTimeMillis >= slowQueryMillis; } /** * Contains statistics about the active pagers in the current process. * * @see #nativeGetPagerStats(PagerStats) |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDirectCursorDriver.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.os.CancellationSignal; /** * A cursor driver that uses the given query directly. * * @hide */ |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDiskIOException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * An exception that indicates that an IO error occured while accessing the * SQLite database file. */ public class SQLiteDiskIOException extends SQLiteException { public SQLiteDiskIOException() {} |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDoneException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * An exception that indicates that the SQLite program is done. * Thrown when an operation that expects a row (such as {@link * SQLiteStatement#simpleQueryForString} or {@link * SQLiteStatement#simpleQueryForLong}) does not get one. */ |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.database.SQLException; /** * A SQLite exception that indicates there was an error with SQL parsing or execution. */ public class SQLiteException extends SQLException { public SQLiteException() { } |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteFullException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * An exception that indicates that the SQLite database is full. */ public class SQLiteFullException extends SQLiteException { public SQLiteFullException() {} |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteGlobal.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.content.res.Resources; import android.os.StatFs; import android.os.SystemProperties; /** * Provides access to SQLite functions that affect all database connection, * such as memory management. * * The native code associated with SQLiteGlobal is also sets global configuration options * using sqlite3_config() then calls sqlite3_initialize() to ensure that the SQLite |
︙ | ︙ | |||
61 62 63 64 65 66 67 68 69 | /** * Gets the default page size to use when creating a database. */ public static int getDefaultPageSize() { synchronized (sLock) { if (sDefaultPageSize == 0) { sDefaultPageSize = new StatFs("/data").getBlockSize(); } | > > | | > > | > > | > > | > > | > > | > > | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | /** * Gets the default page size to use when creating a database. */ public static int getDefaultPageSize() { synchronized (sLock) { if (sDefaultPageSize == 0) { // If there is an issue accessing /data, something is so seriously // wrong that we just let the IllegalArgumentException propagate. sDefaultPageSize = new StatFs("/data").getBlockSize(); } return SystemProperties.getInt("debug.sqlite.pagesize", sDefaultPageSize); } } /** * Gets the default journal mode when WAL is not in use. */ public static String getDefaultJournalMode() { return SystemProperties.get("debug.sqlite.journalmode", Resources.getSystem().getString( com.android.internal.R.string.db_default_journal_mode)); } /** * Gets the journal size limit in bytes. */ public static int getJournalSizeLimit() { return SystemProperties.getInt("debug.sqlite.journalsizelimit", Resources.getSystem().getInteger( com.android.internal.R.integer.db_journal_size_limit)); } /** * Gets the default database synchronization mode when WAL is not in use. */ public static String getDefaultSyncMode() { return SystemProperties.get("debug.sqlite.syncmode", Resources.getSystem().getString( com.android.internal.R.string.db_default_sync_mode)); } /** * Gets the database synchronization mode when in WAL mode. */ public static String getWALSyncMode() { return SystemProperties.get("debug.sqlite.wal.syncmode", Resources.getSystem().getString( com.android.internal.R.string.db_wal_sync_mode)); } /** * Gets the WAL auto-checkpoint integer in database pages. */ public static int getWALAutoCheckpoint() { int value = SystemProperties.getInt("debug.sqlite.wal.autocheckpoint", Resources.getSystem().getInteger( com.android.internal.R.integer.db_wal_autocheckpoint)); return Math.max(1, value); } /** * Gets the connection pool size when in WAL mode. */ public static int getWALConnectionPoolSize() { int value = SystemProperties.getInt("debug.sqlite.wal.poolsize", Resources.getSystem().getInteger( com.android.internal.R.integer.db_connection_pool_size)); return Math.max(2, value); } } |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteMisuseException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * This error can occur if the application creates a SQLiteStatement object and allows multiple * threads in the application use it at the same time. * Sqlite returns this error if bind and execute methods on this object occur at the same time * from multiple threads, like so: * thread # 1: in execute() method of the SQLiteStatement object |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteOpenHelper.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | < | > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.content.Context; import android.database.DatabaseErrorHandler; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.util.Log; import java.io.File; /** * A helper class to manage database creation and version management. * * <p>You create a subclass implementing {@link #onCreate}, {@link #onUpgrade} and * optionally {@link #onOpen}, and this class takes care of opening the database * if it exists, creating it if it does not, and upgrading it as necessary. |
︙ | ︙ | |||
55 56 57 58 59 60 61 62 63 64 65 66 67 68 | // wanted getWritableDatabase. private static final boolean DEBUG_STRICT_READONLY = false; private final Context mContext; private final String mName; private final CursorFactory mFactory; private final int mNewVersion; private SQLiteDatabase mDatabase; private boolean mIsInitializing; private boolean mEnableWriteAheadLogging; private final DatabaseErrorHandler mErrorHandler; /** | > | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | // wanted getWritableDatabase. private static final boolean DEBUG_STRICT_READONLY = false; private final Context mContext; private final String mName; private final CursorFactory mFactory; private final int mNewVersion; private final int mMinimumSupportedVersion; private SQLiteDatabase mDatabase; private boolean mIsInitializing; private boolean mEnableWriteAheadLogging; private final DatabaseErrorHandler mErrorHandler; /** |
︙ | ︙ | |||
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | * {@link #onUpgrade} will be used to upgrade the database; if the database is * newer, {@link #onDowngrade} will be used to downgrade the database * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database * corruption, or null to use the default error handler. */ public SQLiteOpenHelper(Context context, String name, CursorFactory factory, int version, DatabaseErrorHandler errorHandler) { if (version < 1) throw new IllegalArgumentException("Version must be >= 1, was " + version); mContext = context; mName = name; mFactory = factory; mNewVersion = version; mErrorHandler = errorHandler; } /** * Return the name of the SQLite database being opened, as given to * the constructor. */ public String getDatabaseName() { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | * {@link #onUpgrade} will be used to upgrade the database; if the database is * newer, {@link #onDowngrade} will be used to downgrade the database * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database * corruption, or null to use the default error handler. */ public SQLiteOpenHelper(Context context, String name, CursorFactory factory, int version, DatabaseErrorHandler errorHandler) { this(context, name, factory, version, 0, errorHandler); } /** * Same as {@link #SQLiteOpenHelper(Context, String, CursorFactory, int, DatabaseErrorHandler)} * but also accepts an integer minimumSupportedVersion as a convenience for upgrading very old * versions of this database that are no longer supported. If a database with older version that * minimumSupportedVersion is found, it is simply deleted and a new database is created with the * given name and version * * @param context to use to open or create the database * @param name the name of the database file, null for a temporary in-memory database * @param factory to use for creating cursor objects, null for default * @param version the required version of the database * @param minimumSupportedVersion the minimum version that is supported to be upgraded to * {@code version} via {@link #onUpgrade}. If the current database version is lower * than this, database is simply deleted and recreated with the version passed in * {@code version}. {@link #onBeforeDelete} is called before deleting the database * when this happens. This is 0 by default. * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database * corruption, or null to use the default error handler. * @see #onBeforeDelete(SQLiteDatabase) * @see #SQLiteOpenHelper(Context, String, CursorFactory, int, DatabaseErrorHandler) * @see #onUpgrade(SQLiteDatabase, int, int) * @hide */ public SQLiteOpenHelper(Context context, String name, CursorFactory factory, int version, int minimumSupportedVersion, DatabaseErrorHandler errorHandler) { if (version < 1) throw new IllegalArgumentException("Version must be >= 1, was " + version); mContext = context; mName = name; mFactory = factory; mNewVersion = version; mErrorHandler = errorHandler; mMinimumSupportedVersion = Math.max(0, minimumSupportedVersion); } /** * Return the name of the SQLite database being opened, as given to * the constructor. */ public String getDatabaseName() { |
︙ | ︙ | |||
221 222 223 224 225 226 227 | } else { try { if (DEBUG_STRICT_READONLY && !writable) { final String path = mContext.getDatabasePath(mName).getPath(); db = SQLiteDatabase.openDatabase(path, mFactory, SQLiteDatabase.OPEN_READONLY, mErrorHandler); } else { | | > | < | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | } else { try { if (DEBUG_STRICT_READONLY && !writable) { final String path = mContext.getDatabasePath(mName).getPath(); db = SQLiteDatabase.openDatabase(path, mFactory, SQLiteDatabase.OPEN_READONLY, mErrorHandler); } else { db = mContext.openOrCreateDatabase(mName, mEnableWriteAheadLogging ? Context.MODE_ENABLE_WRITE_AHEAD_LOGGING : 0, mFactory, mErrorHandler); } } catch (SQLiteException ex) { if (writable) { throw ex; } Log.e(TAG, "Couldn't open " + mName + " for writing (will try read-only):", ex); |
︙ | ︙ | |||
246 247 248 249 250 251 252 | final int version = db.getVersion(); if (version != mNewVersion) { if (db.isReadOnly()) { throw new SQLiteException("Can't upgrade read-only database from version " + db.getVersion() + " to " + mNewVersion + ": " + mName); } | > > > > > > > > > > > > | | | | | | | | | | | | | | | > | 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | final int version = db.getVersion(); if (version != mNewVersion) { if (db.isReadOnly()) { throw new SQLiteException("Can't upgrade read-only database from version " + db.getVersion() + " to " + mNewVersion + ": " + mName); } if (version > 0 && version < mMinimumSupportedVersion) { File databaseFile = new File(db.getPath()); onBeforeDelete(db); db.close(); if (SQLiteDatabase.deleteDatabase(databaseFile)) { mIsInitializing = false; return getDatabaseLocked(writable); } else { throw new IllegalStateException("Unable to delete obsolete database " + mName + " with version " + version); } } else { db.beginTransaction(); try { if (version == 0) { onCreate(db); } else { if (version > mNewVersion) { onDowngrade(db, version, mNewVersion); } else { onUpgrade(db, version, mNewVersion); } } db.setVersion(mNewVersion); db.setTransactionSuccessful(); } finally { db.endTransaction(); } } } onOpen(db); if (db.isReadOnly()) { Log.w(TAG, "Opened " + mName + " in read-only mode"); |
︙ | ︙ | |||
293 294 295 296 297 298 299 | if (mDatabase != null && mDatabase.isOpen()) { mDatabase.close(); mDatabase = null; } } /** | | | | | | | > | | | < | > > > > > > > > > > > > > > | 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | if (mDatabase != null && mDatabase.isOpen()) { mDatabase.close(); mDatabase = null; } } /** * Called when the database connection is being configured, to enable features such as * write-ahead logging or foreign key support. * <p> * This method is called before {@link #onCreate}, {@link #onUpgrade}, {@link #onDowngrade}, or * {@link #onOpen} are called. It should not modify the database except to configure the * database connection as required. * </p> * <p> * This method should only call methods that configure the parameters of the database * connection, such as {@link SQLiteDatabase#enableWriteAheadLogging} * {@link SQLiteDatabase#setForeignKeyConstraintsEnabled}, {@link SQLiteDatabase#setLocale}, * {@link SQLiteDatabase#setMaximumSize}, or executing PRAGMA statements. * </p> * * @param db The database. */ public void onConfigure(SQLiteDatabase db) {} /** * Called before the database is deleted when the version returned by * {@link SQLiteDatabase#getVersion()} is lower than the minimum supported version passed (if at * all) while creating this helper. After the database is deleted, a fresh database with the * given version is created. This will be followed by {@link #onConfigure(SQLiteDatabase)} and * {@link #onCreate(SQLiteDatabase)} being called with a new SQLiteDatabase object * * @param db the database opened with this helper * @see #SQLiteOpenHelper(Context, String, CursorFactory, int, int, DatabaseErrorHandler) * @hide */ public void onBeforeDelete(SQLiteDatabase db) { } /** * Called when the database is created for the first time. This is where the * creation of tables and the initial population of the tables should happen. * * @param db The database. */ |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteOutOfMemoryException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; public class SQLiteOutOfMemoryException extends SQLiteException { public SQLiteOutOfMemoryException() {} public SQLiteOutOfMemoryException(String error) { super(error); } |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteProgram.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.database.DatabaseUtils; import android.os.CancellationSignal; import java.util.Arrays; /** |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteQuery.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.database.CursorWindow; import android.os.CancellationSignal; import android.os.OperationCanceledException; import android.util.Log; /** |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteQueryBuilder.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.database.Cursor; import android.database.DatabaseUtils; import android.os.CancellationSignal; import android.os.OperationCanceledException; import android.provider.BaseColumns; import android.text.TextUtils; |
︙ | ︙ | |||
386 387 388 389 390 391 392 | // The idea is to ensure that the selection clause is a valid SQL expression // by compiling it twice: once wrapped in parentheses and once as // originally specified. An attacker cannot create an expression that // would escape the SQL expression while maintaining balanced parentheses // in both the wrapped and original forms. String sqlForValidation = buildQuery(projectionIn, "(" + selection + ")", groupBy, having, sortOrder, limit); | < | < < < < < < < < < < | 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | // The idea is to ensure that the selection clause is a valid SQL expression // by compiling it twice: once wrapped in parentheses and once as // originally specified. An attacker cannot create an expression that // would escape the SQL expression while maintaining balanced parentheses // in both the wrapped and original forms. String sqlForValidation = buildQuery(projectionIn, "(" + selection + ")", groupBy, having, sortOrder, limit); db.validateSql(sqlForValidation, cancellationSignal); // will throw if query is invalid } String sql = buildQuery( projectionIn, selection, groupBy, having, sortOrder, limit); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Performing query: " + sql); } return db.rawQueryWithFactory( mFactory, sql, selectionArgs, SQLiteDatabase.findEditTable(mTables), cancellationSignal); // will throw if query is invalid } /** * Construct a SELECT statement suitable for use in a group of * SELECT statements that will be joined through UNION operators * in buildUnionQuery. * * @param projectionIn A list of which columns to return. Passing * null will return all columns, which is discouraged to |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteReadOnlyDatabaseException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; public class SQLiteReadOnlyDatabaseException extends SQLiteException { public SQLiteReadOnlyDatabaseException() {} public SQLiteReadOnlyDatabaseException(String error) { super(error); } |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteSession.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.database.CursorWindow; import android.database.DatabaseUtils; import android.os.CancellationSignal; import android.os.OperationCanceledException; import android.os.ParcelFileDescriptor; |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteStatement.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.os.ParcelFileDescriptor; /** * Represents a statement that can be executed against a database. The statement * cannot return multiple rows or columns, but single value (1 x 1) result sets * are supported. * <p> * This class is not thread-safe. * </p> */ public final class SQLiteStatement extends SQLiteProgram { SQLiteStatement(SQLiteDatabase db, String sql, Object[] bindArgs) { super(db, sql, bindArgs, null); } /** * Execute this SQL statement, if it is not a SELECT / INSERT / DELETE / UPDATE, for example * CREATE / DROP table, view, trigger, index etc. * * @throws android.database.SQLException If the SQL string is invalid for * some reason */ public void execute() { acquireReference(); try { getSession().execute(getSql(), getBindArgs(), getConnectionFlags(), null); } catch (SQLiteDatabaseCorruptException ex) { onCorruption(); throw ex; } finally { releaseReference(); } } /** * Execute this SQL statement, if the the number of rows affected by execution of this SQL * statement is of any importance to the caller - for example, UPDATE / DELETE SQL statements. * * @return the number of rows affected by this SQL statement execution. * @throws android.database.SQLException If the SQL string is invalid for * some reason */ public int executeUpdateDelete() { acquireReference(); try { return getSession().executeForChangedRowCount( getSql(), getBindArgs(), getConnectionFlags(), null); |
︙ | ︙ | |||
77 78 79 80 81 82 83 | /** * Execute this SQL statement and return the ID of the row inserted due to this call. * The SQL statement should be an INSERT for this to be a useful call. * * @return the row ID of the last row inserted, if this insert is successful. -1 otherwise. * | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | /** * Execute this SQL statement and return the ID of the row inserted due to this call. * The SQL statement should be an INSERT for this to be a useful call. * * @return the row ID of the last row inserted, if this insert is successful. -1 otherwise. * * @throws android.database.SQLException If the SQL string is invalid for * some reason */ public long executeInsert() { acquireReference(); try { return getSession().executeForLastInsertedRowId( getSql(), getBindArgs(), getConnectionFlags(), null); |
︙ | ︙ | |||
99 100 101 102 103 104 105 | /** * Execute a statement that returns a 1 by 1 table with a numeric value. * For example, SELECT COUNT(*) FROM table; * * @return The result of the query. * | | | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | /** * Execute a statement that returns a 1 by 1 table with a numeric value. * For example, SELECT COUNT(*) FROM table; * * @return The result of the query. * * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows */ public long simpleQueryForLong() { acquireReference(); try { return getSession().executeForLong( getSql(), getBindArgs(), getConnectionFlags(), null); } catch (SQLiteDatabaseCorruptException ex) { onCorruption(); throw ex; } finally { releaseReference(); } } /** * Execute a statement that returns a 1 by 1 table with a text value. * For example, SELECT COUNT(*) FROM table; * * @return The result of the query. * * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows */ public String simpleQueryForString() { acquireReference(); try { return getSession().executeForString( getSql(), getBindArgs(), getConnectionFlags(), null); } catch (SQLiteDatabaseCorruptException ex) { onCorruption(); throw ex; } finally { releaseReference(); } } /** * Executes a statement that returns a 1 by 1 table with a blob value. * * @return A read-only file descriptor for a copy of the blob value, or {@code null} * if the value is null or could not be read for some reason. * * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows */ public ParcelFileDescriptor simpleQueryForBlobFileDescriptor() { acquireReference(); try { return getSession().executeForBlobFileDescriptor( getSql(), getBindArgs(), getConnectionFlags(), null); } catch (SQLiteDatabaseCorruptException ex) { |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteStatementInfo.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * Describes a SQLite statement. * * @hide */ public final class SQLiteStatementInfo { |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteTableLockedException.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; public class SQLiteTableLockedException extends SQLiteException { public SQLiteTableLockedException() {} public SQLiteTableLockedException(String error) { super(error); } |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteTransactionListener.java.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; /** * A listener for transaction events. */ public interface SQLiteTransactionListener { /** * Called immediately after the transaction begins. |
︙ | ︙ |
Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SqliteWrapper.java.
︙ | ︙ | |||
10 11 12 13 14 15 16 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.database.sqlite; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.util.Log; import android.widget.Toast; /** * @hide */ |
︙ | ︙ | |||
46 47 48 49 50 51 52 | // FIXME: need to optimize this method. private static boolean isLowMemory(SQLiteException e) { return e.getMessage().equals(SQLITE_EXCEPTION_DETAIL_MESSAGE); } public static void checkSQLiteException(Context context, SQLiteException e) { if (isLowMemory(e)) { | > | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | // FIXME: need to optimize this method. private static boolean isLowMemory(SQLiteException e) { return e.getMessage().equals(SQLITE_EXCEPTION_DETAIL_MESSAGE); } public static void checkSQLiteException(Context context, SQLiteException e) { if (isLowMemory(e)) { Toast.makeText(context, com.android.internal.R.string.low_memory, Toast.LENGTH_SHORT).show(); } else { throw e; } } public static Cursor query(Context context, ContentResolver resolver, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { |
︙ | ︙ |
Changes to sqlite3/src/main/jni/sqlite/android_database_SQLiteCommon.cpp.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < > > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "android_database_SQLiteCommon.h" #include <utils/String8.h> namespace android { /* throw a SQLiteException with a message appropriate for the error in handle */ void throw_sqlite3_exception(JNIEnv* env, sqlite3* handle) { throw_sqlite3_exception(env, handle, NULL); } |
︙ | ︙ | |||
61 62 63 64 65 66 67 | user message */ void throw_sqlite3_exception(JNIEnv* env, int errcode, const char* sqlite3Message, const char* message) { const char* exceptionClass; switch (errcode & 0xff) { /* mask off extended error code */ case SQLITE_IOERR: | | | | | | | | | | | | | | | | | | | | > | | > > | < | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | user message */ void throw_sqlite3_exception(JNIEnv* env, int errcode, const char* sqlite3Message, const char* message) { const char* exceptionClass; switch (errcode & 0xff) { /* mask off extended error code */ case SQLITE_IOERR: exceptionClass = "android/database/sqlite/SQLiteDiskIOException"; break; case SQLITE_CORRUPT: case SQLITE_NOTADB: // treat "unsupported file format" error as corruption also exceptionClass = "android/database/sqlite/SQLiteDatabaseCorruptException"; break; case SQLITE_CONSTRAINT: exceptionClass = "android/database/sqlite/SQLiteConstraintException"; break; case SQLITE_ABORT: exceptionClass = "android/database/sqlite/SQLiteAbortException"; break; case SQLITE_DONE: exceptionClass = "android/database/sqlite/SQLiteDoneException"; sqlite3Message = NULL; // SQLite error message is irrelevant in this case break; case SQLITE_FULL: exceptionClass = "android/database/sqlite/SQLiteFullException"; break; case SQLITE_MISUSE: exceptionClass = "android/database/sqlite/SQLiteMisuseException"; break; case SQLITE_PERM: exceptionClass = "android/database/sqlite/SQLiteAccessPermException"; break; case SQLITE_BUSY: exceptionClass = "android/database/sqlite/SQLiteDatabaseLockedException"; break; case SQLITE_LOCKED: exceptionClass = "android/database/sqlite/SQLiteTableLockedException"; break; case SQLITE_READONLY: exceptionClass = "android/database/sqlite/SQLiteReadOnlyDatabaseException"; break; case SQLITE_CANTOPEN: exceptionClass = "android/database/sqlite/SQLiteCantOpenDatabaseException"; break; case SQLITE_TOOBIG: exceptionClass = "android/database/sqlite/SQLiteBlobTooBigException"; break; case SQLITE_RANGE: exceptionClass = "android/database/sqlite/SQLiteBindOrColumnIndexOutOfRangeException"; break; case SQLITE_NOMEM: exceptionClass = "android/database/sqlite/SQLiteOutOfMemoryException"; break; case SQLITE_MISMATCH: exceptionClass = "android/database/sqlite/SQLiteDatatypeMismatchException"; break; case SQLITE_INTERRUPT: exceptionClass = "android/os/OperationCanceledException"; break; default: exceptionClass = "android/database/sqlite/SQLiteException"; break; } if (sqlite3Message) { String8 fullMessage; fullMessage.append(sqlite3Message); fullMessage.appendFormat(" (code %d)", errcode); // print extended error code if (message) { fullMessage.append(": "); fullMessage.append(message); } jniThrowException(env, exceptionClass, fullMessage.string()); } else { jniThrowException(env, exceptionClass, message); } } } // namespace android |
Changes to sqlite3/src/main/jni/sqlite/android_database_SQLiteCommon.h.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _ANDROID_DATABASE_SQLITE_COMMON_H #define _ANDROID_DATABASE_SQLITE_COMMON_H #include <jni.h> #include <nativehelper/JNIHelp.h> #include <sqlite3.h> // Special log tags defined in SQLiteDebug.java. #define SQLITE_LOG_TAG "SQLiteLog" #define SQLITE_TRACE_TAG "SQLiteStatements" #define SQLITE_PROFILE_TAG "SQLiteTime" |
︙ | ︙ |
Changes to sqlite3/src/main/jni/sqlite/android_database_SQLiteConnection.cpp.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | > | | > > > > < < < < < | < < | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "SQLiteConnection" #include <jni.h> #include <nativehelper/JNIHelp.h> #include <android_runtime/AndroidRuntime.h> #include <android_runtime/Log.h> #include <utils/Log.h> #include <utils/String8.h> #include <utils/String16.h> #include <cutils/ashmem.h> #include <sys/mman.h> #include <string.h> #include <unistd.h> #include <androidfw/CursorWindow.h> #include <sqlite3.h> #include <sqlite3_android.h> #include "android_database_SQLiteCommon.h" #include "core_jni_helpers.h" // Set to 1 to use UTF16 storage for localized indexes. #define UTF16_STORAGE 0 namespace android { /* Busy timeout in milliseconds. * If another connection (possibly in another process) has the database locked for * longer than this amount of time then SQLite will generate a SQLITE_BUSY error. * The SQLITE_BUSY error is then raised as a SQLiteDatabaseLockedException. * * In ordinary usage, busy timeouts are quite rare. Most databases only ever * have a single open connection at a time unless they are using WAL. When using * WAL, a timeout could occur if one connection is busy performing an auto-checkpoint * operation. The busy timeout needs to be long enough to tolerate slow I/O write * operations but not so long as to cause the application to hang indefinitely if * there is a problem acquiring a database lock. */ static const int BUSY_TIMEOUT_MS = 2500; static struct { jfieldID name; jfieldID numArgs; jmethodID dispatchCallback; } gSQLiteCustomFunctionClassInfo; static struct { |
︙ | ︙ | |||
83 84 85 86 87 88 89 | OPEN_READ_MASK = 0x00000001, NO_LOCALIZED_COLLATORS = 0x00000010, CREATE_IF_NECESSARY = 0x10000000, }; sqlite3* const db; const int openFlags; | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < | | | < < < < < < < < | | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | OPEN_READ_MASK = 0x00000001, NO_LOCALIZED_COLLATORS = 0x00000010, CREATE_IF_NECESSARY = 0x10000000, }; sqlite3* const db; const int openFlags; const String8 path; const String8 label; volatile bool canceled; SQLiteConnection(sqlite3* db, int openFlags, const String8& path, const String8& label) : db(db), openFlags(openFlags), path(path), label(label), canceled(false) { } }; // Called each time a statement begins execution, when tracing is enabled. static void sqliteTraceCallback(void *data, const char *sql) { SQLiteConnection* connection = static_cast<SQLiteConnection*>(data); ALOG(LOG_VERBOSE, SQLITE_TRACE_TAG, "%s: \"%s\"\n", connection->label.string(), sql); } // Called each time a statement finishes execution, when profiling is enabled. static void sqliteProfileCallback(void *data, const char *sql, sqlite3_uint64 tm) { SQLiteConnection* connection = static_cast<SQLiteConnection*>(data); ALOG(LOG_VERBOSE, SQLITE_PROFILE_TAG, "%s: \"%s\" took %0.3f ms\n", connection->label.string(), sql, tm * 0.000001f); } // Called after each SQLite VM instruction when cancelation is enabled. static int sqliteProgressHandlerCallback(void* data) { SQLiteConnection* connection = static_cast<SQLiteConnection*>(data); return connection->canceled; } static jlong nativeOpen(JNIEnv* env, jclass clazz, jstring pathStr, jint openFlags, jstring labelStr, jboolean enableTrace, jboolean enableProfile) { int sqliteFlags; if (openFlags & SQLiteConnection::CREATE_IF_NECESSARY) { sqliteFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; } else if (openFlags & SQLiteConnection::OPEN_READONLY) { sqliteFlags = SQLITE_OPEN_READONLY; } else { sqliteFlags = SQLITE_OPEN_READWRITE; } const char* pathChars = env->GetStringUTFChars(pathStr, NULL); String8 path(pathChars); env->ReleaseStringUTFChars(pathStr, pathChars); const char* labelChars = env->GetStringUTFChars(labelStr, NULL); String8 label(labelChars); env->ReleaseStringUTFChars(labelStr, labelChars); sqlite3* db; int err = sqlite3_open_v2(path.string(), &db, sqliteFlags, NULL); if (err != SQLITE_OK) { throw_sqlite3_exception_errcode(env, err, "Could not open database"); return 0; } // Check that the database is really read/write when that is what we asked for. if ((sqliteFlags & SQLITE_OPEN_READWRITE) && sqlite3_db_readonly(db, NULL)) { throw_sqlite3_exception(env, db, "Could not open the database in read/write mode."); sqlite3_close(db); return 0; } // Set the default busy handler to retry automatically before returning SQLITE_BUSY. err = sqlite3_busy_timeout(db, BUSY_TIMEOUT_MS); if (err != SQLITE_OK) { throw_sqlite3_exception(env, db, "Could not set busy timeout"); sqlite3_close(db); return 0; } // Register custom Android functions. err = register_android_functions(db, UTF16_STORAGE); if (err) { throw_sqlite3_exception(env, db, "Could not register Android SQL functions."); sqlite3_close(db); return 0; } // Create wrapper object. SQLiteConnection* connection = new SQLiteConnection(db, openFlags, path, label); // Enable tracing and profiling if requested. if (enableTrace) { sqlite3_trace(db, &sqliteTraceCallback, connection); } if (enableProfile) { sqlite3_profile(db, &sqliteProfileCallback, connection); } ALOGV("Opened connection %p with label '%s'", db, label.string()); return reinterpret_cast<jlong>(connection); } static void nativeClose(JNIEnv* env, jclass clazz, jlong connectionPtr) { SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr); if (connection) { |
︙ | ︙ | |||
229 230 231 232 233 234 235 | delete connection; } } // Called each time a custom function is evaluated. static void sqliteCustomFunctionCallback(sqlite3_context *context, int argc, sqlite3_value **argv) { | < | < | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | delete connection; } } // Called each time a custom function is evaluated. static void sqliteCustomFunctionCallback(sqlite3_context *context, int argc, sqlite3_value **argv) { JNIEnv* env = AndroidRuntime::getJNIEnv(); // Get the callback function object. // Create a new local reference to it in case the callback tries to do something // dumb like unregister the function (thereby destroying the global ref) while it is running. jobject functionObjGlobal = reinterpret_cast<jobject>(sqlite3_user_data(context)); jobject functionObj = env->NewLocalRef(functionObjGlobal); |
︙ | ︙ | |||
268 269 270 271 272 273 274 | env->DeleteLocalRef(argsArray); } env->DeleteLocalRef(functionObj); if (env->ExceptionCheck()) { ALOGE("An exception was thrown by custom SQLite function."); | | > | < | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | env->DeleteLocalRef(argsArray); } env->DeleteLocalRef(functionObj); if (env->ExceptionCheck()) { ALOGE("An exception was thrown by custom SQLite function."); LOGE_EX(env); env->ExceptionClear(); } } // Called when a custom function is destroyed. static void sqliteCustomFunctionDestructor(void* data) { jobject functionObjGlobal = reinterpret_cast<jobject>(data); JNIEnv* env = AndroidRuntime::getJNIEnv(); env->DeleteGlobalRef(functionObjGlobal); } static void nativeRegisterCustomFunction(JNIEnv* env, jclass clazz, jlong connectionPtr, jobject functionObj) { SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr); |
︙ | ︙ | |||
310 311 312 313 314 315 316 | } static void nativeRegisterLocalizedCollators(JNIEnv* env, jclass clazz, jlong connectionPtr, jstring localeStr) { SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr); const char* locale = env->GetStringUTFChars(localeStr, NULL); | < < | 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | } static void nativeRegisterLocalizedCollators(JNIEnv* env, jclass clazz, jlong connectionPtr, jstring localeStr) { SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr); const char* locale = env->GetStringUTFChars(localeStr, NULL); int err = register_localized_collators(connection->db, locale, UTF16_STORAGE); env->ReleaseStringUTFChars(localeStr, locale); if (err != SQLITE_OK) { throw_sqlite3_exception(env, connection->db); } } static jlong nativePrepareStatement(JNIEnv* env, jclass clazz, jlong connectionPtr, jstring sqlString) { SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr); jsize sqlLength = env->GetStringLength(sqlString); |
︙ | ︙ | |||
365 366 367 368 369 370 371 | // is always finalized regardless. ALOGV("Finalized statement %p on connection %p", statement, connection->db); sqlite3_finalize(statement); } static jint nativeGetParameterCount(JNIEnv* env, jclass clazz, jlong connectionPtr, jlong statementPtr) { | < < < < | 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | // is always finalized regardless. ALOGV("Finalized statement %p on connection %p", statement, connection->db); sqlite3_finalize(statement); } static jint nativeGetParameterCount(JNIEnv* env, jclass clazz, jlong connectionPtr, jlong statementPtr) { sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr); return sqlite3_bind_parameter_count(statement); } static jboolean nativeIsReadOnly(JNIEnv* env, jclass clazz, jlong connectionPtr, jlong statementPtr) { sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr); return sqlite3_stmt_readonly(statement) != 0; } static jint nativeGetColumnCount(JNIEnv* env, jclass clazz, jlong connectionPtr, jlong statementPtr) { sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr); return sqlite3_column_count(statement); } static jstring nativeGetColumnName(JNIEnv* env, jclass clazz, jlong connectionPtr, jlong statementPtr, jint index) { sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr); const jchar* name = static_cast<const jchar*>(sqlite3_column_name16(statement, index)); if (name) { size_t length = 0; while (name[length]) { length += 1; |
︙ | ︙ | |||
554 555 556 557 558 559 560 | return env->NewString(text, length); } } return NULL; } static int createAshmemRegionWithData(JNIEnv* env, const void* data, size_t length) { | < | 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | return env->NewString(text, length); } } return NULL; } static int createAshmemRegionWithData(JNIEnv* env, const void* data, size_t length) { int error = 0; int fd = ashmem_create_region(NULL, length); if (fd < 0) { error = errno; ALOGE("ashmem_create_region failed: %s", strerror(error)); } else { if (length > 0) { |
︙ | ︙ | |||
584 585 586 587 588 589 590 | return fd; } } close(fd); } | < | | 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | return fd; } } close(fd); } jniThrowIOException(env, error); return -1; } static jint nativeExecuteForBlobFileDescriptor(JNIEnv* env, jclass clazz, jlong connectionPtr, jlong statementPtr) { SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr); sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr); |
︙ | ︙ | |||
607 608 609 610 611 612 613 | return createAshmemRegionWithData(env, blob, length); } } } return -1; } | < < < < | < < > | | < < < < < < | < > > > | < < < < > > > | < < | | < < | < < | < < < | > | < | < < | > > > > > > > > | < | | | > | > | | > > > > | | | | > | < > | < | | < < | < < | | | < | > | | > > > > | < < < | < | | > > > > | < > > > > | | | > > > > > | | | < < < < < < < < < < > > > | > | < < < < < | < | > | | | | | | | | < > > | > | < < | | | | < > | < < | < < > > | | | | > | > | > > > > < < < < < < | | < < < < < < | < < | < < | | | | | > | > > | > | | | | > | < > | | < < | | < < > | < < | | | | > | > > > > | | < < | | < < < | | | < | | < | < < < | > > > | | | | 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | return createAshmemRegionWithData(env, blob, length); } } } return -1; } enum CopyRowResult { CPR_OK, CPR_FULL, CPR_ERROR, }; static CopyRowResult copyRow(JNIEnv* env, CursorWindow* window, sqlite3_stmt* statement, int numColumns, int startPos, int addedRows) { // Allocate a new field directory for the row. status_t status = window->allocRow(); if (status) { LOG_WINDOW("Failed allocating fieldDir at startPos %d row %d, error=%d", startPos, addedRows, status); return CPR_FULL; } // Pack the row into the window. CopyRowResult result = CPR_OK; for (int i = 0; i < numColumns; i++) { int type = sqlite3_column_type(statement, i); if (type == SQLITE_TEXT) { // TEXT data const char* text = reinterpret_cast<const char*>( sqlite3_column_text(statement, i)); // SQLite does not include the NULL terminator in size, but does // ensure all strings are NULL terminated, so increase size by // one to make sure we store the terminator. size_t sizeIncludingNull = sqlite3_column_bytes(statement, i) + 1; status = window->putString(addedRows, i, text, sizeIncludingNull); if (status) { LOG_WINDOW("Failed allocating %u bytes for text at %d,%d, error=%d", sizeIncludingNull, startPos + addedRows, i, status); result = CPR_FULL; break; } LOG_WINDOW("%d,%d is TEXT with %u bytes", startPos + addedRows, i, sizeIncludingNull); } else if (type == SQLITE_INTEGER) { // INTEGER data int64_t value = sqlite3_column_int64(statement, i); status = window->putLong(addedRows, i, value); if (status) { LOG_WINDOW("Failed allocating space for a long in column %d, error=%d", i, status); result = CPR_FULL; break; } LOG_WINDOW("%d,%d is INTEGER 0x%016llx", startPos + addedRows, i, value); } else if (type == SQLITE_FLOAT) { // FLOAT data double value = sqlite3_column_double(statement, i); status = window->putDouble(addedRows, i, value); if (status) { LOG_WINDOW("Failed allocating space for a double in column %d, error=%d", i, status); result = CPR_FULL; break; } LOG_WINDOW("%d,%d is FLOAT %lf", startPos + addedRows, i, value); } else if (type == SQLITE_BLOB) { // BLOB data const void* blob = sqlite3_column_blob(statement, i); size_t size = sqlite3_column_bytes(statement, i); status = window->putBlob(addedRows, i, blob, size); if (status) { LOG_WINDOW("Failed allocating %u bytes for blob at %d,%d, error=%d", size, startPos + addedRows, i, status); result = CPR_FULL; break; } LOG_WINDOW("%d,%d is Blob with %u bytes", startPos + addedRows, i, size); } else if (type == SQLITE_NULL) { // NULL field status = window->putNull(addedRows, i); if (status) { LOG_WINDOW("Failed allocating space for a null in column %d, error=%d", i, status); result = CPR_FULL; break; } LOG_WINDOW("%d,%d is NULL", startPos + addedRows, i); } else { // Unknown data ALOGE("Unknown column type when filling database window"); throw_sqlite3_exception(env, "Unknown column type when filling window"); result = CPR_ERROR; break; } } // Free the last row if if was not successfully copied. if (result != CPR_OK) { window->freeLastRow(); } return result; } static jlong nativeExecuteForCursorWindow(JNIEnv* env, jclass clazz, jlong connectionPtr, jlong statementPtr, jlong windowPtr, jint startPos, jint requiredPos, jboolean countAllRows) { SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr); sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr); CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); status_t status = window->clear(); if (status) { String8 msg; msg.appendFormat("Failed to clear the cursor window, status=%d", status); throw_sqlite3_exception(env, connection->db, msg.string()); return 0; } int numColumns = sqlite3_column_count(statement); status = window->setNumColumns(numColumns); if (status) { String8 msg; msg.appendFormat("Failed to set the cursor window column count to %d, status=%d", numColumns, status); throw_sqlite3_exception(env, connection->db, msg.string()); return 0; } int retryCount = 0; int totalRows = 0; int addedRows = 0; bool windowFull = false; bool gotException = false; while (!gotException && (!windowFull || countAllRows)) { int err = sqlite3_step(statement); if (err == SQLITE_ROW) { LOG_WINDOW("Stepped statement %p to row %d", statement, totalRows); retryCount = 0; totalRows += 1; // Skip the row if the window is full or we haven't reached the start position yet. if (startPos >= totalRows || windowFull) { continue; } CopyRowResult cpr = copyRow(env, window, statement, numColumns, startPos, addedRows); if (cpr == CPR_FULL && addedRows && startPos + addedRows <= requiredPos) { // We filled the window before we got to the one row that we really wanted. // Clear the window and start filling it again from here. // TODO: Would be nicer if we could progressively replace earlier rows. window->clear(); window->setNumColumns(numColumns); startPos += addedRows; addedRows = 0; cpr = copyRow(env, window, statement, numColumns, startPos, addedRows); } if (cpr == CPR_OK) { addedRows += 1; } else if (cpr == CPR_FULL) { windowFull = true; } else { gotException = true; } } else if (err == SQLITE_DONE) { // All rows processed, bail LOG_WINDOW("Processed all rows"); break; } else if (err == SQLITE_LOCKED || err == SQLITE_BUSY) { // The table is locked, retry LOG_WINDOW("Database locked, retrying"); if (retryCount > 50) { ALOGE("Bailing on database busy retry"); throw_sqlite3_exception(env, connection->db, "retrycount exceeded"); gotException = true; } else { // Sleep to give the thread holding the lock a chance to finish usleep(1000); retryCount++; } } else { throw_sqlite3_exception(env, connection->db); gotException = true; } } LOG_WINDOW("Resetting statement %p after fetching %d rows and adding %d rows" "to the window in %d bytes", statement, totalRows, addedRows, window->size() - window->freeSpace()); sqlite3_reset(statement); // Report the total number of rows on request. if (startPos > totalRows) { ALOGE("startPos %d > actual rows %d", startPos, totalRows); } jlong result = jlong(startPos) << 32 | jlong(totalRows); return result; } static jint nativeGetDbLookaside(JNIEnv* env, jobject clazz, jlong connectionPtr) { SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr); int cur = -1; int unused; |
︙ | ︙ | |||
854 855 856 857 858 859 860 | sqlite3_progress_handler(connection->db, 4, sqliteProgressHandlerCallback, connection); } else { sqlite3_progress_handler(connection->db, 0, NULL, NULL); } } | < < < < < < | < < | | | 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | sqlite3_progress_handler(connection->db, 4, sqliteProgressHandlerCallback, connection); } else { sqlite3_progress_handler(connection->db, 0, NULL, NULL); } } static const JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ { "nativeOpen", "(Ljava/lang/String;ILjava/lang/String;ZZ)J", (void*)nativeOpen }, { "nativeClose", "(J)V", (void*)nativeClose }, { "nativeRegisterCustomFunction", "(JLandroid/database/sqlite/SQLiteCustomFunction;)V", (void*)nativeRegisterCustomFunction }, { "nativeRegisterLocalizedCollators", "(JLjava/lang/String;)V", (void*)nativeRegisterLocalizedCollators }, { "nativePrepareStatement", "(JLjava/lang/String;)J", (void*)nativePrepareStatement }, { "nativeFinalizeStatement", "(JJ)V", (void*)nativeFinalizeStatement }, |
︙ | ︙ | |||
910 911 912 913 914 915 916 | (void*)nativeExecuteForString }, { "nativeExecuteForBlobFileDescriptor", "(JJ)I", (void*)nativeExecuteForBlobFileDescriptor }, { "nativeExecuteForChangedRowCount", "(JJ)I", (void*)nativeExecuteForChangedRowCount }, { "nativeExecuteForLastInsertedRowId", "(JJ)J", (void*)nativeExecuteForLastInsertedRowId }, | | < < < < < < < < < < < < < < < | < | | < | | | | < | | < < < < < < < < < < < < < < < < < < < < | 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 | (void*)nativeExecuteForString }, { "nativeExecuteForBlobFileDescriptor", "(JJ)I", (void*)nativeExecuteForBlobFileDescriptor }, { "nativeExecuteForChangedRowCount", "(JJ)I", (void*)nativeExecuteForChangedRowCount }, { "nativeExecuteForLastInsertedRowId", "(JJ)J", (void*)nativeExecuteForLastInsertedRowId }, { "nativeExecuteForCursorWindow", "(JJJIIZ)J", (void*)nativeExecuteForCursorWindow }, { "nativeGetDbLookaside", "(J)I", (void*)nativeGetDbLookaside }, { "nativeCancel", "(J)V", (void*)nativeCancel }, { "nativeResetCancel", "(JZ)V", (void*)nativeResetCancel }, }; int register_android_database_SQLiteConnection(JNIEnv *env) { jclass clazz = FindClassOrDie(env, "android/database/sqlite/SQLiteCustomFunction"); gSQLiteCustomFunctionClassInfo.name = GetFieldIDOrDie(env, clazz, "name", "Ljava/lang/String;"); gSQLiteCustomFunctionClassInfo.numArgs = GetFieldIDOrDie(env, clazz, "numArgs", "I"); gSQLiteCustomFunctionClassInfo.dispatchCallback = GetMethodIDOrDie(env, clazz, "dispatchCallback", "([Ljava/lang/String;)V"); clazz = FindClassOrDie(env, "java/lang/String"); gStringClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); return RegisterMethodsOrDie(env, "android/database/sqlite/SQLiteConnection", sMethods, NELEM(sMethods)); } } // namespace android |
Changes to sqlite3/src/main/jni/sqlite/android_database_SQLiteDebug.cpp.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | > > > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "SQLiteDebug" #include <jni.h> #include <nativehelper/JNIHelp.h> #include <android_runtime/AndroidRuntime.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <utils/Log.h> #include <sqlite3.h> #include "core_jni_helpers.h" namespace android { static struct { jfieldID memoryUsed; jfieldID pageCacheOverflow; jfieldID largestMemAlloc; |
︙ | ︙ | |||
55 56 57 58 59 60 61 | env->SetIntField(statsObj, gSQLiteDebugPagerStatsClassInfo.largestMemAlloc, largestMemAlloc); } /* * JNI registration. */ | | | < < < < < < < < < | | < | | | | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | env->SetIntField(statsObj, gSQLiteDebugPagerStatsClassInfo.largestMemAlloc, largestMemAlloc); } /* * JNI registration. */ static const JNINativeMethod gMethods[] = { { "nativeGetPagerStats", "(Landroid/database/sqlite/SQLiteDebug$PagerStats;)V", (void*) nativeGetPagerStats }, }; int register_android_database_SQLiteDebug(JNIEnv *env) { jclass clazz = FindClassOrDie(env, "android/database/sqlite/SQLiteDebug$PagerStats"); gSQLiteDebugPagerStatsClassInfo.memoryUsed = GetFieldIDOrDie(env, clazz, "memoryUsed", "I"); gSQLiteDebugPagerStatsClassInfo.largestMemAlloc = GetFieldIDOrDie(env, clazz, "largestMemAlloc", "I"); gSQLiteDebugPagerStatsClassInfo.pageCacheOverflow = GetFieldIDOrDie(env, clazz, "pageCacheOverflow", "I"); return RegisterMethodsOrDie(env, "android/database/sqlite/SQLiteDebug", gMethods, NELEM(gMethods)); } } // namespace android |
Changes to sqlite3/src/main/jni/sqlite/android_database_SQLiteGlobal.cpp.
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ | < < < < | | < < < | | | > | > | > > | < < < | | < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "SQLiteGlobal" #include <jni.h> #include <nativehelper/JNIHelp.h> #include "core_jni_helpers.h" #include <sqlite3.h> #include <sqlite3_android.h> #include "android_database_SQLiteCommon.h" #include "android_util_Log.h" namespace android { // Limit heap to 8MB for now. This is 4 times the maximum cursor window // size, as has been used by the original code in SQLiteDatabase for // a long time. static const int SOFT_HEAP_LIMIT = 8 * 1024 * 1024; // Called each time a message is logged. static void sqliteLogCallback(void* data, int err, const char* msg) { bool verboseLog = !!data; int errType = err & 255; if (errType == 0 || errType == SQLITE_CONSTRAINT || errType == SQLITE_SCHEMA || errType == SQLITE_NOTICE || err == SQLITE_WARNING_AUTOINDEX) { if (verboseLog) { ALOG(LOG_VERBOSE, SQLITE_LOG_TAG, "(%d) %s\n", err, msg); } } else if (errType == SQLITE_WARNING) { ALOG(LOG_WARN, SQLITE_LOG_TAG, "(%d) %s\n", err, msg); } else { ALOG(LOG_ERROR, SQLITE_LOG_TAG, "(%d) %s\n", err, msg); } } // Sets the global SQLite configuration. // This must be called before any other SQLite functions are called. static void sqliteInitialize() { // Enable multi-threaded mode. In this mode, SQLite is safe to use by multiple // threads as long as no two threads use the same database connection at the same // time (which we guarantee in the SQLite database wrappers). sqlite3_config(SQLITE_CONFIG_MULTITHREAD); // Redirect SQLite log messages to the Android log. bool verboseLog = android_util_Log_isVerboseLogEnabled(SQLITE_LOG_TAG); sqlite3_config(SQLITE_CONFIG_LOG, &sqliteLogCallback, verboseLog ? (void*)1 : NULL); // The soft heap limit prevents the page cache allocations from growing // beyond the given limit, no matter what the max page cache sizes are // set to. The limit does not, as of 3.5.0, affect any other allocations. sqlite3_soft_heap_limit(SOFT_HEAP_LIMIT); // Initialize SQLite. sqlite3_initialize(); } static jint nativeReleaseMemory(JNIEnv* env, jclass clazz) { return sqlite3_release_memory(SOFT_HEAP_LIMIT); } static const JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ { "nativeReleaseMemory", "()I", (void*)nativeReleaseMemory }, }; int register_android_database_SQLiteGlobal(JNIEnv *env) { sqliteInitialize(); return RegisterMethodsOrDie(env, "android/database/sqlite/SQLiteGlobal", sMethods, NELEM(sMethods)); } } // namespace android |