SQLite

Ticket Change Details
Login
Overview

Artifact ID: a4e8662c091d4f8c1e03192c03f7cf3158aa7a0ed20072584bd36899fd6c127d
Ticket: 8897054d959750c9cb3c9a1d4da762cb2a956f7c
lsm1 does not overwrite values for duplicate keys
User & Date: anonymous 2017-08-14 14:02:50
Changes

  1. foundin changed to: "3.20.0"
  2. icomment:
    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);
    }
    
  3. login: "anonymous"
  4. mimetype: "text/plain"
  5. private_contact changed to: "ccff8adb4b80590cdec7e0c8c2b35729c408fb35"
  6. severity changed to: "Severe"
  7. status changed to: "Open"
  8. title changed to: "lsm1 does not overwrite values for duplicate keys"
  9. type changed to: "Code_Defect"