Java Code Examples for android.database.sqlite.SQLiteProgram

The following examples show how to use android.database.sqlite.SQLiteProgram. These examples are extracted from open source projects. 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 Project: android_9.0.0_r45   Source File: DatabaseUtils.java    License: 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 Project: firebase-android-sdk   Source File: SQLitePersistence.java    License: 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 Project: squidb   Source File: SquidCursorFactory.java    License: 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
public static void bindObjectToProgram(SQLiteProgram prog, int index, Object value)
{
    throw new RuntimeException("Stub!");
}
 
Example 5
Source Project: kripton   Source File: KriptonSQLiteProgram.java    License: Apache License 2.0 4 votes vote down vote up
KriptonSQLiteProgram(SQLiteProgram delegate) {
	this.delegate = delegate;
}