Logan Shaw <[EMAIL PROTECTED]> wrote ..
> druid wrote:
> > Yea, but that brings up another question
> > If the structure of a record is actualy a series on
> > teminated strings, when you retrieve records, how do you
> > know the length of any field in that record
>
> You just have to figure out a way to do this yourself.
You mean that a record is not normally just a single string
with delimiters
Like this
size = StrLen(name)+1+ StrLen(level)+1;
index = dmMaxRecordIndex;
h = DmNewRecord(dbPtr, &index, size);
ptr = MemHandleLock(h);
Offset = 0;
DmWrite(ptr, Offset, (const void *)name, StrLen(name)+1);
Offset += StrLen(name)+1;
DmWrite(ptr, Offset, (const void *)level, StrLen(level)+1);
err = DmCloseDatabase(dbPtr);
maybe im doing this all wrong
>
> The most obvious way is to include null characters as
> terminators, then put all the strings in sequence. That
> means you can't access each string with the record
> independently, but that may not be a big problem.
>
> Let's say you wanted to be able to read and write a
> series of strings into a single record. The code might
> look like this:
>
> Int32 SizeNeeded (Char *strings[])
> {
> Char **currentstring;
> Int32 bytesneeded = 0;
>
> for (currentstring = strings;
> *currentstring != NULL;
> currentstring++)
> {
> bytesneeded += 1 + StrLen (*currentstring);
> }
>
> return (bytesneeded);
> }
>
> void WriteStrings (Char *strings[],
> MemPtr storageheapptr, Int32 startoffset)
> {
> Int32 offset = startoffset;
>
> for (currentstring = strings;
> *currentstring != NULL;
> currentstring++)
> {
> DmWrite (storageheapptr, offset,
> (void *) *currentstring, 1 + StrLen (*currentstring));
> offset += 1 + StrLen (*currenstring);
> }
> }
>
> Then, you'd call SizeNeeded() to figure out how big of a record to
> create (or how big to resize a record to, if you're re-writing an
> existing record) and afterwards call WriteStrings() to actually
> write them.
>
> Reading is similar to writing. If you want to be lazy (and not
> check for records that were truncated in the middle of a string),
> you can call StrLen() directly on a pointer into the record, since
> the storage heap is addressable memory, and then you can call
> StrCopy() to copy directly from the record to some memory you
> allocated using MemPtrNew() or something. Or, if you only need
> the strings for a short time (while you still have the DB record
> locked), you could even just compute pointers into the record
> itself. That is, you could fill the strings[] argument with
> pointers into the storage heap. That method could be error prone
> if the caller doesn't realize that the pointers may become invalid
> once the record is unlocked, but it could be useful in some cases
> (such as if you are sorting the database, and you need speed,
> or something like that).
>
> - Logan
>
> --
> For information on using the PalmSource Developer Forums, or to unsubscribe,
> please
> see http://www.palmos.com/dev/support/forums/
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/