'Whats the best SQLite data type for a long string
In SQLite3 I am going to be storing a very long string that looks something like this:
string linkList = "www.blah.com,www.meh.com,www.hah.com";
will definitely exceed 255 chars, will probably be over 1000 chars
Should the column linkList be a varchar, TEXT or something else to store a string that will probably be longer than 1000 chars
CREATE TABLE(uId INT PRIMARY KEY, linkList varchar);
What would be the best variable type to use for the column linkList?
Solution 1:[1]
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
Solution 2:[2]
Yor have 2 choices to store a long String in SQLite
TEXTtype - SQLite support very long text (I don't know exact number but I tested 33000 char SQLite3)BLOBtype: You can useBLOBData type to hold long String.
Solution 3:[3]
Size limit for TEXT (VARCHAR and others TEXT alike) are defaulted to 100 0000 000 Bytes
look for macro SQLITE_MAX_LENGTH
Can be increase (or decrease, but no gain to do that aside of code sanity maybe)
using int sqlite3_limit(sqlite3 *db, int limitId, int newLimit)
using SQLITE_LIMIT_LENGTH for limitId.
Again: aside of a need for more than ~100MB (or code sanity by trowing execption) I don't see any interest to modify default.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | krevedko |
| Solution 2 | eRaisedToX |
| Solution 3 | Gordon88 |
