SQLite表整数列中存储字符串 [英] SQLite table with integer column stores string

查看:118
本文介绍了SQLite表整数列中存储字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些weired在我的应用程序。我创建了一个名为列类型的表应当存储整数:

I found something weired in my application. I created a table with a column named type which should store integers:

db.execSQL("CREATE TABLE " + CellColumns.TABLE + " ("
    + CellColumns._ID + " INTEGER PRIMARY KEY,"
    + CellColumns.TYPE + " INTEGER," // <-- this
    + CellColumns.CELL_ID + " INTEGER,"
    + CellColumns.CITY_ID + " INTEGER,"
    + CellColumns.LOAD + " INTEGER,"
    + CellColumns.ORIENTATION + " INTEGER);");

阅读:

String type = c.getString(c.getColumnIndex(CellColumns.TYPE));

但不知何故,我总是存储字符串到它没有任何问题(看来我忘了,这个专栏是为那些整数)。同时读取与查询作品的字符串。这是动态的类型转换一栏的源码的功能吗?

But somehow I always store strings into it without any problems (seems I forgot that this column was meant for integers). Also reading the strings with a query works. Is this dynamic "type cast" of a column a feature of sqlite?

推荐答案

这里

大多数SQL数据库引擎(比SQLite的每一个SQL数据库引擎等,据我们所知)使用静态,僵化的类型。有了静态类型,值的数据类型是由它的容器决定 - 在该值存储在特定列

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.

所以,是的,这是源码的一个特点。阅读整页我联系,并仔细阅读:)

So yes, this is a feature of sqlite. Read the whole page I linked, and read carefully :)

这篇关于SQLite表整数列中存储字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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