Java Code Examples for android.database.sqlite.SQLiteStatement.bindBlob()

The following are Jave code examples for showing how to use bindBlob() of the android.database.sqlite.SQLiteStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OftenPorter   File: SqliteHandle.java   Source Code and License Vote up 6 votes
@Override
public boolean saveBinary(Condition query, String name, byte[] data, int offset, int length) throws DBException
{
    SQLiteStatement statement = null;
    try
    {
        SqlUtil.WhereSQL whereSQL = SqlUtil.toUpdate(tableName, checkCondition(query), name, true);
        statement = db.compileStatement(whereSQL.sql);
        byte[] bs = new byte[length];
        System.arraycopy(data, offset, bs, 0, length);
        statement.bindBlob(1, bs);
        Object[] args = whereSQL.args;
        for (int i = 0; i < args.length; i++)
        {
            bind(i + 2, args[i], statement);
        }
        return true;
    } catch (Exception e)
    {
        throw new DBException(e);
    } finally
    {
        close(statement);
    }
}
 
Example 2
Project: GitHub   File: SqlInfo.java   Source Code and License Vote up 5 votes
public SQLiteStatement buildStatement(SQLiteDatabase database) {
    SQLiteStatement result = database.compileStatement(sql);
    if (bindArgs != null) {
        for (int i = 1; i < bindArgs.size() + 1; i++) {
            KeyValue kv = bindArgs.get(i - 1);
            Object value = ColumnUtils.convert2DbValueIfNeeded(kv.value);
            if (value == null) {
                result.bindNull(i);
            } else {
                ColumnConverter converter = ColumnConverterFactory.getColumnConverter(value.getClass());
                ColumnDbType type = converter.getColumnDbType();
                switch (type) {
                    case INTEGER:
                        result.bindLong(i, ((Number) value).longValue());
                        break;
                    case REAL:
                        result.bindDouble(i, ((Number) value).doubleValue());
                        break;
                    case TEXT:
                        result.bindString(i, value.toString());
                        break;
                    case BLOB:
                        result.bindBlob(i, (byte[]) value);
                        break;
                    default:
                        result.bindNull(i);
                        break;
                } // end switch
            }
        }
    }
    return result;
}
 
Example 3
Project: GitHub   File: SimpleEntityNotNullDao.java   Source Code and License Vote up 5 votes
@Override
protected final void bindValues(SQLiteStatement stmt, SimpleEntityNotNull entity) {
    stmt.clearBindings();
    stmt.bindLong(1, entity.getId());
    stmt.bindLong(2, entity.getSimpleBoolean() ? 1L: 0L);
    stmt.bindLong(3, entity.getSimpleByte());
    stmt.bindLong(4, entity.getSimpleShort());
    stmt.bindLong(5, entity.getSimpleInt());
    stmt.bindLong(6, entity.getSimpleLong());
    stmt.bindDouble(7, entity.getSimpleFloat());
    stmt.bindDouble(8, entity.getSimpleDouble());
    stmt.bindString(9, entity.getSimpleString());
    stmt.bindBlob(10, entity.getSimpleByteArray());
}
 
Example 4
Project: SQLite-Performance   File: DbHelper.java   Source Code and License Vote up 5 votes
private void createFiles(SQLiteDatabase db) {
    mFileNames = new String[mFiles];
    byte[] rawData = new byte[mFileSize+mFiles];
    Random random = new Random();
    random.nextBytes(rawData);

    ByteArrayOutputStream[] streams = new ByteArrayOutputStream[mFiles];
    for (int i = 0; i < mFiles; i++) {
        streams[i] = new ByteArrayOutputStream(mFileSize);
        streams[i].write(rawData, i, mFileSize);
        mFileNames[i] = String.valueOf(i);
    }

    SQLiteStatement insert = db.compileStatement("INSERT INTO files (filename, data) VALUES (?, ?)");
    for (int i = 0; i < mFiles; i++) {
        insert.bindString(1, mFileNames[i]);
        insert.bindBlob(2, streams[i].toByteArray());

        insert.execute();
    }
}
 
Example 5
Project: Geoclick   File: DBHelper.java   Source Code and License Vote up 5 votes
public void Picture_Insert(String country, String city, String latitude, String longitude,
                           byte[] thumbnail, String mainImg) {

    // open read and write database
    SQLiteDatabase db = getWritableDatabase();
    // execute insert query

    SQLiteStatement p = db.compileStatement("INSERT INTO Picture values(?,?,?,?,?,?,?);");
    p.bindNull(1);
    p.bindString(2, country);
    p.bindString(3, city);
    p.bindString(4, latitude);
    p.bindString(5, longitude);
    p.bindBlob(6, thumbnail);
    p.bindString(7, mainImg);
    p.execute();
    db.close();
    Log.d("Database :", "INSERT Complete!");
}
 
Example 6
Project: GitHub   File: TestEntityDao.java   Source Code and License Vote up 4 votes
@Override
protected final void bindValues(SQLiteStatement stmt, TestEntity entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
    stmt.bindLong(2, entity.getSimpleInt());
 
    Integer simpleInteger = entity.getSimpleInteger();
    if (simpleInteger != null) {
        stmt.bindLong(3, simpleInteger);
    }
    stmt.bindString(4, entity.getSimpleStringNotNull());
 
    String simpleString = entity.getSimpleString();
    if (simpleString != null) {
        stmt.bindString(5, simpleString);
    }
 
    String indexedString = entity.getIndexedString();
    if (indexedString != null) {
        stmt.bindString(6, indexedString);
    }
 
    String indexedStringAscUnique = entity.getIndexedStringAscUnique();
    if (indexedStringAscUnique != null) {
        stmt.bindString(7, indexedStringAscUnique);
    }
 
    java.util.Date simpleDate = entity.getSimpleDate();
    if (simpleDate != null) {
        stmt.bindLong(8, simpleDate.getTime());
    }
 
    Boolean simpleBoolean = entity.getSimpleBoolean();
    if (simpleBoolean != null) {
        stmt.bindLong(9, simpleBoolean ? 1L: 0L);
    }
 
    byte[] simpleByteArray = entity.getSimpleByteArray();
    if (simpleByteArray != null) {
        stmt.bindBlob(10, simpleByteArray);
    }
}
 
Example 7
Project: GitHub   File: SimpleEntityDao.java   Source Code and License Vote up 4 votes
@Override
protected final void bindValues(SQLiteStatement stmt, SimpleEntity entity) {
    stmt.clearBindings();
 
    Long id = entity.getId();
    if (id != null) {
        stmt.bindLong(1, id);
    }
 
    Boolean simpleBoolean = entity.getSimpleBoolean();
    if (simpleBoolean != null) {
        stmt.bindLong(2, simpleBoolean ? 1L: 0L);
    }
 
    Byte simpleByte = entity.getSimpleByte();
    if (simpleByte != null) {
        stmt.bindLong(3, simpleByte);
    }
 
    Short simpleShort = entity.getSimpleShort();
    if (simpleShort != null) {
        stmt.bindLong(4, simpleShort);
    }
 
    Integer simpleInt = entity.getSimpleInt();
    if (simpleInt != null) {
        stmt.bindLong(5, simpleInt);
    }
 
    Long simpleLong = entity.getSimpleLong();
    if (simpleLong != null) {
        stmt.bindLong(6, simpleLong);
    }
 
    Float simpleFloat = entity.getSimpleFloat();
    if (simpleFloat != null) {
        stmt.bindDouble(7, simpleFloat);
    }
 
    Double simpleDouble = entity.getSimpleDouble();
    if (simpleDouble != null) {
        stmt.bindDouble(8, simpleDouble);
    }
 
    String simpleString = entity.getSimpleString();
    if (simpleString != null) {
        stmt.bindString(9, simpleString);
    }
 
    byte[] simpleByteArray = entity.getSimpleByteArray();
    if (simpleByteArray != null) {
        stmt.bindBlob(10, simpleByteArray);
    }
}