sqlite 中的字符串数据类型

标签 string sqlite types

我创建了一个表如下:

create table employers (
    id integer primary key,
    name string,
    surname string,
    description string
);

我注意到了 here string 不在数据类型之间,我应该用其他东西替换它吗?它是其他数据类型的别名吗?这个字符串最多可以包含多少个字符?

我使用了 string 并且它没有产生任何问题。我只感兴趣怎么可能,我可以使用 string.是别名吗?这种类型的可能性有哪些?

谢谢

最佳答案

您想使用 TEXT,我们会根据需要使用它来保存您的数据。

CREATE TABLE Employers (
    id INTEGER PRIMARY KEY,
    name TEXT,
    surname TEXT,
    description TEXT
);

参见 http://www.sqlite.org/datatype3.html 并注意:

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.

指出:

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.

最后:

Maximum length of a string or BLOB

The maximum number of bytes in a string or BLOB in SQLite is defined by the preprocessor macro SQLITE_MAX_LENGTH. The default value of this macro is 1 billion (1 thousand million or 1,000,000,000). You can raise or lower this value at compile-time using a command-line option like this:

-DSQLITE_MAX_LENGTH=123456789 The current implementation will only support a string or BLOB length up to 231-1 or 2147483647. And some built-in functions such as hex() might fail well before that point. In security-sensitive applications it is best not to try to increase the maximum string and blob length. In fact, you might do well to lower the maximum string and blob length to something more in the range of a few million if that is possible.

During part of SQLite's INSERT and SELECT processing, the complete content of each row in the database is encoded as a single BLOB. So the SQLITE_MAX_LENGTH parameter also determines the maximum number of bytes in a row.

The maximum string or BLOB length can be lowered at run-time using the sqlite3_limit(db,SQLITE_LIMIT_LENGTH,size) interface.

关于sqlite 中的字符串数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6115212/

相关文章:

sqlite - 在几列上使用MAX()获得整行

javascript - 如何在 Angular 表达式中获取一种范围变量?

python - 使用至少 n 个空格拆分字符串

c - 如何使用低级 write() 函数将字符串写入文件?

python - Python中数据库数据的数组

PHP 错误信息 : Fatal error: Call to a member function bindParam() on a non-object

types - 为什么 IEEE754 单精度 float 只有 7 位精度?

c# - C# 中的全局类型别名

java - 替换特定模式中的字符或特定字符之后的字符

python - 在阿拉伯语中查找两个子字符串之间的字符串