Example usage for android.database.sqlite SQLiteProgram bindString

List of usage examples for android.database.sqlite SQLiteProgram bindString

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteProgram bindString.

Prototype

public void bindString(int index, String value) 

Source Link

Document

Bind a String value to this statement.

Usage

From source file:android.database.DatabaseUtils.java

/**
 * 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/*from www  . j  a  va 2 s. co  m*/
 */
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());
    }
}