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.
Related functions: edmiExecuteQuery, edmiGetQuery , edmiGetQuerySchema , edmiDefineQuerySchema
Header:
#include "sdai.h"
Prototype:
EdmiError edmiExecuteQueryBN(SdaiModel modelId,
SdaiString querySchemaName,
SdaiString queryName,
SdaiInteger arguments,
SdaiInteger options,
SdaiQueryResult *queryResult,
/* For each query argument:
[SdaiPrimitiveType argumentDataType,
value] */
… );
Arguments:
modelId |
A numeric modelID that uniquely identifies the data model in the EDMdatabase to run the specified EDMquery on. |
querySchemaName |
Specifies the name of the EDMquerySchema that defines the EDMquery of interest. This query schema must exist in the EDMdatabase. Query schema names are case insensitive. |
queryName |
Specifies the name of an EDMquery function that should be invoked. EDMquery names are case insensitive. |
arguments |
Number of arguments supplied to the actual EDMquery function. |
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 . |
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:
|
Option Description
RESULT_AS_ID |
Specifies that the result of the edmiExecuteQueryBN operation should be returned as aggregateID and not as aggregate contents when sdaiAGGR is the actual data type of the result value. |
RESULT_AS_ID_CONTENTS |
Specifies that the result of the edmiExecuteQueryBN operation should be returned as aggregate contents and not as aggregateID when sdaiAGGR is the EDMquery function data type. |
RESULT_AS_TABLE |
Specifies that the result of the edmiExecuteQueryBN 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. |
Returns:
A completion code of datatype EdmiError is the returned function value. The completion code has the following values:
Completion code = 0 : Operation successfully performed.
Completion code != 0: Error in operation. Completion code is an EDMinterface error code. Use edmiGetErrorText to get the error text corresponding to the error code.
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 = edmiExecuteQueryBN(modelId,
"product_doc_approval",
"product_documentation",
2,
RESULT_AS_TABLE,
&qs,
sdaiSTRING, "PIDaba44889",
sdaiSTRING, "myName")) {
/* Error in operation */
printf("\nError: %s in edmiExecuteQueryBN\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;
}