Search in sources :

Example 1 with WhereCondition

use of org.greenrobot.greendao.query.WhereCondition in project greenDAO by greenrobot.

the class QueryBuilderSimpleTest method testEqByteArray.

// TODO fix byte arrays? Android is doing String args everywhere
public void testEqByteArray() {
    ArrayList<TestEntity> inserted = insert(3);
    TestEntity testEntity = inserted.get(1);
    byte[] byteArray = { 96, 77, 37, -21 };
    testEntity.setSimpleByteArray(byteArray);
    dao.update(testEntity);
    // Unsupported: Query<TestEntity> query = dao.queryBuilder().where(Properties.SimpleByteArray.eq(byteArray)).build();
    // Works, but probably voids any index on BLOBs (Note: there's no hex2blob function and X'?' is bad syntax):
    // String conditionString = "HEX(" + Properties.SimpleByteArray.columnName + ")=?";
    // WhereCondition condition = new WhereCondition.StringCondition(conditionString, SqlUtils.toHex(byteArray));
    String conditionString = Properties.SimpleByteArray.columnName + '=' + SqlUtils.escapeBlobArgument(byteArray);
    WhereCondition condition = new WhereCondition.StringCondition(conditionString);
    Query<TestEntity> query = dao.queryBuilder().where(condition).build();
    TestEntity testEntity2 = query.uniqueOrThrow();
    assertEquals(testEntity.getId(), testEntity2.getId());
// Unsupported: query.setParameter(0, new byte[]{96, 77, 37, -21, 99});
// Unsupported: assertNull(query.unique());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) WhereCondition(org.greenrobot.greendao.query.WhereCondition)

Aggregations

TestEntity (org.greenrobot.greendao.daotest.TestEntity)1 WhereCondition (org.greenrobot.greendao.query.WhereCondition)1