I must produce a table to keep device configurations. The table has three rows: id, parameter_title and parameter_value.

The table was produced by performing the next query statement:

DATABASE_CREATE = "create table DATABASE_TABLE (KEY_ID INTEGER PRIMARY KEY AUTOINCREMENT, KEY_NAME INTEGER not null, VALUE TEXT not null);

and so the rows are saved by performing the next method:

private long insertRow(int rowParameter, String rowValue, SQLiteDatabase db){
	long res = -1;
	ContentValues settingsParameterValues = new ContentValues();
	settingsParameterValues.put(KEY_NAME, rowParameter);
	settingsParameterValues.put(VALUE, rowValue);
	if(db != null){
		res = db.insert(DATABASE_TABLE, null, settingsParameterValues);
	}
	return res;
}

Once the database is produced the default values are saved:

@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE);
		insertRow(PRIVACY_LEVEL_ROW_INDEX, "0", db);
		insertRow(STREAM_TITLE_ROW_INDEX, "untitled", db);
		insertRow(STREAM_TAGS_ROW_INDEX, "", db);
	}

The issue with method insertRow() however is it can't prevent copying the records.

Does anybody understand how to prevent duplicate records within this situation?

Thanks!

You can use the column constraint [cde].

The Initial constraint causes a special index to become produced around the specified posts.

I'd produce a UNIQUE CONSTRAINT within the database table definition. Which will instantly prevent duplicate records and it is virtually the only real concurrency-safe method of doing it!

Also, remember about CHECK CONSTRAINT which might be more useful if you want to define more complicated rules for that data in your soul tables.

Are you currently attempting to prevent it through code, or perhaps in the database?

If attempting to prevent from code you will need to perform a Choose if the row already is available.

If attempting to prevent it in the database you will need to give a UNIQUE constraint on whichever row you won't want to allow replicates on.

Inside your situation, the right primary key could have been UNIQUE.