我正在编写一个android应用程序,进行一些sqllite处理。 这是我的表创建语句。
TABLE_CREATE_REVOKED_TOKENS = "CREATE TABLE IF NOT EXISTS " + TABLE_REVOKED_TOKENS + " (";
TABLE_CREATE_REVOKED_TOKENS += "resource varchar(20) NOT NULL,";
TABLE_CREATE_REVOKED_TOKENS += "base int(11) NOT NULL,";
TABLE_CREATE_REVOKED_TOKENS += "delta int(11) NOT NULL,";
TABLE_CREATE_REVOKED_TOKENS += "data blob NOT NULL,";
TABLE_CREATE_REVOKED_TOKENS += "PRIMARY KEY (resource, base, delta));";
表格中有以下数据。
resource base delta data
"Safe 1" "1" "0" "�<]FSb>�/���Z���d�J�"����E�"
"Safe 1" "1" "1" "�������.���V�����X ��wE���"
当我尝试在表格中插入新行时。我得到以下异常。
Error inserting data=[B@41a99f98 base=1 resource=Safe 1 delta=2
android.database.sqlite.SQLiteConstraintException: columns resource, base, delta, data are not unique (code 19)
这是插入语句的代码。
private int insertNewRevocationList(RevocationList rl) {
String TABLE = TABLE_REVOKED_TOKENS;
ContentValues initialValues = new ContentValues();
initialValues.put("resource", new String(rl.getResource()));
initialValues.put("base", rl.getBase());
initialValues.put("delta", rl.getDelta());
initialValues.put("data", rl.getData());
Log.d(TAG, "create new entry for:");
Log.d(TAG, "resource: " + new String(rl.getResource()) + "\tbase: " + rl.getBase() + "\tdelta: " + rl.getDelta());
return (int) getDb().insert(TABLE, null, initialValues);
}