Loading core/java/android/database/sqlite/SQLiteCompiledSql.java +9 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,9 @@ import android.util.Log; private boolean mInUse = false; /* package */ SQLiteCompiledSql(SQLiteDatabase db, String sql) { if (!db.isOpen()) { throw new IllegalStateException("database " + db.getPath() + " already closed"); } mDatabase = db; mSqlStmt = sql; mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace(); Loading @@ -75,6 +78,9 @@ import android.util.Log; * existing compiled SQL program already around */ private void compile(String sql, boolean forceCompilation) { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } // Only compile if we don't have a valid statement already or the caller has // explicitly requested a recompile. if (forceCompilation) { Loading @@ -90,6 +96,9 @@ import android.util.Log; } /* package */ void releaseSqlStatement() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } // Note that native_finalize() checks to make sure that nStatement is // non-null before destroying it. if (nStatement != 0) { Loading core/java/android/database/sqlite/SQLiteDatabase.java +19 −26 Original line number Diff line number Diff line Loading @@ -500,10 +500,10 @@ public class SQLiteDatabase extends SQLiteClosable { * {@link #yieldIfContendedSafely}. */ public void beginTransactionWithListener(SQLiteTransactionListener transactionListener) { lockForced(); if (!isOpen()) { throw new IllegalStateException("database not open"); } lockForced(); boolean ok = false; try { // If this thread already had the lock then get out Loading Loading @@ -915,11 +915,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @return the database version */ public int getVersion() { SQLiteStatement prog = null; lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement prog = null; lock(); try { prog = new SQLiteStatement(this, "PRAGMA user_version;"); long version = prog.simpleQueryForLong(); Loading @@ -936,9 +936,6 @@ public class SQLiteDatabase extends SQLiteClosable { * @param version the new database version */ public void setVersion(int version) { if (!isOpen()) { throw new IllegalStateException("database not open"); } execSQL("PRAGMA user_version = " + version); } Loading @@ -948,11 +945,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @return the new maximum database size */ public long getMaximumSize() { SQLiteStatement prog = null; lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement prog = null; lock(); try { prog = new SQLiteStatement(this, "PRAGMA max_page_count;"); Loading @@ -972,11 +969,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @return the new maximum database size */ public long setMaximumSize(long numBytes) { SQLiteStatement prog = null; lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement prog = null; lock(); try { long pageSize = getPageSize(); long numPages = numBytes / pageSize; Loading @@ -1000,11 +997,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @return the database page size, in bytes */ public long getPageSize() { SQLiteStatement prog = null; lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement prog = null; lock(); try { prog = new SQLiteStatement(this, "PRAGMA page_size;"); Loading @@ -1024,9 +1021,6 @@ public class SQLiteDatabase extends SQLiteClosable { * @param numBytes the database page size, in bytes */ public void setPageSize(long numBytes) { if (!isOpen()) { throw new IllegalStateException("database not open"); } execSQL("PRAGMA page_size = " + numBytes); } Loading Loading @@ -1143,10 +1137,10 @@ public class SQLiteDatabase extends SQLiteClosable { * @return a pre-compiled statement object. */ public SQLiteStatement compileStatement(String sql) throws SQLException { lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } lock(); try { return new SQLiteStatement(this, sql); } finally { Loading Loading @@ -1586,10 +1580,10 @@ public class SQLiteDatabase extends SQLiteClosable { * whereClause. */ public int delete(String table, String whereClause, String[] whereArgs) { lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } lock(); SQLiteStatement statement = null; try { statement = compileStatement("DELETE FROM " + table Loading Loading @@ -1641,10 +1635,6 @@ public class SQLiteDatabase extends SQLiteClosable { */ public int updateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs, int conflictAlgorithm) { if (!isOpen()) { throw new IllegalStateException("database not open"); } if (values == null || values.size() == 0) { throw new IllegalArgumentException("Empty values"); } Loading Loading @@ -1673,6 +1663,9 @@ public class SQLiteDatabase extends SQLiteClosable { } lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement statement = null; try { statement = compileStatement(sql.toString()); Loading Loading @@ -1724,11 +1717,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @throws SQLException If the SQL string is invalid for some reason */ public void execSQL(String sql) throws SQLException { long timeStart = SystemClock.uptimeMillis(); lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } long timeStart = SystemClock.uptimeMillis(); lock(); logTimeStat(mLastSqlStatement, timeStart, GET_LOCK_LOG_PREFIX); try { native_execSQL(sql); Loading Loading @@ -1759,14 +1752,14 @@ public class SQLiteDatabase extends SQLiteClosable { * @throws SQLException If the SQL string is invalid for some reason */ public void execSQL(String sql, Object[] bindArgs) throws SQLException { if (!isOpen()) { throw new IllegalStateException("database not open"); } if (bindArgs == null) { throw new IllegalArgumentException("Empty bindArgs"); } long timeStart = SystemClock.uptimeMillis(); lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement statement = null; try { statement = compileStatement(sql); Loading core/java/android/database/sqlite/SQLiteProgram.java +21 −0 Original line number Diff line number Diff line Loading @@ -173,6 +173,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * @param index The 1-based index to the parameter to bind null to */ public void bindNull(int index) { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_null(index); Loading @@ -189,6 +192,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * @param value The value to bind */ public void bindLong(int index, long value) { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_long(index, value); Loading @@ -205,6 +211,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * @param value The value to bind */ public void bindDouble(int index, double value) { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_double(index, value); Loading @@ -224,6 +233,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { if (value == null) { throw new IllegalArgumentException("the bind value at index " + index + " is null"); } if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_string(index, value); Loading @@ -243,6 +255,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { if (value == null) { throw new IllegalArgumentException("the bind value at index " + index + " is null"); } if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_blob(index, value); Loading @@ -255,6 +270,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * Clears all existing bindings. Unset bindings are treated as NULL. */ public void clearBindings() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_clear_bindings(); Loading @@ -267,6 +285,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * Release this program's resources, making it invalid. */ public void close() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } mDatabase.lock(); try { releaseReference(); Loading core/java/android/database/sqlite/SQLiteStatement.java +12 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,9 @@ public class SQLiteStatement extends SQLiteProgram * some reason */ public void execute() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } long timeStart = SystemClock.uptimeMillis(); mDatabase.lock(); Loading @@ -67,6 +70,9 @@ public class SQLiteStatement extends SQLiteProgram * some reason */ public long executeInsert() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } long timeStart = SystemClock.uptimeMillis(); mDatabase.lock(); Loading @@ -90,6 +96,9 @@ public class SQLiteStatement extends SQLiteProgram * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows */ public long simpleQueryForLong() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } long timeStart = SystemClock.uptimeMillis(); mDatabase.lock(); Loading @@ -113,6 +122,9 @@ public class SQLiteStatement extends SQLiteProgram * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows */ public String simpleQueryForString() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } long timeStart = SystemClock.uptimeMillis(); mDatabase.lock(); Loading Loading
core/java/android/database/sqlite/SQLiteCompiledSql.java +9 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,9 @@ import android.util.Log; private boolean mInUse = false; /* package */ SQLiteCompiledSql(SQLiteDatabase db, String sql) { if (!db.isOpen()) { throw new IllegalStateException("database " + db.getPath() + " already closed"); } mDatabase = db; mSqlStmt = sql; mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace(); Loading @@ -75,6 +78,9 @@ import android.util.Log; * existing compiled SQL program already around */ private void compile(String sql, boolean forceCompilation) { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } // Only compile if we don't have a valid statement already or the caller has // explicitly requested a recompile. if (forceCompilation) { Loading @@ -90,6 +96,9 @@ import android.util.Log; } /* package */ void releaseSqlStatement() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } // Note that native_finalize() checks to make sure that nStatement is // non-null before destroying it. if (nStatement != 0) { Loading
core/java/android/database/sqlite/SQLiteDatabase.java +19 −26 Original line number Diff line number Diff line Loading @@ -500,10 +500,10 @@ public class SQLiteDatabase extends SQLiteClosable { * {@link #yieldIfContendedSafely}. */ public void beginTransactionWithListener(SQLiteTransactionListener transactionListener) { lockForced(); if (!isOpen()) { throw new IllegalStateException("database not open"); } lockForced(); boolean ok = false; try { // If this thread already had the lock then get out Loading Loading @@ -915,11 +915,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @return the database version */ public int getVersion() { SQLiteStatement prog = null; lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement prog = null; lock(); try { prog = new SQLiteStatement(this, "PRAGMA user_version;"); long version = prog.simpleQueryForLong(); Loading @@ -936,9 +936,6 @@ public class SQLiteDatabase extends SQLiteClosable { * @param version the new database version */ public void setVersion(int version) { if (!isOpen()) { throw new IllegalStateException("database not open"); } execSQL("PRAGMA user_version = " + version); } Loading @@ -948,11 +945,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @return the new maximum database size */ public long getMaximumSize() { SQLiteStatement prog = null; lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement prog = null; lock(); try { prog = new SQLiteStatement(this, "PRAGMA max_page_count;"); Loading @@ -972,11 +969,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @return the new maximum database size */ public long setMaximumSize(long numBytes) { SQLiteStatement prog = null; lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement prog = null; lock(); try { long pageSize = getPageSize(); long numPages = numBytes / pageSize; Loading @@ -1000,11 +997,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @return the database page size, in bytes */ public long getPageSize() { SQLiteStatement prog = null; lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement prog = null; lock(); try { prog = new SQLiteStatement(this, "PRAGMA page_size;"); Loading @@ -1024,9 +1021,6 @@ public class SQLiteDatabase extends SQLiteClosable { * @param numBytes the database page size, in bytes */ public void setPageSize(long numBytes) { if (!isOpen()) { throw new IllegalStateException("database not open"); } execSQL("PRAGMA page_size = " + numBytes); } Loading Loading @@ -1143,10 +1137,10 @@ public class SQLiteDatabase extends SQLiteClosable { * @return a pre-compiled statement object. */ public SQLiteStatement compileStatement(String sql) throws SQLException { lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } lock(); try { return new SQLiteStatement(this, sql); } finally { Loading Loading @@ -1586,10 +1580,10 @@ public class SQLiteDatabase extends SQLiteClosable { * whereClause. */ public int delete(String table, String whereClause, String[] whereArgs) { lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } lock(); SQLiteStatement statement = null; try { statement = compileStatement("DELETE FROM " + table Loading Loading @@ -1641,10 +1635,6 @@ public class SQLiteDatabase extends SQLiteClosable { */ public int updateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs, int conflictAlgorithm) { if (!isOpen()) { throw new IllegalStateException("database not open"); } if (values == null || values.size() == 0) { throw new IllegalArgumentException("Empty values"); } Loading Loading @@ -1673,6 +1663,9 @@ public class SQLiteDatabase extends SQLiteClosable { } lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement statement = null; try { statement = compileStatement(sql.toString()); Loading Loading @@ -1724,11 +1717,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @throws SQLException If the SQL string is invalid for some reason */ public void execSQL(String sql) throws SQLException { long timeStart = SystemClock.uptimeMillis(); lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } long timeStart = SystemClock.uptimeMillis(); lock(); logTimeStat(mLastSqlStatement, timeStart, GET_LOCK_LOG_PREFIX); try { native_execSQL(sql); Loading Loading @@ -1759,14 +1752,14 @@ public class SQLiteDatabase extends SQLiteClosable { * @throws SQLException If the SQL string is invalid for some reason */ public void execSQL(String sql, Object[] bindArgs) throws SQLException { if (!isOpen()) { throw new IllegalStateException("database not open"); } if (bindArgs == null) { throw new IllegalArgumentException("Empty bindArgs"); } long timeStart = SystemClock.uptimeMillis(); lock(); if (!isOpen()) { throw new IllegalStateException("database not open"); } SQLiteStatement statement = null; try { statement = compileStatement(sql); Loading
core/java/android/database/sqlite/SQLiteProgram.java +21 −0 Original line number Diff line number Diff line Loading @@ -173,6 +173,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * @param index The 1-based index to the parameter to bind null to */ public void bindNull(int index) { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_null(index); Loading @@ -189,6 +192,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * @param value The value to bind */ public void bindLong(int index, long value) { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_long(index, value); Loading @@ -205,6 +211,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * @param value The value to bind */ public void bindDouble(int index, double value) { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_double(index, value); Loading @@ -224,6 +233,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { if (value == null) { throw new IllegalArgumentException("the bind value at index " + index + " is null"); } if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_string(index, value); Loading @@ -243,6 +255,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { if (value == null) { throw new IllegalArgumentException("the bind value at index " + index + " is null"); } if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_bind_blob(index, value); Loading @@ -255,6 +270,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * Clears all existing bindings. Unset bindings are treated as NULL. */ public void clearBindings() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } acquireReference(); try { native_clear_bindings(); Loading @@ -267,6 +285,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { * Release this program's resources, making it invalid. */ public void close() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } mDatabase.lock(); try { releaseReference(); Loading
core/java/android/database/sqlite/SQLiteStatement.java +12 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,9 @@ public class SQLiteStatement extends SQLiteProgram * some reason */ public void execute() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } long timeStart = SystemClock.uptimeMillis(); mDatabase.lock(); Loading @@ -67,6 +70,9 @@ public class SQLiteStatement extends SQLiteProgram * some reason */ public long executeInsert() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } long timeStart = SystemClock.uptimeMillis(); mDatabase.lock(); Loading @@ -90,6 +96,9 @@ public class SQLiteStatement extends SQLiteProgram * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows */ public long simpleQueryForLong() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } long timeStart = SystemClock.uptimeMillis(); mDatabase.lock(); Loading @@ -113,6 +122,9 @@ public class SQLiteStatement extends SQLiteProgram * @throws android.database.sqlite.SQLiteDoneException if the query returns zero rows */ public String simpleQueryForString() { if (!mDatabase.isOpen()) { throw new IllegalStateException("database " + mDatabase.getPath() + " already closed"); } long timeStart = SystemClock.uptimeMillis(); mDatabase.lock(); Loading