如果 cursor 为空/null ,我想添加一行。
但是我使用的代码不起作用:(错误:索引 -1 请求大小为 1)
final String query = "SELECT category.CategoryID, " +
"category.Title, category.ParentID " +
" FROM category" +
" WHERE category.Title = '"+ _TopCategory
+"'";
Cursor cursorKayita = db.rawQuery(query, null);
if ( cursorKayita.moveToFirst() ) {
// start activity
} else {
_Categories.put("Title", _TopCategory);
db.insert("category", null, _Categories);
}