FileDocCategorySizeDatePackage
SQLiteProgram.javaAPI DocAndroid 5.1 API6744Thu Mar 12 22:22:10 GMT 2015android.database.sqlite

SQLiteProgram

public abstract class SQLiteProgram extends SQLiteClosable
A base class for compiled SQLite programs.

This class is not thread-safe.

Fields Summary
private static final String[]
EMPTY_STRING_ARRAY
private final SQLiteDatabase
mDatabase
private final String
mSql
private final boolean
mReadOnly
private final String[]
mColumnNames
private final int
mNumParameters
private final Object[]
mBindArgs
Constructors Summary
SQLiteProgram(SQLiteDatabase db, String sql, Object[] bindArgs, android.os.CancellationSignal cancellationSignalForPrepare)


         
              
        mDatabase = db;
        mSql = sql.trim();

        int n = DatabaseUtils.getSqlStatementType(mSql);
        switch (n) {
            case DatabaseUtils.STATEMENT_BEGIN:
            case DatabaseUtils.STATEMENT_COMMIT:
            case DatabaseUtils.STATEMENT_ABORT:
                mReadOnly = false;
                mColumnNames = EMPTY_STRING_ARRAY;
                mNumParameters = 0;
                break;

            default:
                boolean assumeReadOnly = (n == DatabaseUtils.STATEMENT_SELECT);
                SQLiteStatementInfo info = new SQLiteStatementInfo();
                db.getThreadSession().prepare(mSql,
                        db.getThreadDefaultConnectionFlags(assumeReadOnly),
                        cancellationSignalForPrepare, info);
                mReadOnly = info.readOnly;
                mColumnNames = info.columnNames;
                mNumParameters = info.numParameters;
                break;
        }

        if (bindArgs != null && bindArgs.length > mNumParameters) {
            throw new IllegalArgumentException("Too many bind arguments.  "
                    + bindArgs.length + " arguments were provided but the statement needs "
                    + mNumParameters + " arguments.");
        }

        if (mNumParameters != 0) {
            mBindArgs = new Object[mNumParameters];
            if (bindArgs != null) {
                System.arraycopy(bindArgs, 0, mBindArgs, 0, bindArgs.length);
            }
        } else {
            mBindArgs = null;
        }
    
Methods Summary
private voidbind(int index, java.lang.Object value)

        if (index < 1 || index > mNumParameters) {
            throw new IllegalArgumentException("Cannot bind argument at index "
                    + index + " because the index is out of range.  "
                    + "The statement has " + mNumParameters + " parameters.");
        }
        mBindArgs[index - 1] = value;
    
public voidbindAllArgsAsStrings(java.lang.String[] bindArgs)
Given an array of String bindArgs, this method binds all of them in one single call.

param
bindArgs the String array of bind args, none of which must be null.

        if (bindArgs != null) {
            for (int i = bindArgs.length; i != 0; i--) {
                bindString(i, bindArgs[i - 1]);
            }
        }
    
public voidbindBlob(int index, byte[] value)
Bind a byte array value to this statement. The value remains bound until {@link #clearBindings} is called.

param
index The 1-based index to the parameter to bind
param
value The value to bind, must not be null

        if (value == null) {
            throw new IllegalArgumentException("the bind value at index " + index + " is null");
        }
        bind(index, value);
    
public voidbindDouble(int index, double value)
Bind a double value to this statement. The value remains bound until {@link #clearBindings} is called.

param
index The 1-based index to the parameter to bind
param
value The value to bind

        bind(index, value);
    
public voidbindLong(int index, long value)
Bind a long value to this statement. The value remains bound until {@link #clearBindings} is called. addToBindArgs

param
index The 1-based index to the parameter to bind
param
value The value to bind

        bind(index, value);
    
public voidbindNull(int index)
Bind a NULL value to this statement. The value remains bound until {@link #clearBindings} is called.

param
index The 1-based index to the parameter to bind null to

        bind(index, null);
    
public voidbindString(int index, java.lang.String value)
Bind a String value to this statement. The value remains bound until {@link #clearBindings} is called.

param
index The 1-based index to the parameter to bind
param
value The value to bind, must not be null

        if (value == null) {
            throw new IllegalArgumentException("the bind value at index " + index + " is null");
        }
        bind(index, value);
    
public voidclearBindings()
Clears all existing bindings. Unset bindings are treated as NULL.

        if (mBindArgs != null) {
            Arrays.fill(mBindArgs, null);
        }
    
final java.lang.Object[]getBindArgs()

        return mBindArgs;
    
final java.lang.String[]getColumnNames()

        return mColumnNames;
    
protected final intgetConnectionFlags()

hide

        return mDatabase.getThreadDefaultConnectionFlags(mReadOnly);
    
final SQLiteDatabasegetDatabase()

        return mDatabase;
    
protected final SQLiteSessiongetSession()

hide

        return mDatabase.getThreadSession();
    
final java.lang.StringgetSql()

        return mSql;
    
public final intgetUniqueId()
Unimplemented.

deprecated
This method is deprecated and must not be used.

        return -1;
    
protected voidonAllReferencesReleased()

        clearBindings();
    
protected final voidonCorruption()

hide

        mDatabase.onCorruption();