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

Commit bad5f620 authored by Vasu Nori's avatar Vasu Nori Committed by Android Git Automerger
Browse files

am 0bbcdc6c: Merge "verify database state before calling sqlite. Bug:2593970" into froyo

Merge commit '0bbcdc6c' into froyo-plus-aosp

* commit '0bbcdc6c':
  verify database state before calling sqlite. Bug:2593970
parents e35a45b7 0bbcdc6c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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();
@@ -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) {
@@ -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) {
+19 −26
Original line number Diff line number Diff line
@@ -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
@@ -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();
@@ -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);
    }

@@ -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;");
@@ -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;
@@ -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;");
@@ -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);
    }

@@ -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 {
@@ -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
@@ -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");
        }
@@ -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());
@@ -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);
@@ -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);
+21 −0
Original line number Diff line number Diff line
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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();
@@ -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();
+12 −0
Original line number Diff line number Diff line
@@ -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();

@@ -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();

@@ -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();

@@ -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();