android 没有必需方法(如 getBoolean 和 getDate)的数据库游标

android database cursor without required methods such as getBoolean and getDate

android数据库游标缺少常用方法如

getBoolean
getDate
getObject
getBigDecimal

这是为什么?

如何实现这些方法?我应该调用 getString(index) 然后将其转换为上面的类型吗? getObject() 怎么样?

主要是因为不需要它们,有些也不可移植。

  • 布尔值只需使用 0 或 1 的整数,如果需要,您可以使用掩码来拥有多个布尔值。
  • 日期使用 INTEGER (getLong) 或 TEXT 或 REAL。
  • 对象可以潜在地保存为字节 (BLOB) 或拆分成它的组件。例如,Java 中的对象在 C++ 中不会是 readable/usable,这将非常违反可移植性。
  • BigDecimal 使用 REAL (getDouble/getFloat)、TEXT 或偶字节 (BLOB)。

阅读 Datatypes In SQLite Version 3 ,其中解释了 SQLite 和数据类型的灵活性。