为什么Android的SQLite的可存储双值(Java的8个字节)为浮动列字节、Android、SQLite、Java

2023-09-05 08:14:02 作者:狂派领袖威震呆

Create Table:
db.execSQL("CREATE TABLE " + PERSONS_TABLE + " ("
        + PersonsColumns.ID 
        + " INTEGER PRIMARY KEY AUTOINCREMENT, "
        ...
            + PersonsColumns.HEIGHT + " FLOAT, "
                    + PersonsColumns.CITY + " STRING);");
Write Data:
ContentValues values = new ContentValues();
alues.put(PersonsColumns.HEIGHT, 1.7976931348623157E308);
db.insertOrIgnore(values);

您可以看到价值1.7976931348623157E308是在sqlite的浮点值范围(4字节)。为什么它可以正确地存储这个值?

You can see the value 1.7976931348623157E308 is out of the FLOAT value range(4 bytes) in sqlite. why it can correctly store this value ?

推荐答案

SQLite是无类型。你可以存储你想要的任何表的任何列任何类型的数据,而不管该列的声明数据类型。

SQLite is "typeless".You can store any kind of data you want in any column of any table, regardless of the declared datatype of that column

的SQLite还允许数据类型被删去。

SQLite also allows the datatype to be omitted.