nelems.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Licensed Materials - Property of HCL
  3. *
  4. * IBM Informix DataBlade Module
  5. * (C) Copyright International Business Machines Corporation 2002.
  6. * (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved.
  7. *
  8. * COPYRIGHT LICENSE:
  9. * This information contains sample application programs in source language,
  10. * which illustrate programming techniques on various operating platforms.
  11. * You may copy, modify, and distribute these sample programs in any form
  12. * without payment to IBM, for the purposes of developing, using, marketing
  13. * or distributing application programs conforming to the application
  14. * programming interface for the operating platform for which the sample
  15. * programs are written. These examples have not been thoroughly tested under
  16. * all conditions. IBM, therefore, cannot guarantee or imply reliability,
  17. * serviceability, or function of these programs. You may copy, modify, and
  18. * distribute these sample programs in any form without payment to IBM for
  19. * the purposes of developing, using, marketing, or distributing application
  20. * programs conforming to IBM's application programming interfaces.
  21. * Each copy or any portion of these sample programs or any derivative work,
  22. * must include a copyright notice as follows:
  23. * © (your company name) (year). Portions of this code are derived from
  24. * IBM Corp. Sample Programs. © Copyright IBM Corp. (enter the year or
  25. * years). All rights reserved.
  26. *
  27. */
  28. #include "tseries.h"
  29. /*
  30. * Example of counting non null elements
  31. */
  32. mi_integer
  33. nelems(ts_timeseries *ts, MI_FPARAM *fParam)
  34. {
  35. ts_tsdesc *tsdesc;
  36. ts_tscan *tsscan;
  37. ts_tselem elem;
  38. mi_integer cnt;
  39. mi_integer ret;
  40. MI_CONNECTION *conn;
  41. conn = mi_open(NULL, NULL, NULL);
  42. /* open the source timeseries */
  43. cnt = 0;
  44. tsdesc = ts_open(conn, ts, mi_fp_argtype(fParam, 0), 0);
  45. /* scan the entire timeseries */
  46. tsscan = ts_begin_scan(tsdesc, 0, NULL, NULL);
  47. while ((ret = ts_next(tsscan, &elem)) != TS_SCAN_EOS)
  48. if (ret != TS_SCAN_NULL)
  49. /* don't count nulls */
  50. cnt++;
  51. /* clean up */
  52. ts_end_scan(tsscan);
  53. ts_close(tsdesc);
  54. return(cnt);
  55. }