unqlite icon indicating copy to clipboard operation
unqlite copied to clipboard

read/write offset

Open laurentcau opened this issue 3 years ago • 2 comments

Hi,

That would be very very very helpful for us to have read and write (unqlite_kv_store/unqlite_kv_fetch) with dataoffset to partial update data or partial read. Do you think it's doable ?

laurentcau avatar Jan 26 '22 16:01 laurentcau

Hi Laurent,

You can easily achieve this by relying on unqlite_kv_fetch_callback() for extracting offseted data inside your callback function, and using unqlite_kv_append() instead of unqlite_kv_store() to append/update your data.

symisc avatar Jan 27 '22 00:01 symisc

No, I don't think this API allow what I need. Here is small example:

struct SHeader
{
	int value0;
	int value1;
};

struct SData
{
	SHeader header;
	const char buffer[1024*1024*1024];
};

SData data;
unqlite_kv_store(pDb,"key0",4, &data.header, sizeof(data.header));
unqlite_kv_happend(pDb,"key0",4, data.buffer, sizeof(data.buffer));

Later I just need to increment value1 of the header. (For example you want to save an access counter.) with offset API I would do:

int value1=0;
unqlite_kv_fetch(pDb,"key0",4, &value1, sizeof(value1), offsetof(SHeader, value1) );
value1++;
unqlite_kv_store(pDb,"key0",4, &value1, sizeof(value1), offsetof(SHeader, value1) );

How would you do with the current API ? You can use unqlite_kv_fetch_callback() to get the beginning of the Value. But if I place the header at the end of the value, I need to loop many times with the call back to retrieve the data I need. But there is no way to write a small part, so, in fact you need to read all the data (GB in this case), make the change and write them back.

You can find other example if you think about implementing a file system. I think a "seek" function is a must have for such application. I don't see how you could implement that with the current API.

laurentcau avatar Jan 27 '22 09:01 laurentcau