Easy method for appending to record

7 views
Skip to first unread message

Elliot Saba

unread,
Nov 25, 2013, 6:36:27 PM11/25/13
to hamster...@googlegroups.com
Hello, is this the recommended way to append data to a record:

1) Find the entry with ham_cursor_find() with rec set to NULL, so that data is not read in.
2) Get the size of the record with ham_cursor_get_record_size()
3) Write to the record via ham_insert with the flags HAM_PARTIAL and HAM_OVERWRITE with the rec.size member set larger than the size returned by step #2

I couldn't find much information in the documentation about this, and was surprised that if I didn't pass in a larger rec.size when overwriting a record that my input would be truncated.  (This is what I understood from the "Working with partial access" wiki page)

Is this the generally accepted way to grow records?
Thank you!
-E

Christoph Rupp

unread,
Nov 26, 2013, 1:32:58 AM11/26/13
to hamster...@googlegroups.com
Hi Elliot,

even if you do a partial insert you have to specify the FULL record size in rec.size, and not change it in the following (partial) updates. hamsterdb will reserve enough space in the file for your record, and initialize all "gaps" with zeroes. If you would increase the record size then you would exceed the limits of this space.

So either your rec.size always has the same (final) record size, or you can use ham_cursor_overwrite to replace the record with a bigger one.

Here are code samples and tests for partial reads/writes, maybe they're helpful:
https://github.com/cruppstahl/hamsterdb/blob/master/unittests/partial.cpp

bye
Christoph



2013/11/26 Elliot Saba <stati...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "hamsterdb User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hamsterdb-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages