Extract Record components to the corresponding C struct.
For an overview see page QueryResult
Prototype
void extract( Record* rec, void* dst, size_t size, bool nullIndicators[] = NULL, ExtractMode mode = emReferenceToBody);Arguments
rec The Record instance to be extracted dst A pointer to a C struct to receive the database record size The size of the C struct. This must match the size of the database record being extracted nullIndicators An array of Boolean elements that will be set to true
if the corresponding field is null. This array needs to be large enough to collect indicators for all of the records fields. In the case of nested structures, it must contain elements for each field of the nested struct also. If this array is not specified (is NULL) then attempting to extract a NULL value for a scalar field will cause a RuntimeException.mode The mode in which struct components will be extracted. Must be one of the following:
emReferenceToBody
: a pointer to the string body inside the database. Any struct field must have char* elements.emCopyFixedSizeStrings
: copy fixed-size strings. Any struct fields must have char[N] elements where N is the size of the fixed-size string.emCloneStrings
: clone string components. Any struct files must have char* elements. (It is the application’s responsibility to deallocate string bodies (using thedelete[]
operator).Description
This method extracts the Record components to the corresponding C struct. The following rules describe how the C struct is used as the destination data structure:
1. The C struct must have exactly the same components in the same order as the database record.
2. All structure members use default alignment, i.e. the alignment used by the compiler without special alignment pragmas.
3. Array components are represented as a pointer to Array value.
4. String components are stored as null-terminated ANSI strings.
5. If a component of the structure doesn’t belong to any table and is the result of some
select
statement expression calculation, then its type is determined by the following rules:
- integer types (
char
,short
,unsigned short
,int
, etc.) are represented as typeint64_t
- floating point types (
float
,double
) are represented as typedouble
- Other types are represented as they are
6. Nested structures must be represented by the same C struct.
Returns
This method throws a RuntimeException in the case of an error.
Example
Schema snippet: class Person { char<64> name; int4 age; float weight; tree<name> by_name; }; Application snippet: // Define the structure corresponding to database record Person struct _Person { char const* name; int age; float weight; }; void show_results( char * sql) { QueryResult result(engine.executeQuery(sql)); Cursor* cursor = result->records(); while (cursor->hasNext()) { Record* rec = cursor->next(); _Person p; // Extract the Person record to the corresponding struct result->extract(rec, &p, sizeof(p)); printf("\t\t%d) Name=%s, Ordinal=%u\n", count, p.name, p.ordinal ); } }