Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why android SQLite can store double value(java 8 bytes) into float column

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);

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 ?

like image 345
manshuai Avatar asked Jan 18 '23 03:01

manshuai


1 Answers

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 also allows the datatype to be omitted.

like image 168
Shashank Kadne Avatar answered Jan 20 '23 15:01

Shashank Kadne