我正在尝试从我在 android 上使用自动增量创建的 sql 表中检索行 ID (_id) 我可以看到表中除主键字段之外的所有其他字段。这个 id 是表的代码:
public static final String ID = "_id";
public static final String JOKE = "Joke";
public static final String AUTHOR = "Author";
public static final String DATE = "Date";
public static final String STATUS = "Status";
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " ( "
+ ID + " INTEGER PRIMARY KEY AUTOINCREMENT , "
+ JOKE + " TEXT, "
+ AUTHOR + " TEXT, "
+ DATE + " DATE, "
+ STATUS + " TEXT "
+ ")");
}
当我尝试接收字段索引时,我收到字段 ID 的 -1
Cursor cur = context.getContentResolver().query(MyContentProvider.CONTENT_URI, null, null, null, null);
if (cur.moveToFirst()) {
int idColumn = cur.getColumnIndex("_id");
int authorColumn = cur.getColumnIndex("Author");
int statusColumn = cur.getColumnIndex("Status");
int dateColumn = cur.getColumnIndex("Date");
我可以看到所有其他字段的索引,但关键字段 (_id) 任何人都可以帮助我吗?