问题:在数据库中新添加了一条数据,如何获取这条新添加数据的KEY_ID?
long lRes = mSqLiteDatabase.insert(DB_TABLE, KEY_ID, cv);
if (lRes == -1)
{
Log.e(TAG, "insert data error!!!");
return;
}
// TODO "select last_insert_rowid;" ??????
Cursor cur = mSqLiteDatabase.rawQuery("SELECT " + KEY_ID + " from " + DB_TABLE + " WHERE rowid = " + Long.toString(lRes), null);
if (cur != null && cur.getCount() > 0)
{
cur.moveToFirst();
item.nID = cur.getInt(cur.getColumnIndex(KEY_ID));
cur.close();
}