SQLite.insert返回-1,但数据插入到数据库 [英] SQLite.insert return -1 but data inserted into database
问题描述
我有这样一个方法:
protected long put(String tableName, ContentValues values) {
SQLiteDatabase db = (!mInTransaction) ? mHelper.getWritableDatabase() : mDb;
long success = db.insert(tableName, null, values);
return success;
}
该方法返回-1,但数据插入到数据库中。我检查了我的数据,它的确定。任何人都可以帮助我:(
This method return -1 but data inserted into database. I checked my data, it's ok. Anybody can help me :(
这是我的表:
CREATE TABLE选择(category_no INTEGER NOT NULL,subcategory_no INTEGER NOT NULL,quiz_no INTEGER NOT NULL,choice_no INTEGER NOT NULL,回答TEXT NOT NULL,CONTENT_ID INTEGER NOT NULL,PRIMARY KEY(category_no,quiz_no,choice_no));
CREATE TABLE choices ( category_no INTEGER NOT NULL, subcategory_no INTEGER NOT NULL, quiz_no INTEGER NOT NULL, choice_no INTEGER NOT NULL, answer TEXT NOT NULL, content_id INTEGER NOT NULL, PRIMARY KEY ( category_no, quiz_no, choice_no ) );
推荐答案
1
如果发生错误,则返回。 .insert(...)
返回新插入的记录的行ID。这是重要的?你有 _id
在你的数据库字段?
-1
is returned if error occurred. .insert(...)
returns the row id of the new inserted record. Is this important? Do you have _id
field in your db?
这篇关于SQLite.insert返回-1,但数据插入到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!