android – 带整数列的SQLite表存储字符串

前端之家收集整理的这篇文章主要介绍了android – 带整数列的SQLite表存储字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在申请中发现了一些东西.我创建了一个包含名为type的列的表,它应该存储整数:
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));

但不知何故,我总是将字符串存储在其中而没有任何问题(似乎我忘了这个专栏是用于整数).还可以使用查询读取字符串.这个列的动态“类型转换”是sqlite的一个特性吗?

解决方法

here开始:

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.

所以是的,这是sqlite的一个特性.阅读我链接的整个页面,仔细阅读:)

原文链接:https://www.f2er.com/android/317227.html

猜你在找的Android相关文章