SQLite

View Ticket
Login
Ticket Hash: 8897054d959750c9cb3c9a1d4da762cb2a956f7c
Title: lsm1 does not overwrite values for duplicate keys
Status: Closed Type: Code_Defect
Severity: Severe Priority: Immediate
Subsystem: Extensions Resolution: Works_As_Designed
Last Modified: 2017-08-14 14:44:53
7.73 years ago
Created: 2017-08-14 14:02:50
7.73 years ago
Version Found In: 3.20.0
User Comments:
anonymous added on 2017-08-14 14:02:50:
In the lsm1 extension, lsm_insert(): insert a new key/value pair into the database, overwriting any existing entry with the same key (https://sqlite.org/src4/doc/trunk/www/lsmusr.wiki#writing_to_a_database), When I tried to test this case (insert existing entry with the same key) the database size increasing without overwriting any existing entry with the same key. The below test c code illustrate the case:

void test(void)
{
	lsm_db *db;
	int rc = lsm_new(0, &db);
	if( rc != LSM_OK )
		return;

	rc = lsm_open(db, "test.lsmdb");
	if( rc != LSM_OK )
		return;

	DWORD Key = 0x12345678;
	char Val_1[] = "12345678";
	char Val_2[] = "ABCDEFGH";

	lsm_begin(db, 1);

	lsm_insert(db, (void *)&Key, sizeof(Key), Val_1, strlen(Val_1)+1);

	// below insert should update the same key with a new value
	lsm_insert(db, (void *)&Key, sizeof(Key), Val_2, strlen(Val_2)+1);

	lsm_commit(db, 0);

	lsm_cursor *csr;
	if( lsm_csr_open(db, &csr) != LSM_OK )
		return;

	int seekrc = lsm_csr_seek(csr, &Key, sizeof(Key), LSM_SEEK_EQ);
	int validrc = lsm_csr_valid(csr);
	if( seekrc == LSM_OK && validrc )
	{
		char *pKeyPtr, *pValPtr;
		int nKey, nVal;
		lsm_csr_key(csr, (const void **)&pKeyPtr, &nKey);
		lsm_csr_value(csr, (const void **)&pValPtr, &nVal);

		// the below printf will display the old value rather than new updated value
		printf("key = %08X, val = %s\n", pKeyPtr, pValPtr);
	}
	lsm_csr_close(csr);

	lsm_close(db);
}