数据库:
db.execSQL("CREATE TABLE " + TABLE_NAME_NOTE + " ("
+ BaseColumns._ID + " INTEGER PRIMARY KEY,"
+ NoteColumns.TITLE + " NVARCHAR(200),"
+ NoteColumns.NOTE + " TEXT,"
+ NoteColumns.CREATED_DATE + " INTEGER,"
+ NoteColumns.MODIFIED_DATE + " INTEGER,"
+ NoteColumns.TYPE + " INTEGER,"
+ NoteColumns.NEED_NOTICE + " INTEGER,"
+ NoteColumns.NOTICE_WAY + " INTEGER,"
+ NoteColumns.NOTICE_TIME + " INTEGER"
+ ");");
这是我的疑问:
Cursor cursor = mContext.managedQuery(mContext.getIntent().getData(),
NoteEntry.PROJECTION_NOTE,
null, null, NoteColumns.DEFAULT_SORT_ORDER);
当NoteEntry.PROJECTION_NOTE
时,代码正常工作public static final String[] PROJECTION_NOTE = new String[] {
BaseColumns._ID, // 0
NoteColumns.TITLE, // 1
NoteColumns.NOTE };
但是当我设置此
时,我得到“无效的列类型”异常public static final String[] PROJECTION_NOTE = new String[] {
BaseColumns._ID, // 0
NoteColumns.TITLE, // 1
NoteColumns.NOTE,
NoteColumns.CREATED_DATE,
NoteColumns.MODIFIED_DATE,
NoteColumns.TYPE,
NoteColumns.NEED_NOTICE,
NoteColumns.NOTICE_WAY,
NoteColumns.NOTICE_TIME
};
太困惑了。
另一个问题,我应该使用INTEGER类型将Date数据存储为Created_Date字段,sdk中的代码示例。我是sqlite和android的新手
请帮帮我。谢谢。
答案 0 :(得分:1)
将日期也设为 TEXT 类型而不是 INTEGER 类型,因为日期可能包含一些特殊字符。
答案 1 :(得分:0)
“Type”是列名 并发现这种方式解决问题,仍然不明白:
public static final String[] PROJECTION_NOTE = new String[] {
BaseColumns._ID, // 0
NoteColumns.TITLE, // 1
NoteColumns.NOTE,
NoteColumns.CREATED_DATE,
NoteColumns.MODIFIED_DATE,
NoteColumns.TYPE + " as " + NoteColumns.TYPE,
NoteColumns.NEED_NOTICE + " as " + NoteColumns.NEED_NOTICE,
NoteColumns.NOTICE_WAY + " as " + NoteColumns.NOTICE_WAY,
NoteColumns.NOTICE_TIME + " as " + NoteColumns.NOTICE_TIME,
};