android.database.sqlite.SQLiteProgram Java Examples

The following examples show how to use android.database.sqlite.SQLiteProgram. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseUtils.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Binds the given Object to the given SQLiteProgram using the proper
 * typing. For example, bind numbers as longs/doubles, and everything else
 * as a string by call toString() on it.
 *
 * @param prog the program to bind the object to
 * @param index the 1-based index to bind at
 * @param value the value to bind
 */
public static void bindObjectToProgram(SQLiteProgram prog, int index,
        Object value) {
    if (value == null) {
        prog.bindNull(index);
    } else if (value instanceof Double || value instanceof Float) {
        prog.bindDouble(index, ((Number)value).doubleValue());
    } else if (value instanceof Number) {
        prog.bindLong(index, ((Number)value).longValue());
    } else if (value instanceof Boolean) {
        Boolean bool = (Boolean)value;
        if (bool) {
            prog.bindLong(index, 1);
        } else {
            prog.bindLong(index, 0);
        }
    } else if (value instanceof byte[]){
        prog.bindBlob(index, (byte[]) value);
    } else {
        prog.bindString(index, value.toString());
    }
}
 
Example #2
Source File: SQLitePersistence.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Binds the given arguments to the given SQLite statement or query.
 *
 * <p>This method helps work around the fact that all of the querying methods on SQLiteDatabase
 * take an array of strings for bind arguments. Most values can be straightforwardly converted to
 * strings except BLOB literals, which must be base64 encoded and is just too painful.
 *
 * <p>It's possible to bind using typed arguments (including BLOBs) using SQLiteProgram objects.
 * This method bridges the gap by examining the types of the bindArgs and calling to the
 * appropriate bind method on the program.
 */
private static void bind(SQLiteProgram program, Object[] bindArgs) {
  for (int i = 0; i < bindArgs.length; i++) {
    Object arg = bindArgs[i];
    if (arg == null) {
      program.bindNull(i + 1);
    } else if (arg instanceof String) {
      program.bindString(i + 1, (String) arg);
    } else if (arg instanceof Integer) {
      program.bindLong(i + 1, (Integer) arg);
    } else if (arg instanceof Long) {
      program.bindLong(i + 1, (Long) arg);
    } else if (arg instanceof Double) {
      program.bindDouble(i + 1, (Double) arg);
    } else if (arg instanceof byte[]) {
      program.bindBlob(i + 1, (byte[]) arg);
    } else {
      throw fail("Unknown argument %s of type %s", arg, arg.getClass());
    }
  }
}
 
Example #3
Source File: SquidCursorFactory.java    From squidb with Apache License 2.0 5 votes vote down vote up
public static void bindArgumentsToProgram(SQLiteProgram program, Object[] sqlArgs) {
    if (sqlArgs == null) {
        return;
    }
    for (int i = 1; i <= sqlArgs.length; i++) {
        DatabaseUtils.bindObjectToProgram(program, i, sqlArgs[i - 1]);
    }
}
 
Example #4
Source File: DatabaseUtils.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void bindObjectToProgram(SQLiteProgram prog, int index, Object value)
{
    throw new RuntimeException("Stub!");
}
 
Example #5
Source File: KriptonSQLiteProgram.java    From kripton with Apache License 2.0 4 votes vote down vote up
KriptonSQLiteProgram(SQLiteProgram delegate) {
	this.delegate = delegate;
}