/* **----------------------------------------------------------------------------* ** ** MODULE: CDD$BUFFER_EXAMPLE.C ** **----------------------------------------------------------------------------* ** ** Copyright Oracle Corporation 1995. All rights reserved. ** **----------------------------------------------------------------------------* ** ** Functional Description: ** ** This module is provided by Oracle CDD/Repository as an example of ** how to write the code for a call to the MCS_scan_query routine. The ** MCS_scan_query routine is documented in the Oracle CDD/Repository ** Callable Interface Manual. ** ** This module shows how to define and initialize various buffers (i.e. ** parameters) used by MCS_scan_query, and how to pass those buffer as ** parameters to that routine. ** ** Note, in order for this module to actually work, additional code ** must be written, specific to your repository. This module is ** commented below to show where this code should be included. See ** the comments referring to starting and ending the session, starting ** and ending the transaction, processing the elements found by the ** query, etc. ** ** Once your site-specific code is written, you would compile and link ** this module as follows: ** ** CC CDD$BUFFER_EXAMPLE ** LINK CDD$BUFFER_EXAMPLE,SYS$LIBRARY:MCSRTL.OLB/LIBRARY ** ** With the DEC C compiler, you may have to compile as follows: ** ** CC/UNDEFINE=VMS CDD$BUFFER_EXAMPLE ** **----------------------------------------------------------------------------* */ /* ** ** INCLUDE FILES ** */ #include #include #include #include #include #include #include /* ** ** MACRO DEFINITIONS ** */ #define ZERO_BUF( buf_addr, data_size ) \ memset( buf_addr, 0, sizeof( data_size ) ); #define INITIAL_SIZE 1 #define SIZE_INCREMENT 2 /* ** ** FUNCTION PROTOTYPES ** */ void memcpy (); int strncmp (); /* ** ** MAIN PROGRAM ** */ main () { struct _QueryHeader { struct _header { char begin; unsigned long int buffer_type; unsigned long int major_version; unsigned long int minor_version; } header; struct _handle { char the_handle; MCS_ELEMENTID elmid; char within_exp; } handle; } QueryHeader; struct _QueryFooter { char theend; char eoc; } QueryFooter; struct _QueryRelationship { char identifier; unsigned long int protocol; unsigned long int version_major; unsigned long int version_minor; } Relation1, Relation2; struct _QueryTarget { char identifier; unsigned long int protocol; unsigned long int version_major; unsigned long int version_minor; } Target; struct _QueryBlock { char query; } Query; struct _QueryWithinCondition { char relational_op; struct _AttributeProtocol { char identifier; unsigned long int protocol; } Attribute; struct _SimpleLiteral { char identifier; char tipo; unsigned short int length; } SimpleLiteral; } WithinCondition; MCS_VALUE QueryScan, QueryOutputList; MCS_STATUS MyStatus; MCS_ELEMENTID StartingElementId, QueryElmId, RelationId; MCS_STRING OwningType, EntityType, RelationType; MCS_STRINGDSC QueryBuffer; MCS_LONGINT jj, ii; MCS_LONGINT initial_size = INITIAL_SIZE; MCS_LONGINT size_increment = SIZE_INCREMENT; MCS_VALUE MyBlock; char tmp_string[200], QueryString[3000], LiteralString[200]; /* ** Start an Oracle CDD/Repository session. */ /* ** Start a transaction. */ /* ** Load up the Header Block */ QueryHeader.header.begin = cdd$k_begin; QueryHeader.header.buffer_type = cdd$k_dictionary_within_query; QueryHeader.header.major_version = 1; QueryHeader.header.minor_version = 0; QueryHeader.handle.the_handle = cdd$k_start_element_hndl; QueryHeader.handle.elmid = StartingElementId; QueryHeader.handle.within_exp = cdd$k_within_exp; memcpy (tmp_string, &QueryHeader, sizeof(struct _QueryHeader)); for (ii = 0; ii < sizeof(struct _QueryHeader); ii++) { QueryString[ii] = tmp_string[ii]; } jj = ii; /* ** Load up the Relation Block */ if (strncmp (OwningType, "1", 1) == 0) { Relation1.identifier = cdd$k_owning_relationship; } else { Relation1.identifier = cdd$k_owning_closure; } if (strncmp (RelationType, "1", 1) == 0) { Relation1.protocol = cdd$k_rel_da_contains; } else { Relation1.protocol = cdd$k_rel_composite_part; } Relation1.version_major = 1; Relation1.version_minor = 0; memcpy (tmp_string, &Relation1, sizeof(struct _QueryRelationship)); for (ii = 0; ii < sizeof(struct _QueryRelationship); ii++) { QueryString[jj + ii] = tmp_string[ii]; } jj = jj + ii; /* ** Load up the Target Block */ Target.identifier = cdd$k_entity; if (strncmp (EntityType, "1", 1) == 0) { Target.protocol = cdd$k_ent_data_element; } else if (strncmp (EntityType, "2", 1) == 0) { Target.protocol = cdd$k_ent_data_aggregate; } else { Target.protocol = cdd$k_any; } Target.version_major = 1; Target.version_minor = 0; memcpy (tmp_string, &Target, sizeof(struct _QueryTarget)); for (ii = 0; ii < sizeof(struct _QueryTarget); ii++) { QueryString[jj + ii] = tmp_string[ii]; } jj = jj + ii; /* ** Load up the End Block */ QueryFooter.theend = cdd$k_end; QueryFooter.eoc = cdd$k_eoc; memcpy (tmp_string, &QueryFooter, sizeof(struct _QueryFooter)); for (ii = 0; ii < sizeof(struct _QueryFooter); ii++) { QueryString[jj + ii] = tmp_string[ii]; } jj = jj + ii; QueryString[jj] = '\0'; /* ** Create a stringDSC to store the FirstQuery Buffer */ QueryBuffer.LENGTH = jj; QueryBuffer.CLASS = MCS_DSC_CLASS_S; QueryBuffer.DTYPE = MCS_DSC_DTYPE_T; QueryBuffer.POINTER = QueryString; /* ** Perform the Query */ MyStatus = MCS_scan_query (&QueryScan, &StartingElementId, (char*) &QueryBuffer); while( (MyStatus = MCS_scan_getNext(&QueryScan, &QueryElmId, &RelationId)) == MCS_SUCCESS ) { /* ** Process each element found by the query */ } /* ** End the transaction */ /* ** Terminate the Oracle CDD/Repository session. */ return (MyStatus); }