@zowe/db2-for-zowe-cli 6.1.17 → 6.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/README.md +12 -10
  2. package/lib/Db2PluginLifeCycle.d.ts +11 -9
  3. package/lib/Db2PluginLifeCycle.js +18 -13
  4. package/lib/Db2PluginLifeCycle.js.map +1 -1
  5. package/node_modules/axios/CHANGELOG.md +62 -0
  6. package/node_modules/axios/README.md +233 -5
  7. package/node_modules/axios/dist/axios.js +387 -89
  8. package/node_modules/axios/dist/axios.min.js +3 -3
  9. package/node_modules/axios/dist/axios.min.js.map +1 -1
  10. package/node_modules/axios/dist/browser/axios.cjs +458 -98
  11. package/node_modules/axios/dist/esm/axios.js +458 -98
  12. package/node_modules/axios/dist/esm/axios.min.js +2 -2
  13. package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
  14. package/node_modules/axios/dist/node/axios.cjs +568 -116
  15. package/node_modules/axios/index.d.cts +4 -0
  16. package/node_modules/axios/index.d.ts +4 -0
  17. package/node_modules/axios/lib/adapters/fetch.js +64 -11
  18. package/node_modules/axios/lib/adapters/http.js +134 -50
  19. package/node_modules/axios/lib/adapters/xhr.js +52 -3
  20. package/node_modules/axios/lib/core/Axios.js +19 -14
  21. package/node_modules/axios/lib/core/InterceptorManager.js +107 -8
  22. package/node_modules/axios/lib/core/buildFullPath.js +1 -13
  23. package/node_modules/axios/lib/core/dispatchRequest.js +8 -2
  24. package/node_modules/axios/lib/core/mergeConfig.js +1 -1
  25. package/node_modules/axios/lib/core/methodList.js +17 -0
  26. package/node_modules/axios/lib/defaults/index.js +2 -1
  27. package/node_modules/axios/lib/env/data.js +1 -1
  28. package/node_modules/axios/lib/helpers/Http2Sessions.js +2 -0
  29. package/node_modules/axios/lib/helpers/HttpStatusCode.js +11 -1
  30. package/node_modules/axios/lib/helpers/fromDataURI.js +5 -4
  31. package/node_modules/axios/lib/helpers/normalizeURLForProtocolCheck.js +24 -0
  32. package/node_modules/axios/lib/helpers/progressEventReducer.js +1 -1
  33. package/node_modules/axios/lib/helpers/resolveConfig.js +4 -2
  34. package/node_modules/axios/lib/helpers/shouldBypassProxy.js +182 -6
  35. package/node_modules/axios/lib/helpers/throttle.js +3 -2
  36. package/node_modules/axios/lib/helpers/toFormData.js +14 -21
  37. package/node_modules/axios/lib/utils.js +134 -13
  38. package/node_modules/axios/package.json +1 -1
  39. package/node_modules/ibm_db/APIDocumentation.md +2883 -2024
  40. package/node_modules/ibm_db/LICENSE +23 -23
  41. package/node_modules/ibm_db/README.md +735 -735
  42. package/node_modules/ibm_db/binding.gyp +99 -98
  43. package/node_modules/ibm_db/installer/driverInstall.js +984 -958
  44. package/node_modules/ibm_db/installer/ifx.sh +38 -38
  45. package/node_modules/ibm_db/installer/setenv.sh +23 -23
  46. package/node_modules/ibm_db/installer/testODBCConnection.bat +51 -51
  47. package/node_modules/ibm_db/installer/testODBCConnection.sh +61 -61
  48. package/node_modules/ibm_db/lib/climacros.js +431 -431
  49. package/node_modules/ibm_db/lib/odbc.js +4293 -3487
  50. package/node_modules/ibm_db/lib/simple-queue.js +41 -41
  51. package/node_modules/ibm_db/package.json +70 -70
  52. package/node_modules/ibm_db/src/odbc.cpp +1495 -1396
  53. package/node_modules/ibm_db/src/odbc.h +477 -473
  54. package/node_modules/ibm_db/src/odbc_connection.cpp +1762 -1612
  55. package/node_modules/ibm_db/src/odbc_connection.h +228 -215
  56. package/node_modules/ibm_db/src/odbc_result.cpp +1547 -1547
  57. package/node_modules/ibm_db/src/odbc_result.h +152 -152
  58. package/node_modules/ibm_db/src/odbc_statement.cpp +2047 -861
  59. package/node_modules/ibm_db/src/odbc_statement.h +257 -135
  60. package/node_modules/ibm_db/src/strptime.c +389 -389
  61. package/node_modules/ibm_db/src/strptime.h +46 -46
  62. package/node_modules/ibm_db/test/README +23 -23
  63. package/node_modules/ibm_db/test/bench-insert.js +62 -62
  64. package/node_modules/ibm_db/test/bench-insertBatch10.js +74 -74
  65. package/node_modules/ibm_db/test/bench-insertBatch100.js +75 -75
  66. package/node_modules/ibm_db/test/bench-insertBatch1000.js +75 -75
  67. package/node_modules/ibm_db/test/bench-insertBatch10000.js +75 -75
  68. package/node_modules/ibm_db/test/bench-prepare-bind-execute-closeSync.js +60 -60
  69. package/node_modules/ibm_db/test/bench-prepare-bind-executeNonQuery.js +53 -53
  70. package/node_modules/ibm_db/test/bench-prepare-bindSync-execute-closeSync.js +50 -50
  71. package/node_modules/ibm_db/test/bench-prepare-bindSync-executeNonQuery.js +48 -48
  72. package/node_modules/ibm_db/test/bench-prepare-execute-closeSync.js +51 -51
  73. package/node_modules/ibm_db/test/bench-prepare-executeNonQuery.js +47 -47
  74. package/node_modules/ibm_db/test/bench-prepare-not.js +43 -43
  75. package/node_modules/ibm_db/test/bench-query-fetch.js +59 -59
  76. package/node_modules/ibm_db/test/bench-query-fetchAll.js +49 -49
  77. package/node_modules/ibm_db/test/bench-query-fetchAllSync.js +43 -43
  78. package/node_modules/ibm_db/test/bench-query.js +40 -40
  79. package/node_modules/ibm_db/test/bench-querySync-fetchArray.js +28 -28
  80. package/node_modules/ibm_db/test/bench-querySync.js +29 -29
  81. package/node_modules/ibm_db/test/common.d.ts +10 -10
  82. package/node_modules/ibm_db/test/common.js +127 -127
  83. package/node_modules/ibm_db/test/config.json +7 -7
  84. package/node_modules/ibm_db/test/config.zos.json +4 -4
  85. package/node_modules/ibm_db/test/data/sample1.txt +9 -9
  86. package/node_modules/ibm_db/test/data/trc.fmt +30114 -30114
  87. package/node_modules/ibm_db/test/nodeEE-leak-huge-query.js +152 -152
  88. package/node_modules/ibm_db/test/nodeEE-leak-multiple-query-multiple-connections.js +148 -148
  89. package/node_modules/ibm_db/test/nodeEE-leak-multiple-query-pool-connections.js +154 -154
  90. package/node_modules/ibm_db/test/nodeEE-leak-multiple-query.js +133 -133
  91. package/node_modules/ibm_db/test/nodeEE-stress-async-waterfall-multiple-connections.js +174 -174
  92. package/node_modules/ibm_db/test/nodeEE-stress-async-waterfall.js +169 -169
  93. package/node_modules/ibm_db/test/nodeEE-stress-mixed-query-multiple-connections.js +159 -159
  94. package/node_modules/ibm_db/test/nodeEE-stress-mixed-query.js +148 -148
  95. package/node_modules/ibm_db/test/odbc-bench.c +123 -123
  96. package/node_modules/ibm_db/test/perfTest.js +53 -53
  97. package/node_modules/ibm_db/test/quick-example.sh +30 -30
  98. package/node_modules/ibm_db/test/quick-example.ts +80 -80
  99. package/node_modules/ibm_db/test/run-bench.js +96 -96
  100. package/node_modules/ibm_db/test/run-nodeEE.js +132 -132
  101. package/node_modules/ibm_db/test/run-tests.js +132 -138
  102. package/node_modules/ibm_db/test/sql-cli.js +28 -28
  103. package/node_modules/ibm_db/test/test-all-data-types.js +109 -109
  104. package/node_modules/ibm_db/test/test-array-insert.js +178 -178
  105. package/node_modules/ibm_db/test/test-async-await.js +105 -105
  106. package/node_modules/ibm_db/test/test-attributes.js +34 -34
  107. package/node_modules/ibm_db/test/test-bad-pool-connection-prepare-execute.js +57 -57
  108. package/node_modules/ibm_db/test/test-basic-test.js +138 -138
  109. package/node_modules/ibm_db/test/test-binary-array-insert.js +73 -73
  110. package/node_modules/ibm_db/test/test-blob-from-file.js +90 -90
  111. package/node_modules/ibm_db/test/test-blob-insert.js +144 -144
  112. package/node_modules/ibm_db/test/test-blob-stream-insert.js +321 -299
  113. package/node_modules/ibm_db/test/test-blob-to-file.js +370 -370
  114. package/node_modules/ibm_db/test/test-block-fetch.js +364 -364
  115. package/node_modules/ibm_db/test/test-blocking-issue210.js +123 -123
  116. package/node_modules/ibm_db/test/test-call-async.js +64 -64
  117. package/node_modules/ibm_db/test/test-call-stmt.js +53 -53
  118. package/node_modules/ibm_db/test/test-cancel.js +703 -0
  119. package/node_modules/ibm_db/test/test-chinese-char.js +59 -59
  120. package/node_modules/ibm_db/test/test-connection.js +306 -0
  121. package/node_modules/ibm_db/test/test-date.js +32 -32
  122. package/node_modules/ibm_db/test/test-dbclob.js +93 -93
  123. package/node_modules/ibm_db/test/test-decimals.js +135 -135
  124. package/node_modules/ibm_db/test/test-describe-metadata.js +148 -0
  125. package/node_modules/ibm_db/test/test-executeFile.js +167 -167
  126. package/node_modules/ibm_db/test/test-executeFileSync.js +85 -85
  127. package/node_modules/ibm_db/test/test-fetch-apis.js +146 -146
  128. package/node_modules/ibm_db/test/test-fetchN.js +130 -130
  129. package/node_modules/ibm_db/test/test-getinfo.js +197 -197
  130. package/node_modules/ibm_db/test/test-ibm-db-issue14.js +58 -58
  131. package/node_modules/ibm_db/test/test-ibm-db-issue17.js +54 -54
  132. package/node_modules/ibm_db/test/test-ibm-db-issue18.js +54 -54
  133. package/node_modules/ibm_db/test/test-issue-1059-fetchAll-undefined.js +67 -67
  134. package/node_modules/ibm_db/test/test-issue-1080-array-blob-insert.js +40 -0
  135. package/node_modules/ibm_db/test/test-issue-54.js +39 -39
  136. package/node_modules/ibm_db/test/test-issue-get-column-value-2.js +44 -44
  137. package/node_modules/ibm_db/test/test-issue211.js +80 -80
  138. package/node_modules/ibm_db/test/test-issue253.js +39 -39
  139. package/node_modules/ibm_db/test/test-max-pool-size.js +96 -96
  140. package/node_modules/ibm_db/test/test-memory-leaks-new-objects.js +32 -32
  141. package/node_modules/ibm_db/test/test-multi-open-query-close.js +75 -75
  142. package/node_modules/ibm_db/test/test-param-put-data.js +713 -0
  143. package/node_modules/ibm_db/test/test-pool-idle-connection.js +72 -72
  144. package/node_modules/ibm_db/test/test-pool-operations.js +325 -0
  145. package/node_modules/ibm_db/test/test-pool-stale-connections.js +111 -111
  146. package/node_modules/ibm_db/test/test-pool-uncommited.js +33 -33
  147. package/node_modules/ibm_db/test/test-prepare-execute.js +339 -0
  148. package/node_modules/ibm_db/test/test-prepareSync-multiple-execution.js +93 -93
  149. package/node_modules/ibm_db/test/test-primary-foreign-keys.js +246 -0
  150. package/node_modules/ibm_db/test/test-procedures.js +243 -0
  151. package/node_modules/ibm_db/test/test-promise-all-data-types.js +42 -42
  152. package/node_modules/ibm_db/test/test-query-operations.js +405 -0
  153. package/node_modules/ibm_db/test/test-quick-example.js +25 -25
  154. package/node_modules/ibm_db/test/test-row-array-insert.js +167 -167
  155. package/node_modules/ibm_db/test/test-sp-array.js +54 -54
  156. package/node_modules/ibm_db/test/test-sp-dbc-6000.js +88 -88
  157. package/node_modules/ibm_db/test/test-sp-memleak.js +136 -136
  158. package/node_modules/ibm_db/test/test-sp-resultset-execute.js +269 -269
  159. package/node_modules/ibm_db/test/test-sp-resultset.js +228 -228
  160. package/node_modules/ibm_db/test/test-transactions.js +261 -0
  161. package/node_modules/ibm_db/test/test-typescript.js +48 -48
  162. package/node_modules/ibm_db/test/test-xml-datatype.js +70 -70
  163. package/node_modules/ibm_db/test/testWebApp.js +56 -56
  164. package/node_modules/ibm_db/test/trace +51 -51
  165. package/node_modules/ibm_db/test/typescript-apis-test.js +978 -978
  166. package/node_modules/ibm_db/test/webapp.html +17 -17
  167. package/node_modules/ibm_db/test/webapp.js +79 -79
  168. package/node_modules/ibm_db/typescript/README.md +28 -28
  169. package/node_modules/ibm_db/typescript/dist/Database.d.ts +26 -0
  170. package/node_modules/ibm_db/typescript/dist/ODBCStatement.d.ts +93 -0
  171. package/package.json +10 -6
  172. package/node_modules/ibm_db/test/disabled/test-binding-statement-rebinding.js +0 -59
  173. package/node_modules/ibm_db/test/disabled/test-open-dont-close.js +0 -12
  174. package/node_modules/ibm_db/test/disabled/test-param-select-with-booleans-only.js +0 -21
  175. package/node_modules/ibm_db/test/disabled/test-param-select-with-decimals-only.js +0 -20
  176. package/node_modules/ibm_db/test/disabled/test-param-select-with-null.js +0 -21
  177. package/node_modules/ibm_db/test/disabled/test-param-select-with-nulls-mixed.js +0 -23
  178. package/node_modules/ibm_db/test/disabled/test-param-select-with-numbers-mixed.js +0 -22
  179. package/node_modules/ibm_db/test/disabled/test-param-select-with-numbers-only.js +0 -24
  180. package/node_modules/ibm_db/test/disabled/test-param-select-with-strings-only.js +0 -23
  181. package/node_modules/ibm_db/test/disabled/test-param-select-with-unicode.js +0 -15
  182. package/node_modules/ibm_db/test/disabled/test-prepare-bind-execute-closeSync.js +0 -62
  183. package/node_modules/ibm_db/test/disabled/test-prepare-bind-execute-error.js +0 -49
  184. package/node_modules/ibm_db/test/disabled/test-prepare-bind-execute-long-string.js +0 -63
  185. package/node_modules/ibm_db/test/disabled/test-prepare-bind-executeNonQuery.js +0 -63
  186. package/node_modules/ibm_db/test/disabled/test-prepare-bindSync-execute-closeSync.js +0 -46
  187. package/node_modules/ibm_db/test/disabled/test-prepare-bindSync-executeNonQuery.js +0 -50
  188. package/node_modules/ibm_db/test/disabled/test-prepare.js +0 -34
  189. package/node_modules/ibm_db/test/disabled/test-prepareSync.js +0 -29
  190. package/node_modules/ibm_db/test/disabled/test-query-select-fetchAll.js +0 -23
  191. package/node_modules/ibm_db/test/disabled/test-query-select-fetchAllSync.js +0 -23
  192. package/node_modules/ibm_db/test/disabled/test-query-select-unicode.js +0 -15
  193. package/node_modules/ibm_db/test/disabled/test-querySync-select-unicode.js +0 -20
  194. package/node_modules/ibm_db/test/test-affected-rows.js +0 -55
  195. package/node_modules/ibm_db/test/test-bad-connection-string.js +0 -30
  196. package/node_modules/ibm_db/test/test-binding-connection-timeOut.js +0 -31
  197. package/node_modules/ibm_db/test/test-binding-statement-executeSync.js +0 -84
  198. package/node_modules/ibm_db/test/test-binding-transaction-commit.js +0 -79
  199. package/node_modules/ibm_db/test/test-binding-transaction-commitSync.js +0 -53
  200. package/node_modules/ibm_db/test/test-closed.js +0 -14
  201. package/node_modules/ibm_db/test/test-connection-object.js +0 -16
  202. package/node_modules/ibm_db/test/test-describe-column.js +0 -92
  203. package/node_modules/ibm_db/test/test-describe-database.js +0 -18
  204. package/node_modules/ibm_db/test/test-describe-table.js +0 -31
  205. package/node_modules/ibm_db/test/test-domains-open.js +0 -19
  206. package/node_modules/ibm_db/test/test-global-open-close.js +0 -11
  207. package/node_modules/ibm_db/test/test-instantiate-one-and-end.js +0 -9
  208. package/node_modules/ibm_db/test/test-multi-open-close.js +0 -45
  209. package/node_modules/ibm_db/test/test-multi-openSync-closeSync.js +0 -52
  210. package/node_modules/ibm_db/test/test-open-close.js +0 -29
  211. package/node_modules/ibm_db/test/test-open-connectTimeout.js +0 -33
  212. package/node_modules/ibm_db/test/test-openSync.js +0 -31
  213. package/node_modules/ibm_db/test/test-pool-close.js +0 -120
  214. package/node_modules/ibm_db/test/test-pool-connect.js +0 -36
  215. package/node_modules/ibm_db/test/test-pool-rollbackTransaction.js +0 -35
  216. package/node_modules/ibm_db/test/test-prepareSync-bad-sql.js +0 -34
  217. package/node_modules/ibm_db/test/test-promise-open-close.js +0 -33
  218. package/node_modules/ibm_db/test/test-query-create-table-fetchSync.js +0 -23
  219. package/node_modules/ibm_db/test/test-query-create-table.js +0 -12
  220. package/node_modules/ibm_db/test/test-query-drop-table.js +0 -13
  221. package/node_modules/ibm_db/test/test-query-insert.js +0 -38
  222. package/node_modules/ibm_db/test/test-query-select-fetch.js +0 -21
  223. package/node_modules/ibm_db/test/test-query-select-fetchMode-array.js +0 -17
  224. package/node_modules/ibm_db/test/test-query-select.js +0 -64
  225. package/node_modules/ibm_db/test/test-queryResult.js +0 -35
  226. package/node_modules/ibm_db/test/test-queryStream.js +0 -43
  227. package/node_modules/ibm_db/test/test-querySync-select-with-exception.js +0 -25
  228. package/node_modules/ibm_db/test/test-querySync-select.js +0 -28
  229. package/node_modules/ibm_db/test/test-require-and-end.js +0 -8
  230. package/node_modules/ibm_db/test/test-statement-close.js +0 -118
  231. package/node_modules/ibm_db/test/test-transaction-commit-sync.js +0 -54
  232. package/node_modules/ibm_db/test/test-transaction-commit.js +0 -79
@@ -1,473 +1,477 @@
1
- /*
2
- Copyright (c) 2013, Dan VerWeire <dverweire@gmail.com>
3
- Copyright (c) 2010, Lee Smith <notwink@gmail.com>
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted, provided that the above
7
- copyright notice and this permission notice appear in all copies.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
- */
17
-
18
- #ifndef _SRC_ODBC_H
19
- #define _SRC_ODBC_H
20
-
21
- #include <napi.h>
22
- #include <uv.h>
23
- #include <wchar.h>
24
-
25
- #include <stdlib.h>
26
- #include <stdint.h>
27
- #include <string.h>
28
- #include <string>
29
- #include <sqlcli1.h>
30
-
31
- #define MAX_FIELD_SIZE 1024
32
- #define MAX_VALUE_SIZE 1022
33
-
34
- // Property attributes matching NAN behavior: writable + configurable
35
- #define NAPI_METHOD_ATTR static_cast<napi_property_attributes>(napi_writable | napi_configurable)
36
-
37
- #define MODE_COLLECT_AND_CALLBACK 1
38
- #define MODE_CALLBACK_FOR_EACH 2
39
- #define FETCH_ARRAY 3
40
- #define FETCH_OBJECT 4
41
- #define FETCH_NODATA 0
42
- #define SQL_DESTROY SQL_DROP
43
-
44
- // Workaround(zOS): Db2 supplied headers do not define SQL_SUCCEEDED
45
- #ifndef SQL_SUCCEEDED
46
- #define SQL_SUCCEEDED(rc) (((rc) & (~1)) == 0)
47
- #endif
48
-
49
- #ifndef FREE
50
- #define FREE(x) do { if(x) { free(x); x = NULL; } } while(0)
51
- #endif
52
-
53
- // Free Bind Parameters
54
- #define FREE_PARAMS(params, count) \
55
- Parameter prm; \
56
- if (params != NULL) \
57
- { \
58
- for (int i = 0; i < count; i++) \
59
- { \
60
- if (prm = params[i], prm.buffer != NULL && !prm.isBuffer) \
61
- { \
62
- switch (prm.c_type) \
63
- { \
64
- case SQL_C_SBIGINT: \
65
- case SQL_C_LONG: \
66
- delete (int64_t *)prm.buffer; \
67
- break; \
68
- case SQL_C_DOUBLE: \
69
- delete (double *)prm.buffer; \
70
- break; \
71
- case SQL_C_BIT: \
72
- delete (bool *)prm.buffer; \
73
- break; \
74
- case SQL_C_CHAR: \
75
- case SQL_C_WCHAR: \
76
- default: \
77
- free(prm.buffer); \
78
- prm.buffer = NULL; \
79
- break; \
80
- } \
81
- } \
82
- if (prm.arraySize > 0) \
83
- { \
84
- free(prm.strLenArray); \
85
- prm.strLenArray = NULL; \
86
- prm.arraySize = 0; \
87
- } \
88
- if (prm.chunkCount > 0) \
89
- { \
90
- free(prm.chunks); \
91
- prm.chunks = NULL; \
92
- free(prm.chunkLens); \
93
- prm.chunkLens = NULL; \
94
- prm.chunkCount = 0; \
95
- } \
96
- } \
97
- free(params); \
98
- } \
99
- params = NULL; \
100
- count = 0;
101
-
102
- // Define sqltypes which are not defined in SDSNC.H/SQLCLI on z/OS
103
- #ifndef SQL_BOOLEAN
104
- #define SQL_BOOLEAN 16
105
- #define SQL_ROW 19
106
- #endif
107
-
108
- // Workaround(zOS): Guard data-at-execution macros
109
- #ifndef SQL_NEED_DATA
110
- #define SQL_NEED_DATA 99
111
- #endif
112
- #ifndef SQL_LEN_DATA_AT_EXEC_OFFSET
113
- #define SQL_LEN_DATA_AT_EXEC_OFFSET (-100)
114
- #endif
115
- #ifndef SQL_LEN_DATA_AT_EXEC
116
- #define SQL_LEN_DATA_AT_EXEC(length) (-(length) + SQL_LEN_DATA_AT_EXEC_OFFSET)
117
- #endif
118
-
119
- // two macros ensures that any macro used will be expanded
120
- // before being stringified
121
- #define LINESTRING(x) #x
122
- #define LINENO(x) LINESTRING(x)
123
-
124
- typedef struct
125
- {
126
- unsigned char *name;
127
- unsigned char *type_name;
128
- unsigned int name_len;
129
- SQLSMALLINT max_display_len;
130
- SQLSMALLINT scale;
131
- SQLSMALLINT precision;
132
- SQLSMALLINT field_len;
133
- SQLLEN type;
134
- SQLUSMALLINT index;
135
- bool getData;
136
- bool isFileBound;
137
- } Column;
138
-
139
- typedef struct
140
- {
141
- SQLSMALLINT paramtype;
142
- SQLSMALLINT c_type;
143
- SQLSMALLINT type;
144
- SQLULEN size;
145
- SQLSMALLINT decimals;
146
- SQLPOINTER buffer;
147
- SQLLEN buffer_length;
148
- SQLLEN length;
149
- SQLUINTEGER fileOption;
150
- SQLINTEGER fileIndicator;
151
- int arraySize;
152
- SQLINTEGER *strLenArray;
153
- bool isBuffer;
154
- void **chunks;
155
- SQLLEN *chunkLens;
156
- int chunkCount;
157
- } Parameter;
158
-
159
- // Propagate exceptions from UV callbacks (NAPI equivalent of NAN's FatalException)
160
- static inline void PropagateCallbackException(Napi::Env env) {
161
- if (env.IsExceptionPending()) {
162
- Napi::Error err = env.GetAndClearPendingException();
163
- napi_fatal_exception(env, err.Value());
164
- }
165
- }
166
-
167
- class ODBC : public Napi::ObjectWrap<ODBC>
168
- {
169
- public:
170
- static Napi::FunctionReference constructor;
171
- static uv_mutex_t g_odbcMutex;
172
- static uv_async_t g_async;
173
-
174
- static Napi::Object Init(Napi::Env env, Napi::Object exports);
175
-
176
- ODBC(const Napi::CallbackInfo &info);
177
- ~ODBC();
178
-
179
- static Column *GetColumns(SQLHSTMT hStmt, short *colCount);
180
- static void FreeColumns(Column *&columns, short *colCount);
181
- static Napi::Value GetColumnValue(Napi::Env env, SQLHSTMT hStmt, Column column, uint16_t *buffer, size_t bufferLength);
182
- static Napi::Value GetOutputParameter(Napi::Env env, Parameter *prm);
183
- static Napi::Object GetRecordTuple(Napi::Env env, SQLHSTMT hStmt, Column *columns, short *colCount, uint16_t *buffer, size_t bufferLength);
184
- static Napi::Value GetRecordArray(Napi::Env env, SQLHSTMT hStmt, Column *columns, short *colCount, uint16_t *buffer, size_t bufferLength);
185
- static Napi::Value CallbackSQLError(Napi::Env env, SQLSMALLINT handleType, SQLHANDLE handle, Napi::FunctionReference *cb);
186
- static Napi::Value CallbackSQLError(Napi::Env env, SQLSMALLINT handleType, SQLHANDLE handle, char *message, Napi::FunctionReference *cb);
187
- static Napi::Value GetSQLError(Napi::Env env, SQLSMALLINT handleType, SQLHANDLE handle);
188
- static Napi::Value GetSQLError(Napi::Env env, SQLSMALLINT handleType, SQLHANDLE handle, char *message);
189
- static Napi::Array GetAllRecordsSync(Napi::Env env, SQLHENV hENV, SQLHDBC hDBC, SQLHSTMT hSTMT, uint16_t *buffer, size_t bufferLength);
190
- static Parameter *GetParametersFromArray(Napi::Env env, Napi::Array values, int *paramCount);
191
- static SQLRETURN BindParameters(SQLHSTMT hSTMT, Parameter params[], int count);
192
- static SQLRETURN PutDataLoop(SQLHSTMT hSTMT, Parameter params[], int count);
193
-
194
- void Free();
195
-
196
- // Instance methods exposed to JS
197
- Napi::Value CreateConnection(const Napi::CallbackInfo &info);
198
- Napi::Value CreateConnectionSync(const Napi::CallbackInfo &info);
199
-
200
- protected:
201
- SQLHENV m_hEnv;
202
-
203
- static void GetStringParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
204
- static void GetNullParam(Parameter *param, int num);
205
- static void GetInt32Param(Napi::Env env, Napi::Value value, Parameter *param, int num);
206
- static void GetNumberParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
207
- static void GetBoolParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
208
- static void GetArrayParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
209
- static void GetBufferParam(Napi::Value value, Parameter *param, int num);
210
- static void GetDataAtExecParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
211
-
212
- // UV async callbacks
213
- static void UV_CreateConnection(uv_work_t *work_req);
214
- static void UV_AfterCreateConnection(uv_work_t *work_req, int status);
215
- };
216
-
217
- struct create_connection_work_data
218
- {
219
- napi_env env;
220
- Napi::FunctionReference *cb;
221
- ODBC *dbo;
222
- SQLHDBC hDBC;
223
- int result;
224
- };
225
-
226
- struct open_request
227
- {
228
- Napi::FunctionReference *cb;
229
- ODBC *dbo;
230
- int result;
231
- char connection[1];
232
- };
233
-
234
- struct close_request
235
- {
236
- Napi::FunctionReference *cb;
237
- ODBC *dbo;
238
- int result;
239
- };
240
-
241
- struct query_request
242
- {
243
- Napi::FunctionReference *cb;
244
- ODBC *dbo;
245
- SQLHSTMT hSTMT;
246
- int affectedRows;
247
- char *sql;
248
- char *catalog;
249
- char *schema;
250
- char *table;
251
- char *type;
252
- char *column;
253
- Parameter *params;
254
- int paramCount;
255
- int result;
256
- };
257
-
258
- #ifdef UNICODE
259
- #define SQL_T(x) (L##x)
260
- #define UNICHAR uint16_t
261
- #else
262
- #define SQL_T(x) (x)
263
- #define UNICHAR char
264
- #endif
265
-
266
- #ifdef DEBUG
267
- #define DEBUG_PRINTF(...) fprintf(stdout, __VA_ARGS__)
268
- #ifdef UNICODE
269
- #define DEBUG_TPRINTF(...) fwprintf(stdout, __VA_ARGS__)
270
- #else
271
- #define DEBUG_TPRINTF(...) fprintf(stdout, __VA_ARGS__)
272
- #endif
273
- #else
274
- #define DEBUG_PRINTF(...) (void)0
275
- #define DEBUG_TPRINTF(...) (void)0
276
- #endif
277
-
278
- #define REQ_ARGS(N) \
279
- if (info.Length() < (N)) \
280
- { \
281
- Napi::TypeError::New(env, "Expected " #N " arguments").ThrowAsJavaScriptException(); \
282
- return env.Undefined(); \
283
- }
284
-
285
- #define REQ_STR_ARG(I, VAR) \
286
- if (info.Length() <= (I) || !info[I].IsString()) \
287
- { \
288
- Napi::TypeError::New(env, "Argument " #I " must be a string").ThrowAsJavaScriptException(); \
289
- return env.Undefined(); \
290
- } \
291
- std::string VAR = info[I].As<Napi::String>().Utf8Value();
292
-
293
- #define REQ_WSTR_ARG(I, VAR) \
294
- if (info.Length() <= (I) || !info[I].IsString()) \
295
- { \
296
- Napi::TypeError::New(env, "Argument " #I " must be a string").ThrowAsJavaScriptException(); \
297
- return env.Undefined(); \
298
- } \
299
- std::string VAR = info[I].As<Napi::String>().Utf8Value();
300
-
301
- #define REQ_STRO_ARG(I, VAR) \
302
- if (info.Length() <= (I) || !info[I].IsString()) \
303
- { \
304
- Napi::TypeError::New(env, "Argument " #I " must be a string").ThrowAsJavaScriptException(); \
305
- return env.Undefined(); \
306
- } \
307
- std::string VAR = info[I].As<Napi::String>().Utf8Value();
308
-
309
- #define REQ_STR_OR_NULL_ARG(I, VAR) \
310
- if (info.Length() <= (I) || (!info[I].IsString() && !info[I].IsNull())) \
311
- { \
312
- Napi::TypeError::New(env, "Argument " #I " must be a string or null").ThrowAsJavaScriptException(); \
313
- return env.Undefined(); \
314
- } \
315
- std::string VAR = info[I].IsNull() ? std::string("null") : info[I].As<Napi::String>().Utf8Value();
316
-
317
- #define REQ_STRO_OR_NULL_ARG(I, VAR) \
318
- if (info.Length() <= (I) || (!info[I].IsString() && !info[I].IsNull())) \
319
- { \
320
- Napi::TypeError::New(env, "Argument " #I " must be a string or null").ThrowAsJavaScriptException(); \
321
- return env.Undefined(); \
322
- } \
323
- std::string VAR = info[I].IsNull() ? std::string("null") : info[I].As<Napi::String>().Utf8Value();
324
-
325
- #define REQ_FUN_ARG(I, VAR) \
326
- if (info.Length() <= (I) || !info[I].IsFunction()) \
327
- { \
328
- Napi::TypeError::New(env, "Argument " #I " must be a function").ThrowAsJavaScriptException(); \
329
- return env.Undefined(); \
330
- } \
331
- Napi::Function VAR = info[I].As<Napi::Function>();
332
-
333
- #define REQ_BOOL_ARG(I, VAR) \
334
- if (info.Length() <= (I) || !info[I].IsBoolean()) \
335
- { \
336
- Napi::TypeError::New(env, "Argument " #I " must be a boolean").ThrowAsJavaScriptException(); \
337
- return env.Undefined(); \
338
- } \
339
- bool VAR = info[I].As<Napi::Boolean>().Value();
340
-
341
- #define REQ_EXT_ARG(I, VAR) \
342
- if (info.Length() <= (I) || !info[I].IsExternal()) \
343
- { \
344
- Napi::TypeError::New(env, "Argument " #I " invalid").ThrowAsJavaScriptException(); \
345
- return env.Undefined(); \
346
- } \
347
- Napi::External<void> VAR = info[I].As<Napi::External<void>>();
348
-
349
- #define REQ_UINT_ARG(I, VAR) \
350
- if (info.Length() <= (I) || !info[I].IsNumber()) \
351
- { \
352
- Napi::TypeError::New(env, "Argument " #I " invalid").ThrowAsJavaScriptException(); \
353
- return env.Undefined(); \
354
- } \
355
- SQLUINTEGER VAR = info[I].As<Napi::Number>().Uint32Value();
356
-
357
- #define REQ_INT_ARG(I, VAR) \
358
- if (info.Length() <= (I) || !info[I].IsNumber()) \
359
- { \
360
- Napi::TypeError::New(env, "Argument " #I " invalid").ThrowAsJavaScriptException(); \
361
- return env.Undefined(); \
362
- } \
363
- SQLINTEGER VAR = info[I].As<Napi::Number>().Int32Value();
364
-
365
- #define OPT_INT_ARG(I, VAR, DEFAULT) \
366
- SQLUSMALLINT VAR; \
367
- if (info.Length() <= (I)) \
368
- { \
369
- VAR = (DEFAULT); \
370
- } \
371
- else if (info[I].IsNumber()) \
372
- { \
373
- VAR = info[I].As<Napi::Number>().Int32Value(); \
374
- } \
375
- else \
376
- { \
377
- Napi::TypeError::New(env, "Argument " #I " must be an integer").ThrowAsJavaScriptException();\
378
- return env.Undefined(); \
379
- }
380
-
381
- // Check memory allocated successfully or not (for methods returning Napi::Value)
382
- #define MEMCHECK(buffer) \
383
- if (!buffer) \
384
- { \
385
- Napi::Error::New(env, "Could not allocate enough memory in ibm_db " \
386
- "file " __FILE__ ":" LINENO(__LINE__)).ThrowAsJavaScriptException(); \
387
- return env.Undefined(); \
388
- }
389
-
390
- // Macro to get c++ string from std::string (JS string via Utf8Value)
391
- #ifdef UNICODE
392
- #define GETCPPSTR(to, from, len) \
393
- if (len > 0 && from != "null") \
394
- { \
395
- to = (uint16_t *)malloc((len + 1) * sizeof(uint16_t)); \
396
- MEMCHECK(to); \
397
- memcpy(to, from.c_str(), len); \
398
- ((uint16_t *)to)[len] = '\0'; \
399
- } \
400
- else \
401
- { \
402
- len = 0; \
403
- }
404
- #else
405
- #define GETCPPSTR(to, from, len) \
406
- if (len > 0 && from != "null") \
407
- { \
408
- to = (char *)malloc(len + 1); \
409
- MEMCHECK(to); \
410
- memcpy(to, from.c_str(), len); \
411
- ((char *)to)[len] = '\0'; \
412
- } \
413
- else \
414
- { \
415
- len = 0; \
416
- }
417
- #endif
418
-
419
- // Check memory allocated (goto exit variant)
420
- #define MEMCHECK2(buffer, errmsg) \
421
- if (!buffer) \
422
- { \
423
- errmsg = "Could not allocate enough memory in ibm_db " \
424
- "file " __FILE__ ":" LINENO(__LINE__); \
425
- goto exit; \
426
- }
427
-
428
- // Macro to get c++ string from std::string (goto exit variant)
429
- #ifdef UNICODE
430
- #define GETCPPSTR2(to, from, len, errmsg) \
431
- if (len > 0 && from != "null") \
432
- { \
433
- to = (uint16_t *)malloc((len + 1) * sizeof(uint16_t)); \
434
- if (to) \
435
- { \
436
- memcpy(to, from.c_str(), len); \
437
- ((uint16_t *)to)[len] = '\0'; \
438
- } \
439
- else \
440
- { \
441
- errmsg = "Could not allocate enough memory in ibm_db " \
442
- "file " __FILE__ ":" LINENO(__LINE__); \
443
- goto exit; \
444
- } \
445
- } \
446
- else \
447
- { \
448
- len = 0; \
449
- }
450
- #else
451
- #define GETCPPSTR2(to, from, len, errmsg) \
452
- if (len > 0 && from != "null") \
453
- { \
454
- to = (char *)malloc(len + 1); \
455
- if (to) \
456
- { \
457
- memcpy(to, from.c_str(), len); \
458
- ((char *)to)[len] = '\0'; \
459
- } \
460
- else \
461
- { \
462
- errmsg = "Could not allocate enough memory in ibm_db " \
463
- "file " __FILE__ ":" LINENO(__LINE__); \
464
- goto exit; \
465
- } \
466
- } \
467
- else \
468
- { \
469
- len = 0; \
470
- }
471
- #endif
472
-
473
- #endif
1
+ /*
2
+ Copyright (c) 2013, Dan VerWeire <dverweire@gmail.com>
3
+ Copyright (c) 2010, Lee Smith <notwink@gmail.com>
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+
18
+ #ifndef _SRC_ODBC_H
19
+ #define _SRC_ODBC_H
20
+
21
+ #include <napi.h>
22
+ #include <uv.h>
23
+ #include <wchar.h>
24
+
25
+ #include <stdlib.h>
26
+ #include <stdint.h>
27
+ #include <string.h>
28
+ #include <string>
29
+ #include <sqlcli1.h>
30
+
31
+ #define MAX_FIELD_SIZE 1024
32
+ #define MAX_VALUE_SIZE 1022
33
+
34
+ // Property attributes matching NAN behavior: writable + configurable
35
+ #define NAPI_METHOD_ATTR static_cast<napi_property_attributes>(napi_writable | napi_configurable)
36
+
37
+ #define MODE_COLLECT_AND_CALLBACK 1
38
+ #define MODE_CALLBACK_FOR_EACH 2
39
+ #define FETCH_ARRAY 3
40
+ #define FETCH_OBJECT 4
41
+ #define FETCH_NODATA 0
42
+ #define SQL_DESTROY SQL_DROP
43
+
44
+ // Workaround(zOS): Db2 supplied headers do not define SQL_SUCCEEDED
45
+ #ifndef SQL_SUCCEEDED
46
+ #define SQL_SUCCEEDED(rc) (((rc) & (~1)) == 0)
47
+ #endif
48
+
49
+ #ifndef FREE
50
+ #define FREE(x) do { if(x) { free(x); x = NULL; } } while(0)
51
+ #endif
52
+
53
+ // Free Bind Parameters
54
+ #define FREE_PARAMS(params, count) \
55
+ Parameter prm; \
56
+ if (params != NULL) \
57
+ { \
58
+ for (int i = 0; i < count; i++) \
59
+ { \
60
+ if (prm = params[i], prm.buffer != NULL && !prm.isBuffer) \
61
+ { \
62
+ switch (prm.c_type) \
63
+ { \
64
+ case SQL_C_SBIGINT: \
65
+ case SQL_C_LONG: \
66
+ delete (int64_t *)prm.buffer; \
67
+ break; \
68
+ case SQL_C_DOUBLE: \
69
+ delete (double *)prm.buffer; \
70
+ break; \
71
+ case SQL_C_BIT: \
72
+ delete (bool *)prm.buffer; \
73
+ break; \
74
+ case SQL_C_CHAR: \
75
+ case SQL_C_WCHAR: \
76
+ default: \
77
+ free(prm.buffer); \
78
+ prm.buffer = NULL; \
79
+ break; \
80
+ } \
81
+ } \
82
+ if (prm.arraySize > 0) \
83
+ { \
84
+ free(prm.strLenArray); \
85
+ prm.strLenArray = NULL; \
86
+ prm.arraySize = 0; \
87
+ } \
88
+ if (prm.chunkCount > 0) \
89
+ { \
90
+ free(prm.chunks); \
91
+ prm.chunks = NULL; \
92
+ free(prm.chunkLens); \
93
+ prm.chunkLens = NULL; \
94
+ prm.chunkCount = 0; \
95
+ } \
96
+ } \
97
+ free(params); \
98
+ } \
99
+ params = NULL; \
100
+ count = 0;
101
+
102
+ // Define sqltypes which are not defined in SDSNC.H/SQLCLI on z/OS
103
+ #ifndef SQL_BOOLEAN
104
+ #define SQL_BOOLEAN 16
105
+ #define SQL_ROW 19
106
+ #endif
107
+
108
+ // Workaround(zOS): Guard data-at-execution macros
109
+ #ifndef SQL_NEED_DATA
110
+ #define SQL_NEED_DATA 99
111
+ #endif
112
+ #ifndef SQL_LEN_DATA_AT_EXEC_OFFSET
113
+ #define SQL_LEN_DATA_AT_EXEC_OFFSET (-100)
114
+ #endif
115
+ #ifndef SQL_LEN_DATA_AT_EXEC
116
+ #define SQL_LEN_DATA_AT_EXEC(length) (-(length) + SQL_LEN_DATA_AT_EXEC_OFFSET)
117
+ #endif
118
+
119
+ // two macros ensures that any macro used will be expanded
120
+ // before being stringified
121
+ #define LINESTRING(x) #x
122
+ #define LINENO(x) LINESTRING(x)
123
+
124
+ typedef struct
125
+ {
126
+ unsigned char *name;
127
+ unsigned char *type_name;
128
+ unsigned int name_len;
129
+ SQLSMALLINT max_display_len;
130
+ SQLSMALLINT scale;
131
+ SQLSMALLINT precision;
132
+ SQLSMALLINT field_len;
133
+ SQLLEN type;
134
+ SQLUSMALLINT index;
135
+ bool getData;
136
+ bool isFileBound;
137
+ } Column;
138
+
139
+ typedef struct
140
+ {
141
+ SQLSMALLINT paramtype;
142
+ SQLSMALLINT c_type;
143
+ SQLSMALLINT type;
144
+ SQLULEN size;
145
+ SQLSMALLINT decimals;
146
+ SQLPOINTER buffer;
147
+ SQLLEN buffer_length;
148
+ SQLLEN length;
149
+ SQLUINTEGER fileOption;
150
+ SQLINTEGER fileIndicator;
151
+ int arraySize;
152
+ SQLINTEGER *strLenArray;
153
+ bool isBuffer;
154
+ void **chunks;
155
+ SQLLEN *chunkLens;
156
+ int chunkCount;
157
+ } Parameter;
158
+
159
+ // Propagate exceptions from UV callbacks (NAPI equivalent of NAN's FatalException)
160
+ static inline void PropagateCallbackException(Napi::Env env) {
161
+ if (env.IsExceptionPending()) {
162
+ Napi::Error err = env.GetAndClearPendingException();
163
+ napi_fatal_exception(env, err.Value());
164
+ }
165
+ }
166
+
167
+ class ODBC : public Napi::ObjectWrap<ODBC>
168
+ {
169
+ public:
170
+ static Napi::FunctionReference constructor;
171
+ static uv_mutex_t g_odbcMutex;
172
+ static uv_async_t g_async;
173
+
174
+ static Napi::Object Init(Napi::Env env, Napi::Object exports);
175
+
176
+ ODBC(const Napi::CallbackInfo &info);
177
+ ~ODBC();
178
+
179
+ static Column *GetColumns(SQLHSTMT hStmt, short *colCount);
180
+ static void FreeColumns(Column *&columns, short *colCount);
181
+ static Napi::Value GetColumnValue(Napi::Env env, SQLHSTMT hStmt, Column column, uint16_t *buffer, size_t bufferLength);
182
+ static Napi::Value GetOutputParameter(Napi::Env env, Parameter *prm);
183
+ static Napi::Object GetRecordTuple(Napi::Env env, SQLHSTMT hStmt, Column *columns, short *colCount, uint16_t *buffer, size_t bufferLength);
184
+ static Napi::Value GetRecordArray(Napi::Env env, SQLHSTMT hStmt, Column *columns, short *colCount, uint16_t *buffer, size_t bufferLength);
185
+ static Napi::Value CallbackSQLError(Napi::Env env, SQLSMALLINT handleType, SQLHANDLE handle, Napi::FunctionReference *cb);
186
+ static Napi::Value CallbackSQLError(Napi::Env env, SQLSMALLINT handleType, SQLHANDLE handle, char *message, Napi::FunctionReference *cb);
187
+ static Napi::Value GetSQLError(Napi::Env env, SQLSMALLINT handleType, SQLHANDLE handle);
188
+ static Napi::Value GetSQLError(Napi::Env env, SQLSMALLINT handleType, SQLHANDLE handle, char *message);
189
+ static Napi::Array GetAllRecordsSync(Napi::Env env, SQLHENV hENV, SQLHDBC hDBC, SQLHSTMT hSTMT, uint16_t *buffer, size_t bufferLength);
190
+ static Parameter *GetParametersFromArray(Napi::Env env, Napi::Array values, int *paramCount);
191
+ static SQLRETURN BindParameters(SQLHSTMT hSTMT, Parameter params[], int count);
192
+ static SQLRETURN PutDataLoop(SQLHSTMT hSTMT, Parameter params[], int count);
193
+
194
+ void Free();
195
+
196
+ // Instance methods exposed to JS
197
+ Napi::Value CreateConnection(const Napi::CallbackInfo &info);
198
+ Napi::Value CreateConnectionSync(const Napi::CallbackInfo &info);
199
+
200
+ protected:
201
+ SQLHENV m_hEnv;
202
+
203
+ static void GetStringParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
204
+ static void GetNullParam(Parameter *param, int num);
205
+ static void GetInt32Param(Napi::Env env, Napi::Value value, Parameter *param, int num);
206
+ static void GetNumberParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
207
+ static void GetBoolParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
208
+ static void GetArrayParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
209
+ static void GetBufferParam(Napi::Value value, Parameter *param, int num);
210
+ static void GetDataAtExecParam(Napi::Env env, Napi::Value value, Parameter *param, int num);
211
+
212
+ // UV async callbacks
213
+ static void UV_CreateConnection(uv_work_t *work_req);
214
+ static void UV_AfterCreateConnection(uv_work_t *work_req, int status);
215
+ };
216
+
217
+ struct create_connection_work_data
218
+ {
219
+ napi_env env;
220
+ Napi::FunctionReference *cb;
221
+ ODBC *dbo;
222
+ SQLHDBC hDBC;
223
+ int result;
224
+ };
225
+
226
+ struct open_request
227
+ {
228
+ Napi::FunctionReference *cb;
229
+ ODBC *dbo;
230
+ int result;
231
+ char connection[1];
232
+ };
233
+
234
+ struct close_request
235
+ {
236
+ Napi::FunctionReference *cb;
237
+ ODBC *dbo;
238
+ int result;
239
+ };
240
+
241
+ struct query_request
242
+ {
243
+ Napi::FunctionReference *cb;
244
+ ODBC *dbo;
245
+ SQLHSTMT hSTMT;
246
+ int affectedRows;
247
+ char *sql;
248
+ char *catalog;
249
+ char *schema;
250
+ char *table;
251
+ char *type;
252
+ char *column;
253
+ Parameter *params;
254
+ int paramCount;
255
+ int result;
256
+ };
257
+
258
+ #ifdef UNICODE
259
+ #define SQL_T(x) (L##x)
260
+ #define UNICHAR uint16_t
261
+ #else
262
+ #define SQL_T(x) (x)
263
+ #define UNICHAR char
264
+ #endif
265
+
266
+ #ifdef DEBUG
267
+ #define DEBUG_PRINTF(...) fprintf(stdout, __VA_ARGS__)
268
+ #ifdef UNICODE
269
+ #define DEBUG_TPRINTF(...) fwprintf(stdout, __VA_ARGS__)
270
+ #else
271
+ #define DEBUG_TPRINTF(...) fprintf(stdout, __VA_ARGS__)
272
+ #endif
273
+ #else
274
+ #define DEBUG_PRINTF(...) (void)0
275
+ #define DEBUG_TPRINTF(...) (void)0
276
+ #endif
277
+
278
+ #define REQ_ARGS(N) \
279
+ if (info.Length() < (N)) \
280
+ { \
281
+ Napi::TypeError::New(env, "Expected " #N " arguments").ThrowAsJavaScriptException(); \
282
+ return env.Undefined(); \
283
+ }
284
+
285
+ #define REQ_STR_ARG(I, VAR) \
286
+ if (info.Length() <= (I) || !info[I].IsString()) \
287
+ { \
288
+ Napi::TypeError::New(env, "Argument " #I " must be a string").ThrowAsJavaScriptException(); \
289
+ return env.Undefined(); \
290
+ } \
291
+ std::string VAR = info[I].As<Napi::String>().Utf8Value();
292
+
293
+ #define REQ_WSTR_ARG(I, VAR) \
294
+ if (info.Length() <= (I) || !info[I].IsString()) \
295
+ { \
296
+ Napi::TypeError::New(env, "Argument " #I " must be a string").ThrowAsJavaScriptException(); \
297
+ return env.Undefined(); \
298
+ } \
299
+ std::string VAR = info[I].As<Napi::String>().Utf8Value();
300
+
301
+ #define REQ_STRO_ARG(I, VAR) \
302
+ if (info.Length() <= (I) || !info[I].IsString()) \
303
+ { \
304
+ Napi::TypeError::New(env, "Argument " #I " must be a string").ThrowAsJavaScriptException(); \
305
+ return env.Undefined(); \
306
+ } \
307
+ std::string VAR = info[I].As<Napi::String>().Utf8Value();
308
+
309
+ #define REQ_STR_OR_NULL_ARG(I, VAR) \
310
+ if (info.Length() <= (I) || (!info[I].IsString() && !info[I].IsNull())) \
311
+ { \
312
+ Napi::TypeError::New(env, "Argument " #I " must be a string or null").ThrowAsJavaScriptException(); \
313
+ return env.Undefined(); \
314
+ } \
315
+ std::string VAR = info[I].IsNull() ? std::string("null") : info[I].As<Napi::String>().Utf8Value();
316
+
317
+ #define REQ_STRO_OR_NULL_ARG(I, VAR) \
318
+ if (info.Length() <= (I) || (!info[I].IsString() && !info[I].IsNull())) \
319
+ { \
320
+ Napi::TypeError::New(env, "Argument " #I " must be a string or null").ThrowAsJavaScriptException(); \
321
+ return env.Undefined(); \
322
+ } \
323
+ std::string VAR = info[I].IsNull() ? std::string("null") : info[I].As<Napi::String>().Utf8Value();
324
+
325
+ #define REQ_FUN_ARG(I, VAR) \
326
+ if (info.Length() <= (I) || !info[I].IsFunction()) \
327
+ { \
328
+ Napi::TypeError::New(env, "Argument " #I " must be a function").ThrowAsJavaScriptException(); \
329
+ return env.Undefined(); \
330
+ } \
331
+ Napi::Function VAR = info[I].As<Napi::Function>();
332
+
333
+ #define REQ_BOOL_ARG(I, VAR) \
334
+ if (info.Length() <= (I) || !info[I].IsBoolean()) \
335
+ { \
336
+ Napi::TypeError::New(env, "Argument " #I " must be a boolean").ThrowAsJavaScriptException(); \
337
+ return env.Undefined(); \
338
+ } \
339
+ bool VAR = info[I].As<Napi::Boolean>().Value();
340
+
341
+ #define REQ_EXT_ARG(I, VAR) \
342
+ if (info.Length() <= (I) || !info[I].IsExternal()) \
343
+ { \
344
+ Napi::TypeError::New(env, "Argument " #I " invalid").ThrowAsJavaScriptException(); \
345
+ return env.Undefined(); \
346
+ } \
347
+ Napi::External<void> VAR = info[I].As<Napi::External<void>>();
348
+
349
+ #define REQ_UINT_ARG(I, VAR) \
350
+ if (info.Length() <= (I) || !info[I].IsNumber()) \
351
+ { \
352
+ Napi::TypeError::New(env, "Argument " #I " invalid").ThrowAsJavaScriptException(); \
353
+ return env.Undefined(); \
354
+ } \
355
+ SQLUINTEGER VAR = info[I].As<Napi::Number>().Uint32Value();
356
+
357
+ #define REQ_INT_ARG(I, VAR) \
358
+ if (info.Length() <= (I) || !info[I].IsNumber()) \
359
+ { \
360
+ Napi::TypeError::New(env, "Argument " #I " invalid").ThrowAsJavaScriptException(); \
361
+ return env.Undefined(); \
362
+ } \
363
+ SQLINTEGER VAR = info[I].As<Napi::Number>().Int32Value();
364
+
365
+ #define OPT_INT_ARG(I, VAR, DEFAULT) \
366
+ SQLUSMALLINT VAR; \
367
+ if (info.Length() <= (I)) \
368
+ { \
369
+ VAR = (DEFAULT); \
370
+ } \
371
+ else if (info[I].IsNumber()) \
372
+ { \
373
+ VAR = info[I].As<Napi::Number>().Int32Value(); \
374
+ } \
375
+ else \
376
+ { \
377
+ Napi::TypeError::New(env, "Argument " #I " must be an integer").ThrowAsJavaScriptException();\
378
+ return env.Undefined(); \
379
+ }
380
+
381
+ // Check memory allocated successfully or not (for methods returning Napi::Value)
382
+ #define MEMCHECK(buffer) \
383
+ if (!buffer) \
384
+ { \
385
+ Napi::Error::New(env, "Could not allocate enough memory in ibm_db " \
386
+ "file " __FILE__ ":" LINENO(__LINE__)).ThrowAsJavaScriptException(); \
387
+ return env.Undefined(); \
388
+ }
389
+
390
+ // Macro to get c++ string from std::string (JS string via Utf8Value)
391
+ #ifdef UNICODE
392
+ #define GETCPPSTR(to, from, len) \
393
+ if (len > 0 && (size_t)(len) <= (SIZE_MAX / sizeof(uint16_t)) - 1 && \
394
+ from != "null") \
395
+ { \
396
+ to = (uint16_t *)malloc((len + 1) * sizeof(uint16_t)); \
397
+ MEMCHECK(to); \
398
+ memcpy(to, from.c_str(), len); \
399
+ ((uint16_t *)to)[len] = '\0'; \
400
+ } \
401
+ else \
402
+ { \
403
+ len = 0; \
404
+ }
405
+ #else
406
+ #define GETCPPSTR(to, from, len) \
407
+ if (len > 0 && (size_t)(len) <= SIZE_MAX - 1 && \
408
+ from != "null") \
409
+ { \
410
+ to = (char *)malloc(len + 1); \
411
+ MEMCHECK(to); \
412
+ memcpy(to, from.c_str(), len); \
413
+ ((char *)to)[len] = '\0'; \
414
+ } \
415
+ else \
416
+ { \
417
+ len = 0; \
418
+ }
419
+ #endif
420
+
421
+ // Check memory allocated (goto exit variant)
422
+ #define MEMCHECK2(buffer, errmsg) \
423
+ if (!buffer) \
424
+ { \
425
+ errmsg = "Could not allocate enough memory in ibm_db " \
426
+ "file " __FILE__ ":" LINENO(__LINE__); \
427
+ goto exit; \
428
+ }
429
+
430
+ // Macro to get c++ string from std::string (goto exit variant)
431
+ #ifdef UNICODE
432
+ #define GETCPPSTR2(to, from, len, errmsg) \
433
+ if (len > 0 && (size_t)(len) <= (SIZE_MAX / sizeof(uint16_t)) - 1 && \
434
+ from != "null") \
435
+ { \
436
+ to = (uint16_t *)malloc((len + 1) * sizeof(uint16_t)); \
437
+ if (to) \
438
+ { \
439
+ memcpy(to, from.c_str(), len); \
440
+ ((uint16_t *)to)[len] = '\0'; \
441
+ } \
442
+ else \
443
+ { \
444
+ errmsg = "Could not allocate enough memory in ibm_db " \
445
+ "file " __FILE__ ":" LINENO(__LINE__); \
446
+ goto exit; \
447
+ } \
448
+ } \
449
+ else \
450
+ { \
451
+ len = 0; \
452
+ }
453
+ #else
454
+ #define GETCPPSTR2(to, from, len, errmsg) \
455
+ if (len > 0 && (size_t)(len) <= SIZE_MAX - 1 && \
456
+ from != "null") \
457
+ { \
458
+ to = (char *)malloc(len + 1); \
459
+ if (to) \
460
+ { \
461
+ memcpy(to, from.c_str(), len); \
462
+ ((char *)to)[len] = '\0'; \
463
+ } \
464
+ else \
465
+ { \
466
+ errmsg = "Could not allocate enough memory in ibm_db " \
467
+ "file " __FILE__ ":" LINENO(__LINE__); \
468
+ goto exit; \
469
+ } \
470
+ } \
471
+ else \
472
+ { \
473
+ len = 0; \
474
+ }
475
+ #endif
476
+
477
+ #endif