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 typing in sqlite allows it to do things which are not possible in traditional rigidly typed databases.
我有两个问题:
解决方法
根据sqlite网站,他们已经完成了“为了最大限度地提高sqlite和其他数据库引擎之间的兼容性”. (见上面的链接)
sqlite supports the concept of “type affinity” on columns. The type affinity of a column is the recommended type for data stored in that column. The important idea here is that the type is recommended,not required. Any column can still store any type of data. It is just that some columns,given the choice,will prefer to use one storage class over another. The preferred storage class for a column is called its “affinity”.
我的理解是,sqlite正是它的命名 – 一个非常轻量级的简约数据库引擎.与强类型相关联的开销可能超出了项目的范围,最好留给使用sqlite的应用程序.
但是再次,根据他们的网站,他们已经做到了这一点,以最大限度地发挥与其他DB引擎的兼容性.