I want to create a table with the column type Long
instead of Integer
. Is it possible?
我想创建一个列类型为Long而不是Integer的表。可能吗?
6 个解决方案
#1
170
From the SQLite docs
来自SQLite文档
INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
整数。该值是有符号整数,存储为1,2,3,4,6或8个字节,具体取决于值的大小。
Since long
is 8 byte and INTEGER
can also save values of 8 bytes, you can use INTEGER
.
由于long是8字节而INTEGER也可以保存8字节的值,因此可以使用INTEGER。
#2
13
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
我不认为有类型很长。您可以使用INTEGER(或)数字。以下是与支持的数据类型http://www.sqlite.org/datatype3.html的链接
#3
13
Create the column as an INTEGER
type:
将列创建为INTEGER类型:
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_A + "("
+ KEY + " INTEGER" + ")");
Put the long
value in INTEGER
column:
将long值放在INTEGER列中:
contentValues.put(KEY, object.getLongValue());
db.insert(TABLE_A, null, contentValues);
Important: retrieve the value from cursor as LONG
重要说明:将游标中的值检索为LONG
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_A, null);
long value = cursor.getLong(0);
#4
4
You just define a column with Integer type. SQLite sets the column length to 1,2,4,8 depending on your input.
您只需使用Integer类型定义一列。 SQLite根据您的输入将列长度设置为1,2,4,8。
#5
3
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.?
他的上面的链接描述了一个64位整数或者本质上很长,也看看SQLite整数数据类型如int,integer,bigint等有什么区别?
and Version of SQLite used in Android?
和Android中使用的SQLite版本?
#6
1
SQLIte will set suitable integer width depend on your input
SQLIte将根据您的输入设置合适的整数宽度
#1
170
From the SQLite docs
来自SQLite文档
INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
整数。该值是有符号整数,存储为1,2,3,4,6或8个字节,具体取决于值的大小。
Since long
is 8 byte and INTEGER
can also save values of 8 bytes, you can use INTEGER
.
由于long是8字节而INTEGER也可以保存8字节的值,因此可以使用INTEGER。
#2
13
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
我不认为有类型很长。您可以使用INTEGER(或)数字。以下是与支持的数据类型http://www.sqlite.org/datatype3.html的链接
#3
13
Create the column as an INTEGER
type:
将列创建为INTEGER类型:
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_A + "("
+ KEY + " INTEGER" + ")");
Put the long
value in INTEGER
column:
将long值放在INTEGER列中:
contentValues.put(KEY, object.getLongValue());
db.insert(TABLE_A, null, contentValues);
Important: retrieve the value from cursor as LONG
重要说明:将游标中的值检索为LONG
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_A, null);
long value = cursor.getLong(0);
#4
4
You just define a column with Integer type. SQLite sets the column length to 1,2,4,8 depending on your input.
您只需使用Integer类型定义一列。 SQLite根据您的输入将列长度设置为1,2,4,8。
#5
3
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.?
他的上面的链接描述了一个64位整数或者本质上很长,也看看SQLite整数数据类型如int,integer,bigint等有什么区别?
and Version of SQLite used in Android?
和Android中使用的SQLite版本?
#6
1
SQLIte will set suitable integer width depend on your input
SQLIte将根据您的输入设置合适的整数宽度