Persistance Problems with View Within a View

ohthepain <[email protected]> Tue, 10 Dec 2013 14:21:42 -0800 (PST)
Newsgroups gmane.comp.db.metakit
Message-ID <[email protected]>
Sorry, if this is a repost, but I don't see my last post.

I am trying to create a view within a view, but only the outer view seems to get loaded from disk. 

I have reduced my code to a simple example. The example checks to see if the blob is there, and creates it otherwise. Then it checks to see if a value is in the subview, and creates it otherwise. 

The first Find() call command does find the blob but the view 'vBlob' is always empty, so the second Find() call always fails.

I tried running 'strings myfile4.dat' and got
Tblob1
blobs[key:S,blob[key:S,value:S]]

Any idea what I am doing wrong?


	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();
	}