http://forlong401.com/?p=1317
http://androidren.com/index.php?qa=300&qa_1=sqlite%E6%94%AF%E6%8C%81%E9%82%A3%E4%BA%9B%E6%95%B0%E6%8D%AE% e7%b1%bb%e5%9e%8b
Because SQLite uses dynamic data types, other traditional relational databases use static data types. So if you want to know that SQLite supports those data types, you need to figure out: the difference between a dynamic data type and a static data type.
Dynamic Data type: The data type of the database store and the type of data input are dynamically matched, in short, a database field is defined as a string text type, you can also deposit integer integer data.
Static data types: The data types that the database stores and the type requirements for data entry are consistent. In short, the data types that a field can store are determined when the table is declared.
As a result, there are significant differences in data storage between SQLite and traditional relational databases.
In SQLite, there are also differences in storage classifications and data types. The SQLite data type is a property that specifies the data type of any object. Each column in SQLite has an associated data type for each variable and expression. You can use these data types while creating a table. SQLite uses a more general dynamic type System. In SQLite, the data type of a value is related to the value itself, not to its container. This relationship is reflected in the transformation of the storage type and the data type, which is the concept of using type affinity.
There are five kinds of sqlite storage types:
Storage class |
Describe |
Null |
Value is a NULL value. |
INTEGER |
The value is a signed integer that is stored in 1, 2, 3, 4, 6, or 8 bytes, depending on the size of the value. |
REAL |
The value is a floating-point value that is stored as a 8-byte IEEE floating-point number. |
TEXT |
The value is a text string that is stored using the database encoding (UTF-8, utf-16be, or Utf-16le). |
Blob |
The value is a blob of data that is stored entirely according to its input. |
SQLite type Affinity has the following five types:
SQLite supports the type affinity concept on columns. Any column can still store any type of data, but the preferred storage class for the column is its affinity. In the SQLite3 database, the columns for each table are assigned to one of the following types of affinity:
Affinity |
Describe |
TEXT |
The column stores all data using the storage class NULL, TEXT, or BLOB. |
NUMERIC |
The column can contain values that use all five storage classes. |
INTEGER |
Same as the column with NUMERIC affinity, with an exception in the CAST expression. |
REAL |
Similar to a column with NUMERIC affinity, the difference is that it forces an integer value to be converted to a floating point representation. |
NONE |
Columns with affinity NONE, which storage class is not preferred, nor does it attempt to cast data from one storage class to another. |
Here are the rules for traditional relational database data types and type affinity mappings:
example typenames from the CREATE TABLE Statement or CAST Expression |
resulting Affinity |
rule used to determine Affinity |
int integer tinyint smallint mediumint bigint unsigned BIG INT int2 int8 |
INTEGER |
1 |
CHARACTER (20) VARCHAR (255) VARYING CHARACTER (255) NCHAR (55) NATIVE CHARACTER (70) NVARCHAR (100) TEXT Clob |
TEXT |
2 |
Blob No datatype specified |
NONE |
3 |
real double double PRECISION float |
real |
4 |
NUMERIC DECIMAL (10,5) BOOLEAN DATE Datetime |
NUMERIC |
5 |
Conclusion:
SQLite supports those data types: all supported. However, to maintain logical consistency, portability, and ease of maintenance, it is recommended that you define the fields of the data table using types that are consistent with the data storage types that SQLite supports. In short, you will have your data type one by one corresponding to the following data type best:
Storage class |
Describe |
Null |
Value is a NULL value. |
INTEGER |
The value is a signed integer that is stored in 1, 2, 3, 4, 6, or 8 bytes, depending on the size of the value. |
REAL |
The value is a floating-point value that is stored as a 8-byte IEEE floating-point number. |
TEXT |
The value is a text string that is stored using the database encoding (UTF-8, utf-16be, or Utf-16le). |
Blob |
The value is a blob of data that is stored entirely according to its input. |
Reference:
http://androidren.com/index.php?qa=300&qa_1=sqlite%E6%94%AF%E6%8C%81%E9%82%A3%E4%BA%9B%E6%95%B0%E6%8D%AE% e7%b1%bb%e5%9e%8b
Http://sqlite.org/datatype3.html
Each value stored in a SQLite database (or manipulated by the database engine) has one of the following storage classes:
- Null. The value is a NULL value.
- INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
- REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
- TEXT. The value is a text string, stored using the database encoding (UTF-8, utf-16be or Utf-16le).
- Blob. The value is a blob of data, stored exactly as it was input.
SQLite supports those data types