FileDocCategorySizeDatePackage
SQLiteStatement.javaAPI DocAndroid 1.5 API5538Wed May 06 22:41:54 BST 2009android.database.sqlite

SQLiteStatement

public class SQLiteStatement extends SQLiteProgram
A pre-compiled statement against a {@link SQLiteDatabase} that can be reused. The statement cannot return multiple rows, but 1x1 result sets are allowed. Don't use SQLiteStatement constructor directly, please use {@link SQLiteDatabase#compileStatement(String)}

Fields Summary
private static final String
TAG
private final String
mSql
Constructors Summary
SQLiteStatement(SQLiteDatabase db, String sql)
Don't use SQLiteStatement constructor directly, please use {@link SQLiteDatabase#compileStatement(String)}

param
db
param
sql


                      
    /* package */     
        super(db, sql);
        if (SQLiteDebug.DEBUG_SQL_STATEMENTS) {
            mSql = sql;
        } else {
            mSql = null;
        }
    
Methods Summary
public voidexecute()
Execute this SQL statement, if it is not a query. For example, CREATE TABLE, DELTE, INSERT, etc.

throws
android.database.SQLException If the SQL string is invalid for some reason

        mDatabase.lock();
        boolean logStats = mDatabase.mLogStats;
        long startTime = logStats ? SystemClock.elapsedRealtime() : 0;

        acquireReference();
        try {
            if (SQLiteDebug.DEBUG_SQL_STATEMENTS) {
                Log.v(TAG, "execute() for [" + mSql + "]");
            }
            native_execute();
            if (logStats) {
                mDatabase.logTimeStat(false /* write */, startTime, SystemClock.elapsedRealtime());
            }
        } finally {                    
            releaseReference();
            mDatabase.unlock();
        }
    
public longexecuteInsert()
Execute this SQL statement and return the ID of the most recently inserted row. The SQL statement should probably be an INSERT for this to be a useful call.

return
the row ID of the last row inserted.
throws
android.database.SQLException If the SQL string is invalid for some reason

        mDatabase.lock();
        boolean logStats = mDatabase.mLogStats;
        long startTime = logStats ? SystemClock.elapsedRealtime() : 0;

        acquireReference();
        try {
            if (SQLiteDebug.DEBUG_SQL_STATEMENTS) {
                Log.v(TAG, "executeInsert() for [" + mSql + "]");
            }
            native_execute();
            if (logStats) {
                mDatabase.logTimeStat(false /* write */, startTime, SystemClock.elapsedRealtime());
            }
            return mDatabase.lastInsertRow();
        } finally {
            releaseReference();
            mDatabase.unlock();
        }
    
private final native longnative_1x1_long()

private final native java.lang.Stringnative_1x1_string()

private final native voidnative_execute()

public longsimpleQueryForLong()
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

        mDatabase.lock();
        boolean logStats = mDatabase.mLogStats;
        long startTime = logStats ? SystemClock.elapsedRealtime() : 0;

        acquireReference();
        try {
            if (SQLiteDebug.DEBUG_SQL_STATEMENTS) {
                Log.v(TAG, "simpleQueryForLong() for [" + mSql + "]");
            }
            long retValue = native_1x1_long();
            if (logStats) {
                mDatabase.logTimeStat(false /* write */, startTime, SystemClock.elapsedRealtime());
            }
            return retValue;
        } finally {
            releaseReference();
            mDatabase.unlock();
        }
    
public java.lang.StringsimpleQueryForString()
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

        mDatabase.lock();
        boolean logStats = mDatabase.mLogStats;
        long startTime = logStats ? SystemClock.elapsedRealtime() : 0;

        acquireReference();
        try {
            if (SQLiteDebug.DEBUG_SQL_STATEMENTS) {
                Log.v(TAG, "simpleQueryForString() for [" + mSql + "]");
            }
            String retValue = native_1x1_string();
            if (logStats) {
                mDatabase.logTimeStat(false /* write */, startTime, SystemClock.elapsedRealtime());
            }
            return retValue;
        } finally {
            releaseReference();
            mDatabase.unlock();
        }