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的一个特性.阅读我链接的整个页面,仔细阅读:)

相关文章

以下为个人理解,如错请评 CE: 凭据加密 (CE) 存储空间, 实际路径/data/user_ce/ DE: 设备加密 (DE) 存...
转载来源:https://blog.csdn.net/yfbdxz/article/details/114702144 用EventLog.writeEvent打的日志(或...
事件分发机制详解 一、基础知识介绍 1、经常用的事件有:MotionEvent.ACTION_DOWN,MotionEvent.ACTION...
又是好久没有写博客了,一直都比较忙,最近终于有时间沉淀和整理一下最近学到和解决的一些问题。 最近进...
Android性能优化——之控件的优化 前面讲了图像的优化,接下来分享一下控件的性能优化,这里主要是面向...
android的开源库是用来在android上显示gif图片的。我在网上查了一下,大家说这个框架写的不错,加载大的...