SQLite text and BLOB values are always variable length. The maximum size of a text or BLOB value is limited by a compile-time directive. The default limit is exactly one billion bytes, or slightly less than a full gigabyte.
SQLite only has four primitive data types: INTEGER, REAL, TEXT, and BLOB. APIs that return database values as an object will only ever return one of these four types.
Long. Allows whole numbers between -2,147,483,648 and 2,147,483,647. 4 bytes. Single. Single precision floating-point.
You can declare a VARCHAR(10) and SQLite will be happy to store a 500-million character string there. And it will keep all 500-million characters intact. Your content is never truncated. SQLite understands the column type of "VARCHAR(N)" to be the same as "TEXT", regardless of the value of N.
From the SQLite docs
INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
Since long
is 8 byte and INTEGER
can also save values of 8 bytes, you can use INTEGER
.
Create the column as an INTEGER
type:
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_A + "("
+ KEY + " INTEGER" + ")");
Put the long
value in INTEGER
column:
contentValues.put(KEY, object.getLongValue());
db.insert(TABLE_A, null, contentValues);
Important: retrieve the value from cursor as LONG
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_A, null);
long value = cursor.getLong(0);
I don't think there is type long. Either you can use INTEGER (or) Numeric. Here is link with supported data types http://www.sqlite.org/datatype3.html
His above link depicts a 64 bit Integer or Essentially a long, also see What is the difference between SQLite integer data types like int, integer, bigint, etc.?
and Version of SQLite used in Android?
You just define a column with Integer type. SQLite sets the column length to 1,2,4,8 depending on your input.
SQLIte will set suitable integer width depend on your input
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With