我正在尝试识别 SQLite 列数据类型,但我不知道如何检查列中的数字是 long
或 int
,还是 float
或 double
。
Cursor c;
Object val;
int type = c.getType(i);
if(type == Cursor.FIELD_TYPE_BLOB){
val = c.getBlob(i);
}else if(type == Cursor.FIELD_TYPE_FLOAT){
val = c.getFloat(i);
}else if(type == Cursor.FIELD_TYPE_INTEGER){
val = c.getInt(i);
}else if(type == Cursor.FIELD_TYPE_LONG){ //this here is the problem. "Cursor.FIELD_TYPE_LONG" does not exists
val = c.getLong(i);
} else if(type == Cursor.FIELD_TYPE_NULL){
val = null;
}else if(type == Cursor.FIELD_TYPE_STRING){
val = c.getString(i);
}
最佳答案
SQLite 没有列数据类型;列中的值可以有不同的类型。
作为documentation表明,整数可以存储在 8 个字节中,因此如果您不知道列中的值实际有多大,则必须使用 getLong
。
float 也是 8 字节值,因此您必须使用 double
。
关于java - SQLite识别长值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32284135/