edmiExecuteQuery

EdmiError edmiExecuteQuery(SdaiModel       modelId,
                            SdaiQuery       queryId, 
                            SdaiInteger     arguments, 
                            SdaiInteger     options, 
                            SdaiQueryResult *queryResult, 
                            /* For each query argument: 
                            [SdaiPrimitiveType argumentDataType, 
                              value] */ 
                            ... ); 

Invokes the specified EDMquery with the specified arguments on the specified data model. An EDMquery is defined in an EDMquerySchema. An EDMquerySchema is defined in an EDMdatabase by the edmiDefineQuerySchema operation. The execution of an EDMquery is fully performed by the EDMexpressVM. The result of the EDMquery is returned to the caller. The data required to hold the result data is allocated by the edmiExecuteQuery operation. The operation edmiFreeQueryResult should be invoked by the calling application to free the result data when it is no longer needed. The result of this operation will be returned as a struct named SdaiQueryResult. See the include file sdai.h for detailed description of this struct The actual data model must be open before this operation can be successfully performed. If the query is supposed to update the model, the model must be opened for read and write access. See sdaiOpenModel or sdaiOpenModelBN for details. Powerful trace mechanisms are available for testing and debugging through the "expressions logging", see: edmiDefineExpressionsLog It is recommended to use the EDMsupervisor and the interactive EDMdebugger to test and debug all Express and Express-X schemata executed by the EDMexpressVM, including EDMquery.

 

Arguments


TypeNameComment
SdaiModel

modelId

A numeric modelID that uniquely identifies the data model in the EDMdatabase to run the specified EDMquery on. The modelID is returned when the model is created or it can be retrieved by the following operations: edmiGetModel , edmiGetModelBN and sdaiGetInstanceModel

SdaiQuery

queryId

A numeric queryId that uniquely identifies the EDMquery of interest in the EDMdatabase .

SdaiInteger

arguments

Number of arguments supplied to the actual EDMquery function. This number should correspond to signature of the actual EDMquery function, i.e., the <arguments> should correspond to the number of formal parameters in the actual EDMquery function declaration in the EDMquerySchema.

SdaiInteger

options

Specifies the options to be used in the invocation of the EDMquery function. The <options> value can be specified as a bitwise OR between the actual options to enable. All option names are defined on the header file sdai.h . See detailed descriptions of the available options below.

SdaiQueryResult

queryResult

Address of a variable that will receive the result of the operation. The received result will be of data type SdaiQueryResult.

 

argument_values

For each arguments the following pair of data must be supplied:

  1. <dataType> : The data type (SdaiPrimitiveType) of the argument. The legal data type of an argument is specified in the signature of the actual EDMquery function.  Legal data types are:
    sdaiINTEGER, sdaiREAL, sdaiSTRING, sdaiAGGR, sdaiINSTANCE, sdaiBOOLEAN, sdaiLOGICAL, sdaiBINARY, sdaiENUMERATION, sdaiSELECT and edmiINDETERMINATE
  2. <value>: The data value to assign as the actual argument value when invoking the specified EDMquery function. The data value must be of the same primitive type as specified in the <dataType> argument.

maximum number of arguments is 64

Return Value


Error rendering macro 'excerpt-include' : User 'null' does not have permission to view the page 'US:_r_EDMInterface'.

Options


 

OptionComment

RESULT_AS_ID

Specifies that the result of the edmiExecuteQuery operation should be returned as aggregateID and not as aggregate contents when sdaiAGGR is the actual data type of the result value. The actual aggregateID is returned in the element data.value.aggrVal in the returned SdaiQueryResult struct. The declared return value (function value) of the actual EDMquery function defines the legal data type of the result value.  RESULT_AS_ID is the default option value.

RESULT_AS_ID_CONTENTS

Specifies that the result of the edmiExecuteQuery operation should be returned as aggregate contents and not as aggregateID when sdaiAGGR is the EDMquery function data type. This means that the result will be a table with one column and number of rows equal to the number of elements in the aggregate.

RESULT_AS_TABLE

Specifies that the result of the edmiExecuteQuery operation should be returned as a table. This option is only valid when the EDMquery result is an aggregate of instances or an aggregate of view instances.  The number of elements in the aggregate will be the number of rows in the table and the number of attributes in the actual instance type or view type will be the number of columns in the table.

Example


 

/*===================================================================
 /* Extract of an EDMquerySchema */
 QUERY_SCHEMA product_doc_approval FOR PDM_SCHEMA;
 GLOBAL 
 DECLARE exps INSTANCE OF PDM_SCHEMA; 
 END_GLOBAL; 
  
 VIEW_ENTITY product_view_with_ids; 
 Product : Product; 
 Product_Id : STRING; 
 Product_Name : STRING; 
 Document : Document;  
 Document_Id : STRING; 
 Document_Name : STRING; 
 Document_Type : Document_Type; 
 Product_Data_Type : STRING; 
 END_VIEW_ENTITY; 
 LOCAL 
 result : SET of product_view_with_ids;  
 ... 
 END_LOCAL; 
  
 QUERY_FUNCTION product_documentation (prod_id , prod_name : STRING) 
 : SET OF product_view_with_ids; 
 LOCAL 
 result : SET of product_view_with_ids;  
 ... 
 END_LOCAL; 
 . . . 
 RETURN(result); 
 END_QUERY_FUNCTION; 
 END_QUERY_SCHEMA;
 ====================================================================*/
 EdmiError rstat;
 SdaiModel modelId;
 SdaiQuery queryId;
 SdaiQueryResult qs;
 short columnWidth,*columnWidths;
 String *columns,*columnLabels;
 long i,j,n,numberOfRows,numberOfColumns,numberOfVisibleRows;
 long len,*ps,*pd,*columnSortFlags,numberOfVisibleColumns;
 char **cp,*cpp;
 SdaiColumnDescr **columnDescr;
 char *dummy = " ";
 SdaiInteger *pint;
 SdaiString *pstr;
 SdaiLogical *plog;
 tSdaiSelect *psel;
 SdaiInstance *pinst;
 SdaiReal myReal,*preal;
 char cell[MAX_SIMPLEID];
 . . .  
 if (rstat = edmiExecuteQuery(modelId,
 queryId, 
 2, 
 RESULT_AS_TABLE, 
 &qs, 
 sdaiSTRING, "PIDaba44889", 
 sdaiSTRING, "myName")) { 
 /* Error in operation */ 
 printf("\nError: %s in edmiExecuteQuery\n", 
 edmiGetErrorText(rstat)); 
 goto error; 
 } 
 /* Make displayable table */ 
 if(qs->data.type == edmiINDETERMINATE) goto err; /* no data */ 
 numberOfRows = qs->rows;  
 numberOfColumns = qs->columns;  
 columns = (char*)MALLOC(numberOfRows*numberOfColumns*sizeof(char)); 
 columnWidths = (short*) MALLOC(numberOfColumns*sizeof(short)); 
 memset(columnWidths,'\0',numberOfColumns*sizeof(short)); 
 columnLabels = (char*) MALLOC(numberOfColumns*sizeof(char)); 
 columnSortFlags = (long*) MALLOC(numberOfColumns*sizeof(long)); 
 columnDescr = (qs->columnDescr); 
 for(i=0; i < numberOfColumns; ++i){ 
 query_primTypes[i] = (*columnDescr)->datatype; 
 cpp = (char*) MALLOC(strlen((*columnDescr)->columnName)+1); 
 strcpy(cpp,(*columnDescr)->columnName); 
 columnLabels[i] = cpp; 
 columnWidths[i] = (short) strlen(cpp)+2; 
 columnSortFlags[i] = QUERY_SORT_NONE; 
 for(j=0; j<numberOfRows; ++j){ 
 sprintf(Cell,""); 
 if ((*columnDescr)->pvalueSet[j] == sdaiTRUE) { 
 switch ((*columnDescr)->datatype) { 
 case sdaiINTEGER: 
 pint = (SdaiInteger *) (*columnDescr)->pvalue; 
 sprintf(Cell,"%12ld ",pint[j]); 
 break; 
 case sdaiINSTANCE: 
 case sdaiAGGR: 
 pinst = (SdaiInstance *) (*columnDescr)->pvalue; 
 sprintf(Cell,"%12lu ",pinst[j]); 
 break; 
 case sdaiSTRING: 
 case sdaiENUMERATION: 
 case sdaiBINARY: 
 pstr = (SdaiString *) (*columnDescr)->pvalue; 
 sprintf(Cell,"%s ",pstr[j]); 
 break; 
 case sdaiREAL: 
 preal = (SdaiReal *) (*columnDescr)->pvalue; 
 ps = (long *) &preal[j]; 
 pd = (long *) &myReal; 
 COPY_REAL(ps,pd); 
 sprintf(Cell,"%f",myReal); 
 break; 
 case sdaiBOOLEAN: 
 case sdaiLOGICAL: 
 plog = (SdaiLogical *) (*columnDescr)->pvalue; 
 if (plog[j] == sdaiTRUE) { 
 sprintf(Cell,"TRUE"); 
 } else if (plog[j] == sdaiFALSE) { 
 sprintf(Cell,"FALSE"); 
 } else { 
 sprintf(Cell,"UNKNOWN"); 
 } 
 break; 
 case sdaiSELECT: 
 psel = (SdaiSelect) (*columnDescr)->pvalue; 
 selectValueToCell(&psel[j],Cell); 
 break; 
 default: 
 break; 
 } 
 } 
 len = strlen(Cell); 
 if(len > 0){ 
 columnWidth = len+1; 
 cpp = (char*) MALLOC(columnWidth+1); 
 strcpy(cpp,Cell); 
 cp = columns+(j*numberOfColumns)+i; 
 *cp = cpp; 
 } else { 
 cp = columns+(j*numberOfColumns)+i; 
 *cp = dummy; 
 } 
 if (len >= columnWidths[i]) columnWidths[i] = len + 1;  
 } 
 if(columnWidths[i] > QUERY_MAX_COLUMN_WIDTH)  
 columnWidths[i] = QUERY_MAX_COLUMN_WIDTH; 
 ++columnDescr; 
 } 

 

See also

Filter by label

There are no items with the selected labels at this time.

Â