This project has moved and is read-only. For the latest updates, please go here.

JetUpdate bookmark size makes no sense

Mar 8, 2014 at 6:54 AM
I don't understand how this can happen...

int bookmarkSize = 4;
byte[] bookmark = new byte[bookmarkSize];
int outBookmarkSize = 0;
Api.JetUpdate(sesid, tableid, bookmark, bookmarkSize, out outBookmarkSize);
Debug.Assert(outBookmarkSize <= bookmarkSize);

Sometimes, that assert fires.
In that case, outBookmarkSize == 5.
How can it be bigger than my byte[] ?

I was expecting it to throw EsentBufferTooSmallException.

Did I misunderstand how Api.JetUpdate works?
Mar 19, 2014 at 12:01 AM
It doesn't even return a warning.
It returns the size of the actual bookmark, and copies what it can in to the byte array.
If the returned bookmark size is larger than your buffer, then the bookmark will be truncated, with no error or warning.


-martin
Mar 19, 2014 at 12:12 AM
Is a truncated bookmark useful for anything? I'm guessing not.

Since the update has actually occurred, I can't reallocate and try again.
And there is apparently no way for me to know in advance the size I need to allocate.
Is there a maximum size that I can allocate my byte array? Some number that I can be sure will be big enough?
Mar 21, 2014 at 2:28 AM
Any simple type (except maybe GUID) that is <= 8 or < 16 or so bytes should be 1 byte larger than the native type.

For variable/tagged binary we insert a discriminator byte every few bytes. This is an implementation detail, and is subject to change.

Unicode data explodes when it's normalized (could be 5x the original string size).

-martin
Marked as answer by ptousig on 3/20/2014 at 11:59 PM