Using _Rreadk with PFs having multiple key fields defined

Patrik Schindler <[email protected]> Sat, 13 Aug 2022 17:22:08 +0200
Newsgroups gmane.comp.lang.as400.c
Message-ID <[email protected]>
Hello,

I'm contemplating on the most efficient, and least error-prone way to handle database reads with multiple key fields. Goals are: Avoid copying data, use pointers to existing variables whenever possible. Avoid hard coding field sizes. These should be derived at compile time, if possible. If not, they should be derived at most once in the code flow.

Because we're talking CL environment here, I assume all strings to be fixed-length, no zero-termination. Correct?
I need to gather the necessary data for the desired key values and copy those to the proper relative positions reflecting the key field positions within one big buffer for _Rreadk. Is this how multiple key fields work? I haven't found examples. Not in the net, not in the documentation PDFs.

One can include "key" as flag when referring to external defined files with #pragma mapinc. This results in a "_Packed struct" being defined for all key fields of the file in question. I was trying to typecast a char pointer to a variable of this type "_Packed struct …", but the compiler disallows this.

At the moment, I'm thinking about using hard coded sizeof() calls for each key field, to get a sum for malloc()ing the mentioned big _Rreadk key buffer. And defining individual character pointer variables using pointer arithmetic with the derived field lengths to the proper key field positions within this big buffer.

Did you use multiple-key PFs with _Rreadk? How did you handle the proper assembly of the buffer with the key-values? How did you automatically deduct the proper size of the (key) fields for assembly of that one big buffer?

What's your opinion?

:wq! PoC

-- 
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/c400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/c400-l.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com