123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /*
- * Licensed Materials - Property of HCL
- *
- * IBM Informix DataBlade Module
- * (C) Copyright International Business Machines Corporation 2002.
- * (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved.
- *
- * COPYRIGHT LICENSE:
- * This information contains sample application programs in source language,
- * which illustrate programming techniques on various operating platforms.
- * You may copy, modify, and distribute these sample programs in any form
- * without payment to IBM, for the purposes of developing, using, marketing
- * or distributing application programs conforming to the application
- * programming interface for the operating platform for which the sample
- * programs are written. These examples have not been thoroughly tested under
- * all conditions. IBM, therefore, cannot guarantee or imply reliability,
- * serviceability, or function of these programs. You may copy, modify, and
- * distribute these sample programs in any form without payment to IBM for
- * the purposes of developing, using, marketing, or distributing application
- * programs conforming to IBM's application programming interfaces.
- * Each copy or any portion of these sample programs or any derivative work,
- * must include a copyright notice as follows:
- * © (your company name) (year). Portions of this code are derived from
- * IBM Corp. Sample Programs. © Copyright IBM Corp. (enter the year or
- * years). All rights reserved.
- *
- */
- /*
- * SETUP:
- *
- * create function TsToList(TimeSeries, integer) returns list
- * external name '/foo/bar/TsToList.so(ts_to_list)'
- * language c not variant;
- *
- */
- #include <stdio.h>
- #include <mi.h>
- #include <tseries.h>
- /*
- * This function converts the first column of a timeseries
- * to an array. This assumes the type is mi_real
- */
- #include <math.h>
- #ifdef NT
- __declspec(dllexport)
- #endif
- MI_COLLECTION *
- ts_to_list(ts_timeseries *tsPtr, mi_integer col, MI_FPARAM *fParam)
- {
- ts_tsdesc *descPtr;
- ts_tselem tselem;
- ts_tscan *scan;
- MI_CONNECTION *conn;
- int scancode;
- MI_COLLECTION *colPtr = NULL;
- MI_COLL_DESC *colDesc = NULL;
- ts_typeinfo *typePtr;
- mi_boolean isNull;
- void *rslt;
- MI_TYPE_DESC *list_td;
- MI_TYPE_DESC *subtype_td;
- MI_TYPEID *subtype_id;
- char errbuf[100];
-
- /* get a connection for libmi */
- conn = mi_open(NULL,NULL,NULL);
- /* open a descriptor for the timeseries */
- descPtr = ts_open(conn, tsPtr, mi_fp_argtype(fParam, 0), 0);
- scan = ts_begin_scan(descPtr, 0, NULL, NULL);
- while ((scancode = ts_next(scan, &tselem)) != TS_SCAN_EOS) {
- switch(scancode) {
- case TS_SCAN_ELEM:
- if (colPtr == (MI_COLLECTION *)NULL) {
- /* first time */
- typePtr = ts_colinfo_number(descPtr, col);
- /* make sure type of column agrees with return type */
- list_td = mi_type_typedesc(conn, mi_fp_rettype(fParam, 0));
- subtype_td = mi_type_element_typedesc(list_td);
- subtype_id = mi_typedesc_typeid(subtype_td);
- if (!mi_typeid_equals(subtype_id, typePtr->ti_typeid)) {
- subtype_td = mi_type_typedesc(conn, typePtr->ti_typeid);
- sprintf(errbuf, "Subtype of %s must match column type (%s)",
- mi_type_typename(list_td),
- mi_type_typename(subtype_td));
- mi_db_error_raise(NULL, MI_FATAL, errbuf, 0);
- }
- colPtr = mi_collection_create(conn, mi_fp_rettype(fParam, 0));
- colDesc = mi_collection_open(conn, colPtr);
- }
-
- /* insert this ts_elem into the collection */
- rslt = ts_get_col_by_number(descPtr,
- tselem,
- col,
- &isNull,
- ts_current_offset(scan));
- if (!isNull) {
- /* we inseret only if it is not NULL. */
- mi_collection_insert(conn, colDesc,
- (MI_DATUM) rslt, MI_CURSOR_NEXT,0);
- }
- break;
- case TS_SCAN_NULL:
- break;
- }
- }
- ts_end_scan(scan);
- ts_close(descPtr);
- mi_collection_close(conn, colDesc);
- return(colPtr);
- }
|