use of org.xutils.db.converter.ColumnConverter in project xUtils3 by wyouflf.
the class ColumnUtils method convert2DbValueIfNeeded.
@SuppressWarnings("unchecked")
public static Object convert2DbValueIfNeeded(final Object value) {
Object result = value;
if (value != null) {
Class<?> valueType = value.getClass();
ColumnConverter converter = ColumnConverterFactory.getColumnConverter(valueType);
result = converter.fieldValue2DbValue(value);
}
return result;
}
use of org.xutils.db.converter.ColumnConverter in project xUtils3 by wyouflf.
the class SqlInfo method buildStatement.
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;
}
Aggregations