crxSDKSample.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: crx
  4. (C) Copyright IBM Corp. 2003, 2010
  5. US Government Users Restricted Rights - Use, duplication or disclosure
  6. restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. /// COPYRIGHT_DATA { 'YEAR':[2010, 2009, 2003], 'RELEASE':['colorado_wave1'], 'VISIBLE':'YES', 'COMPONENT':'crx' }
  9. ///All lines above the COPYRIGHT_DATA line will be replaced when copyright notices are generated.
  10. // crxSDKSample.cpp
  11. //
  12. #include "crxSDK.h"
  13. #include <stdlib.h> // <- RandomInt
  14. #include <time.h>
  15. #include <string.h> // <- memset, strcpy
  16. #include <stdio.h> // <- sprintf
  17. #if defined( _MSC_VER )
  18. # define crxSDKSampleExport __declspec( dllexport )
  19. #else
  20. # define crxSDKSampleExport
  21. #endif
  22. //------------------------------------------------------------
  23. // Custom Report Functions
  24. //------------------------------------------------------------
  25. // The crxSDKSampleTree.xml must contain the list of custom report functions
  26. // and must specify the type of their return value.
  27. // use "crxDTypeString" to return a CCL_char*
  28. // use "crxDTypeInt8" to return a CCL_int8
  29. // ...
  30. // Note the exact spelling in:
  31. // use "crxDTypeDate" to return a CCLDate2
  32. // use "crxDTypeTime" to return a CCLTime2
  33. // use "crxDTypeTimeTZ" to return a CCLTimeTZ
  34. // use "crxDTypeDatetimeTZ" to return a CCLTimestampTZ
  35. // use "crxDTypeDatetime" to return a CCLTimestamp2
  36. // use "crxDTypeDTInterval" to return a CCLInterval2
  37. // use "crxDTypeYMInterval" to return a CCLIntervalYM
  38. //------------------------------------------------------------
  39. //
  40. extern "C"
  41. {
  42. //------------------------------------------------------------
  43. crxSDKSampleExport CCLDBColumnState SDKRandomInt
  44. (
  45. void* result,
  46. CCL_uint32 resultSize,
  47. const crxDataI* context
  48. )
  49. {
  50. srand( (unsigned)time( NULL ) );
  51. *( (CCL_int32*)result ) = rand();
  52. return( CCL_DB_COLSTATE_OK );
  53. }// RandomInt
  54. //------------------------------------------------------------
  55. crxSDKSampleExport CCLDBColumnState SDKArea
  56. (
  57. void* result,
  58. CCL_uint32 resultSize,
  59. const crxDataI* context,
  60. const CCL_float64* arg1,
  61. const CCL_float64* arg2,
  62. const char* arg3
  63. )
  64. {
  65. CCLDBColumnState state = CCL_DB_COLSTATE_OK;
  66. switch( arg3[0] )
  67. {
  68. case( 'T' ):
  69. case( 't' ):
  70. {
  71. *(CCL_float64*)result = (*arg1)*(*arg2)/2;
  72. break;
  73. }
  74. case( 'P' ):
  75. case( 'p' ):
  76. {
  77. *(CCL_float64*)result = (*arg1)*(*arg2);
  78. break;
  79. }
  80. default:
  81. {
  82. *(CCL_float64*)result = 0;
  83. state = CCL_DB_COLSTATE_ERROR;
  84. }
  85. }
  86. return( state );
  87. }// Area
  88. //------------------------------------------------------------
  89. crxSDKSampleExport CCLDBColumnState SDKDateToString
  90. (
  91. void* result,
  92. CCL_uint32 resultSize,
  93. const crxDataI* context,
  94. const CCLDate2* arg1
  95. )
  96. {
  97. CCLDBColumnState state = CCL_DB_COLSTATE_OK;
  98. CCL_int32 year, month, day;
  99. year = month = day = 0;
  100. try
  101. {
  102. year = arg1->year;
  103. month = arg1->month;
  104. day = arg1->day;
  105. char yearStr[5];
  106. char monthStr[5];
  107. char dayStr[5];
  108. memset( yearStr, 0, 5 );
  109. memset( monthStr, 0, 5 );
  110. memset( dayStr, 0, 5 );
  111. sprintf( yearStr, "%04ld", year);
  112. sprintf( monthStr, "%02ld", month);
  113. sprintf( dayStr, "%02ld", day);
  114. strcpy( (CCL_char*)result, yearStr );
  115. strcat( (CCL_char*)result, "-" );
  116. strcat( (CCL_char*)result, monthStr );
  117. strcat( (CCL_char*)result, "-" );
  118. strcat( (CCL_char*)result, monthStr );
  119. }
  120. catch( ... )
  121. {
  122. state = CCL_DB_COLSTATE_ERROR;
  123. }
  124. return( state );
  125. }// DateToString
  126. // Trakker 535408 (SDK DOCS) begin
  127. crxSDKSampleExport CCLDBColumnState SDKtestReturnUint32
  128. (
  129. void* result,
  130. CCL_uint32 resultSize,
  131. const crxDataI* context
  132. )
  133. {
  134. CCLDBColumnState state = CCL_DB_COLSTATE_OK;
  135. try
  136. {
  137. *(CCL_uint32*)result = (CCL_uint32) 33;
  138. }
  139. catch( ... )
  140. {
  141. state = CCL_DB_COLSTATE_ERROR;
  142. }
  143. return( state );
  144. }// SDKtestReturnUint32
  145. crxSDKSampleExport CCLDBColumnState SDKtestReturnInt32
  146. (
  147. void* result,
  148. CCL_int32 resultSize,
  149. const crxDataI* context
  150. )
  151. {
  152. CCLDBColumnState state = CCL_DB_COLSTATE_OK;
  153. try
  154. {
  155. *(CCL_int32*)result = (CCL_int32) 33;
  156. }
  157. catch( ... )
  158. {
  159. state = CCL_DB_COLSTATE_ERROR;
  160. }
  161. return( state );
  162. }// SDKtestReturnInt32
  163. crxSDKSampleExport CCLDBColumnState SDKtestReturnUint64
  164. (
  165. void* result,
  166. CCL_uint32 resultSize,
  167. const crxDataI* context
  168. )
  169. {
  170. CCLDBColumnState state = CCL_DB_COLSTATE_OK;
  171. try
  172. {
  173. *(CCL_uint64*)result = (CCL_uint64) 33;
  174. }
  175. catch( ... )
  176. {
  177. state = CCL_DB_COLSTATE_ERROR;
  178. }
  179. return( state );
  180. }// SDKtestReturnUint64
  181. crxSDKSampleExport CCLDBColumnState SDKtestReturnInt64
  182. (
  183. void* result,
  184. CCL_int32 resultSize,
  185. const crxDataI* context
  186. )
  187. {
  188. CCLDBColumnState state = CCL_DB_COLSTATE_OK;
  189. try
  190. {
  191. *(CCL_int64*)result = (CCL_int64) 33;
  192. }
  193. catch( ... )
  194. {
  195. state = CCL_DB_COLSTATE_ERROR;
  196. }
  197. return( state );
  198. }// SDKtestReturnInt64
  199. crxSDKSampleExport CCLDBColumnState SDKtestReturnFloat32
  200. (
  201. void* result,
  202. CCL_int32 resultSize,
  203. const crxDataI* context
  204. )
  205. {
  206. CCLDBColumnState state = CCL_DB_COLSTATE_OK;
  207. try
  208. {
  209. *(CCL_float32*)result = (CCL_float32) 33.0;
  210. }
  211. catch( ... )
  212. {
  213. state = CCL_DB_COLSTATE_ERROR;
  214. }
  215. return( state );
  216. }// SDKtestReturnFloat32
  217. crxSDKSampleExport CCLDBColumnState SDKtestReturnFloat64
  218. (
  219. void* result,
  220. CCL_uint32 resultSize,
  221. const crxDataI* context
  222. )
  223. {
  224. CCLDBColumnState state = CCL_DB_COLSTATE_OK;
  225. try
  226. {
  227. *(CCL_float64*)result = (CCL_float64) 33;
  228. }
  229. catch( ... )
  230. {
  231. state = CCL_DB_COLSTATE_ERROR;
  232. }
  233. return( state );
  234. }// SDKtestReturnFloat64
  235. // Trakker 535408 (SDK DOCS) end
  236. }