Troubles Creating a View Within a View

ohthepain <[email protected]> Tue, 10 Dec 2013 10:32:41 -0800 (PST)
Newsgroups gmane.comp.db.metakit
Message-ID <[email protected]>
I am having trouble trying to persist the data in a view within a view. 

I am trying to create a set of key/value stores, or 'blobs'. My db format string is 
   blobs[key:S,blob[key:S,value:S]]
which is supposed to mean a view of views of key/value pairs. 

The code below is a simple repro of the bug I am trying to fix. Basically, the second time I run this method I expect to find a value at in the view. 

The blob does get read from disk. So, the second time I run my app the first Find call does find the blob row. But the view in that row is always empty, and the second .Find call always returns -1.

Thanks in advance for any help here. I realize that this is an old forum.
p

	c4_Storage database("myfile4.dat", true);
	c4_StringProp pKey("key");
	c4_StringProp pValue("value");
	c4_LongProp pGuid("id");
	c4_ViewProp vpBlob("blob");
	
	c4_View vBlobs = database.GetAs("blobs2[key:S,blob[key:S,value:S]]");
	
	// Find the blob row
	int index = vBlobs.Find(pKey["blob1"]);
	if (index == -1)
	{
		c4_Row row;
		pKey(row) = "blob1";
		vpBlob(row) = c4_View();
		index = vBlobs.Add(row);
		database.Commit();
	}
	
	c4_Row blobRow = vBlobs[index];
	const char* oldkey = pKey(blobRow);
	assert(!strcmp(oldkey, "blob1"));
	c4_View vBlob = vpBlob(blobRow);
	
	// Check the view value
	index = vBlob.Find(pKey["key1"]);
	if (index == -1)
	{
		// Not found - create the value
		c4_Row row;
		pKey(row) = "key1";
		pValue(row) = "value1";
		index = vBlob.Add(row);
		database.Commit();
	}