Describes the function in Sybase CEP for printing schema and its syntax.
Sending or receiving data with the Sybase CEP Engine requires a schema for the message containing the data. Sybase CEP Studio creates a schema interactively with the user. When the user interfaces to this data, the schema provides information such as column names and column data types.
Try to develop adapters that are flexible enough to accommodate change, rather than hard-coding a schema. A major first step in this flexibility is obtaining the existing schema. The following function simply prints the existing schema. This function is identical for both an input and an output adapter:
static void PrintSchema(C8Adapter* i_adapter_ptr) { const C8Schema* i_schema_ptr = C8AdapterGetSchema(i_adapter_ptr); C8Char *l_name; const char *l_type_name; C8UInt ndx; C8UInt l_col_cnt; if(i_schema_ptr == 0) { printf("Cannot get schema pointer.\n"); return; } l_col_cnt = C8SchemaGetColumns(i_schema_ptr); printf("This schema has %d columns.\n", l_col_cnt); for (ndx = 0; ndx < l_col_cnt; ++ndx) { l_name = (C8Char*)C8SchemaGetColumnName(i_schema_ptr, ndx); l_type_name = MapC8TypeToString(C8SchemaGetColumnType( i_schema_ptr, ndx)); printf("\t%s\t%s\n", l_name, l_type_name); } }
This routine takes the adapter pointer and retrieves the schema pointer. The C8SchemaGetColumns() function provides the number of columns in a schema and provides the upper limit to the print loop. Column names are etrieved with C8SchemaGetColumnName() and the Sybase CEP datatypes with another utility function C8SchemaGetColumnType(). The output of this function will be displayed on the same window as Sybase CEP Server since adapters run tightly bound to Sybase CEP Server.
A minor utility function, MapC8TypeToString() converts a Sybase CEP data type to a displayable string.
// Given a C8_TYPES object, return a printable string. static const char *MapC8TypeToString(C8_TYPES i_atype) { switch(i_atype) { case C8_INT: return "C8_INT"; case C8_LONG: return "C8_LONG"; case C8_FLOAT: return "C8_FLOAT"; case C8_CHAR_PTR: return "C8_CHAR_PTR"; case C8_TIMESTAMP: return "C8_TIMESTAMP"; case C8_INTERVAL: return "C8_INTERVAL"; case C8_BOOL: return "C8_BOOL"; case C8_XML: return "C8_XML"; case C8_INVALID: // fall through to default default: return "C8_INVALID"; } // Should not happen return "C8_INVALID"; }