SQLite 数据类型

January 22, 2013

Android

Android使用的是SQLite数据库,SQLite对数据类型不是很重视,或者说很灵活,你可以定义成数字的类型,但是可以把它当成字符来使用。不过为了便于代码阅读,还是写上相符合的类型比较好。

类型主要有5种,NULL , INTEGER , REAL , TEXT , BLOB

Most SQL database engines (every SQL database engine other than SQLite, as far as we know) uses static, rigid typing. With static typing, the datatype of a value is determined by its container - the particular column in which the value is stored.

SQLite uses a more general dynamic type system. In SQLite, the datatype of a value is associated with the value itself, not with its container. The dynamic type system of SQLite is backwards compatible with the more common static type systems of other database engines in the sense that SQL statement that work on statically typed databases should work the same way in SQLite. However, the dynamic typing in SQLite allows it to do things which are not possible in traditional rigidly typed databases.

Each value stored in an 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.//二进制

--- EOF ---

添加新评论