长字符串的最佳SQLite数据类型是什么

时间:2022-03-12 17:04:10

In SQLite3 I am going to be storing a very long string that looks something like this:

在SQLite3中,我将存储一个很长的字符串,它看起来像这样:

string linkList = "www.blah.com,www.meh.com,www.hah.com"; 

will definitely exceed 255 chars, will probably be over 1000 chars

一定会超过255个字符,可能会超过1000个字符

Should the column linkList be a varchar, TEXT or something else to store a string that will probably be longer than 1000 chars

列链接列表应该是varchar、TEXT还是其他什么来存储可能超过1000字符的字符串

CREATE TABLE(uId INT PRIMARY KEY, linkList varchar);

What would be the best variable type to use for the column linkList?

列链接列表使用的最佳变量类型是什么?

3 个解决方案

#1


20  

You should use TEXT. Although, that's the same thing as VARCHAR:

您应该使用文本。虽然,这和VARCHAR是一样的

If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity

如果列声明的类型包含任何字符串“CHAR”、“CLOB”或“TEXT”,则该列具有文本关联。注意,类型VARCHAR包含字符串“CHAR”,并因此分配了文本关联

And also:

还有:

Note that numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values.

注意,SQLite忽略了圆括号中的数字参数(例如:“VARCHAR(255)”)——SQLite不会对字符串、blob或数值的长度施加任何长度限制(除了大的全局SQLITE_MAX_LENGTH限制)。

#2


18  

Actually, all data types in SQLite is no matter, all data will be stored as strings. You can execute query CREATE TABLE(uId INT PRIMARY KEY, linkList BlahBlahString); without any error. Data type in SQLite is for sql compability only

实际上,SQLite中的所有数据类型都不重要,所有数据都将作为字符串存储。可以执行查询创建表(uId INT主键,linkList BlahBlahString);没有任何错误。SQLite中的数据类型仅用于sql压缩

#3


4  

Yor have 2 choices to store a long String in SQLite

你有两个选择来存储长字符串在SQLite中

  1. TEXT type - SQLite support very long text (I don't know exact number but I tested 33000 char SQLite3)
  2. 文本类型- SQLite支持非常长的文本(我不知道确切的数字,但是我测试了33000字符SQLite3)
  3. BLOB type: You can use BLOB Data type to hold long String.
  4. BLOB类型:可以使用BLOB数据类型来保存长字符串。

#1


20  

You should use TEXT. Although, that's the same thing as VARCHAR:

您应该使用文本。虽然,这和VARCHAR是一样的

If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity

如果列声明的类型包含任何字符串“CHAR”、“CLOB”或“TEXT”,则该列具有文本关联。注意,类型VARCHAR包含字符串“CHAR”,并因此分配了文本关联

And also:

还有:

Note that numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values.

注意,SQLite忽略了圆括号中的数字参数(例如:“VARCHAR(255)”)——SQLite不会对字符串、blob或数值的长度施加任何长度限制(除了大的全局SQLITE_MAX_LENGTH限制)。

#2


18  

Actually, all data types in SQLite is no matter, all data will be stored as strings. You can execute query CREATE TABLE(uId INT PRIMARY KEY, linkList BlahBlahString); without any error. Data type in SQLite is for sql compability only

实际上,SQLite中的所有数据类型都不重要,所有数据都将作为字符串存储。可以执行查询创建表(uId INT主键,linkList BlahBlahString);没有任何错误。SQLite中的数据类型仅用于sql压缩

#3


4  

Yor have 2 choices to store a long String in SQLite

你有两个选择来存储长字符串在SQLite中

  1. TEXT type - SQLite support very long text (I don't know exact number but I tested 33000 char SQLite3)
  2. 文本类型- SQLite支持非常长的文本(我不知道确切的数字,但是我测试了33000字符SQLite3)
  3. BLOB type: You can use BLOB Data type to hold long String.
  4. BLOB类型:可以使用BLOB数据类型来保存长字符串。