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的一个特性吗?
解决方法
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.