我的数据库中有一个整数列,我希望得到它的值。使用query()方法,getType()返回3(字符串类型),getInt()返回的数字范围为19-21
String[] columns = {EpisodeEntry.EPISODE_ID, EpisodeEntry.TITLE,
EpisodeEntry.DESCRIPTION, EpisodeEntry.PUB_DATE,
EpisodeEntry.DURATION, EpisodeEntry.LISTENED,
EpisodeEntry.CURRENT_TIME};
Cursor cursor = database.query(EpisodeEntry.TABLE_NAME, columns,
EpisodeEntry.DIRECTORY + " = \"" + directory + "\"",
null, null, null, null);
Log.d("sw9", "DB CURRENT TIME TYPE: " +
cursor.getType(cursor.getColumnIndex(EpisodeEntry.CURRENT_TIME)));
使用rawQuery()方法,游标返回1(整数类型),getInt()返回正确的数字。
Cursor cursor = database.rawQuery("SELECT * FROM episode WHERE directory = '"
+ directory + "'", null);
Log.d("sw9", "DB CURRENT TIME TYPE: " +
cursor.getType(cursor.getColumnIndex(EpisodeEntry.CURRENT_TIME)));
rawQuery()方法是正确的,但我不知道为什么query()方法不正确。有人能说清楚这个吗?
我最好使用rawQuery()来避免这样的问题吗?问题是我的错(很可能)还是Androids错(不太可能)?
编辑:嗯所以我把它隔离到* vs命名列:
返回错误值“14”:
Cursor cursor = database.rawQuery("SELECT " + EpisodeEntry.EPISODE_ID + ", " +
EpisodeEntry.TITLE + ", " +
EpisodeEntry.DESCRIPTION + ", " + EpisodeEntry.PUB_DATE + ", " +
EpisodeEntry.DURATION + ", " + EpisodeEntry.LISTENED + ", " +
EpisodeEntry.CURRENT_TIME + " FROM episode WHERE directory = \""
+ directory + "\"", null);
返回正确的值:
Cursor cursor = database.rawQuery("SELECT * FROM episode WHERE directory = \""
+ directory + "\"", null);
架构:
private static final String SQL_CREATE_EPISODE =
"CREATE TABLE " + EpisodeEntry.TABLE_NAME + " (" +
EpisodeEntry.EPISODE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
EpisodeEntry.TITLE + TEXT_TYPE + COMMA_SEP +
EpisodeEntry.DESCRIPTION + TEXT_TYPE + COMMA_SEP +
EpisodeEntry.ENCLOSURE + TEXT_TYPE + " UNIQUE" + COMMA_SEP +
EpisodeEntry.PUB_DATE + TEXT_TYPE + COMMA_SEP +
EpisodeEntry.DURATION + TEXT_TYPE + COMMA_SEP +
EpisodeEntry.GUID + TEXT_TYPE + COMMA_SEP +
EpisodeEntry.DIRECTORY + TEXT_TYPE + COMMA_SEP +
EpisodeEntry.LISTENED + " INTEGER" + COMMA_SEP +
EpisodeEntry.CURRENT_TIME + " INTEGER" +
");";