SQLite 整数数据类型(如 int、integer、bigint 等)之间有什么区别? [英] What is the difference between SQLite integer data types like int, integer, bigint, etc.?

查看:369
本文介绍了SQLite 整数数据类型(如 int、integer、bigint 等)之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sqlite 中整数数据类型的区别是什么?

情报
整数
TINYINT
小智能
中等
BIGINT
未签名的大整数
INT2
INT8

INT
INTEGER
TINYINT
SMALLINT
MEDIUMINT
BIGINT
UNSIGNED BIG INT
INT2
INT8

哪一个可以存储 32 位整数,哪一个可以存储 64 位值?是否支持 128 位?

Which one can store 32-bit integers and which one can store 64-bit values? Is there support for 128-bit?

我现在发现整数数据大小有点混乱,例如 INTEGER 可以存储多达 64 位的有符号整数,但值可能只占用磁盘上的 32 位.

I find integer data size a little confusing for now, INTEGER for example can store up to 64-bit signed integers, but values may occupy only 32 bits on disk.

在 INTEGER 列上调用 sqlite3_column_int 仅当存储的值小于 int32 最大值时才有效,如果更高,它将如何表现?

Calling sqlite3_column_int on an INTEGER column will work only if the value stored is less that int32 max value, how will it behave if higher?

推荐答案

来自 SQLite3 文档:

From the SQLite3 documentation:

http://www.sqlite.org/datatype3.html

大多数 SQL 数据库引擎(除SQLite,据我们所知)使用静态的、严格的类型.带静电类型,一个值的数据类型由它的容器决定——存储值的特定列.

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 使用更通用的动态类型系统.在 SQLite 中,值的数据类型与值本身相关联,而不是与其相关联容器.SQLite 的动态类型系统向后兼容与其他数据库引擎中更常见的静态类型系统用于静态类型数据库的 SQL 语句的意义在 SQLite 中应该以相同的方式工作.但是,动态输入SQLite 允许它做传统上做不到的事情严格类型的数据库.

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.

因此在 MS Sql Server 中(例如),一个int"==integer"==4 字节/32 位.

So in MS Sql Server (for example), an "int" == "integer" == 4 bytes/32 bits.

相比之下,SqlLite整数"可以保存您放入其中的任何内容:从 1 字节字符到 8 字节长.

In contrast, a SqlLite "integer" can hold whatever you put into it: from a 1-byte char to an 8-byte long long.

以上链接列出了所有类型,并提供了有关 Sqlite亲和性"的更多详细信息.

The above link lists all types, and gives more details about Sqlite "affinity".

您所指的 C/C++ 接口必须使用强类型语言.

The C/C++ interface you're referring to must work with strongly typed languages.

所以有两个API:sqlite3_column_int(),最大4-byte;和 sqlite3_column_int64()

So there are two APIs: sqlite3_column_int(), max 4-byte; and sqlite3_column_int64()

http://www.sqlite.org/capi3ref.html#sqlite3_int64

这篇关于SQLite 整数数据类型(如 int、integer、bigint 等)之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆