@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,364 +1,364 @@
1
- // Test for issue #977:
2
- // When SQL_ATTR_ROW_ARRAY_SIZE > 1, ibm_db should use SQLBindCol-based
3
- // block fetch to correctly return all rows. With 20 rows and
4
- // ROW_ARRAY_SIZE=5, all 20 rows must be returned.
5
-
6
- var common = require("./common")
7
- , ibmdb = require("../")
8
- , assert = require("assert")
9
- , cn = common.connectionString
10
- ;
11
-
12
- var tableName = "TEST_ISSUE977";
13
-
14
- ibmdb.open(cn, function(err, conn) {
15
- if (err) { console.log(err); return; }
16
- console.log("Connection opened successfully.");
17
-
18
- // Drop table if exists
19
- try { conn.querySync("DROP TABLE " + tableName); } catch(e) {}
20
-
21
- // Create table and insert 20 rows
22
- conn.querySync("CREATE TABLE " + tableName +
23
- " (ID INTEGER, NAME VARCHAR(20))");
24
- for (var i = 1; i <= 20; i++) {
25
- conn.querySync("INSERT INTO " + tableName +
26
- " VALUES (" + i + ", 'Row" + i + "')");
27
- }
28
- console.log("Inserted 20 rows into " + tableName);
29
-
30
- // Verify all 20 rows exist using normal querySync (no ROW_ARRAY_SIZE)
31
- var allRows = conn.querySync("SELECT * FROM " + tableName + " ORDER BY ID");
32
- console.log("\nTest 0: querySync without ROW_ARRAY_SIZE = " +
33
- allRows.length + " rows (expected 20)");
34
- assert.equal(allRows.length, 20);
35
-
36
- testFetchAllSync();
37
-
38
- function testFetchAllSync() {
39
- // Test 1: prepare + setAttrSync(ROW_ARRAY_SIZE, 5) + fetchAllSync
40
- console.log("\nTest 1: fetchAllSync with SQL_ATTR_ROW_ARRAY_SIZE = 5");
41
- var stmt = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
42
- stmt.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
43
- var result = stmt.executeSync();
44
- var data = result.fetchAllSync();
45
- console.log(" Returned " + data.length + " rows (expected 20)");
46
- assert.equal(data.length, 20, "fetchAllSync should return 20 rows");
47
- // Verify all rows are present and in order
48
- for (var i = 0; i < 20; i++) {
49
- assert.equal(data[i].ID, i + 1,
50
- "Row " + i + " should have ID=" + (i + 1));
51
- assert.equal(data[i].NAME, "Row" + (i + 1));
52
- }
53
- console.log(" Data = ", data);
54
- console.log(" PASS: All 20 rows correctly returned with proper data.");
55
- result.closeSync();
56
- stmt.closeSync();
57
-
58
- testFetchAll();
59
- }
60
-
61
- function testFetchAll() {
62
- // Test 2: prepare + setAttrSync(ROW_ARRAY_SIZE, 5) + async fetchAll
63
- console.log("\nTest 2: async fetchAll with SQL_ATTR_ROW_ARRAY_SIZE = 5");
64
- var stmt2 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
65
- stmt2.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
66
- var result2 = stmt2.executeSync();
67
-
68
- result2.fetchAll(function(err, data2) {
69
- if (err) {
70
- console.log(" ERROR:", err);
71
- assert.fail("fetchAll should not error");
72
- }
73
- console.log(" Returned " + data2.length + " rows (expected 20)");
74
- assert.equal(data2.length, 20, "fetchAll should return 20 rows");
75
- for (var i = 0; i < 20; i++) {
76
- assert.equal(data2[i].ID, i + 1);
77
- }
78
- console.log(" PASS: All 20 rows correctly returned.");
79
- result2.closeSync();
80
- stmt2.closeSync();
81
-
82
- testFetchSync();
83
- });
84
- }
85
-
86
- function testFetchSync() {
87
- // Test 3: prepare + setAttrSync(ROW_ARRAY_SIZE, 5) + fetchSync loop
88
- // fetchSync returns an array of up to ROW_ARRAY_SIZE rows per call
89
- console.log("\nTest 3: fetchSync loop with SQL_ATTR_ROW_ARRAY_SIZE = 5");
90
- var stmt3 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
91
- stmt3.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
92
- var result3 = stmt3.executeSync();
93
-
94
- var allRows = [];
95
- var blockCount = 0;
96
- var block;
97
- while ((block = result3.fetchSync()) !== null) {
98
- blockCount++;
99
- assert.ok(Array.isArray(block), "fetchSync should return an array when ROW_ARRAY_SIZE > 1");
100
- assert.ok(block.length <= 5, "Block should have at most ROW_ARRAY_SIZE rows");
101
- console.log(" Block " + blockCount + ": " + block.length + " rows");
102
- console.log(" Block data = ", block);
103
- for (var i = 0; i < block.length; i++) {
104
- allRows.push(block[i]);
105
- }
106
- }
107
- console.log(" Total: " + allRows.length + " rows in " + blockCount + " blocks (expected 20 rows, 4 blocks)");
108
- assert.equal(allRows.length, 20, "fetchSync should return 20 total rows");
109
- assert.equal(blockCount, 4, "Should fetch 4 blocks of 5 rows each");
110
- for (var i = 0; i < 20; i++) {
111
- assert.equal(allRows[i].ID, i + 1);
112
- }
113
- console.log(" PASS: All 20 rows correctly returned in 4 blocks of 5.");
114
- result3.closeSync();
115
- stmt3.closeSync();
116
-
117
- testFetchNSync();
118
- }
119
-
120
- function testFetchNSync() {
121
- // Test 4: prepare + setAttrSync(ROW_ARRAY_SIZE, 5) + fetchNSync
122
- console.log("\nTest 4: fetchNSync(10) with SQL_ATTR_ROW_ARRAY_SIZE = 5");
123
- var stmt4 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
124
- stmt4.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
125
- var result4 = stmt4.executeSync();
126
-
127
- var batch1 = result4.fetchNSync(10);
128
- console.log(" Batch 1: " + batch1.length + " rows (expected 10)");
129
- assert.equal(batch1.length, 10, "fetchNSync(10) should return 10 rows");
130
- console.log(" Batch 1 data = ", batch1);
131
- for (var i = 0; i < 10; i++) {
132
- assert.equal(batch1[i].ID, i + 1);
133
- }
134
-
135
- var batch2 = result4.fetchNSync(10);
136
- console.log(" Batch 2: " + batch2.length + " rows (expected 10)");
137
- assert.equal(batch2.length, 10, "fetchNSync(10) should return 10 rows");
138
- console.log(" Batch 2 data = ", batch2);
139
- for (var i = 0; i < 10; i++) {
140
- assert.equal(batch2[i].ID, i + 11);
141
- }
142
-
143
- var batch3 = result4.fetchNSync(10);
144
- console.log(" Batch 3: " + batch3.length + " rows (expected 0)");
145
- assert.equal(batch3.length, 0, "fetchNSync(10) after all rows should return 0");
146
-
147
- console.log(" PASS: fetchNSync correctly batched all 20 rows.");
148
- result4.closeSync();
149
- stmt4.closeSync();
150
-
151
- testFetchArrayMode();
152
- }
153
-
154
- function testFetchArrayMode() {
155
- // Test 5: fetchAllSync with FETCH_ARRAY mode and ROW_ARRAY_SIZE=5
156
- console.log("\nTest 5: fetchAllSync FETCH_ARRAY with SQL_ATTR_ROW_ARRAY_SIZE = 5");
157
- var stmt5 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
158
- stmt5.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
159
- var result5 = stmt5.executeSync();
160
- var data5 = result5.fetchAllSync({fetchMode: 3}); // FETCH_ARRAY = 3
161
- console.log(" Returned " + data5.length + " rows (expected 20)");
162
- assert.equal(data5.length, 20, "fetchAllSync FETCH_ARRAY should return 20 rows");
163
- assert.equal(data5[0][0], 1, "First row ID should be 1");
164
- assert.equal(data5[0][1], "Row1", "First row NAME should be 'Row1'");
165
- assert.equal(data5[19][0], 20, "Last row ID should be 20");
166
- console.log(" PASS: All 20 rows correctly returned as arrays.");
167
- result5.closeSync();
168
- stmt5.closeSync();
169
-
170
- testFetchAsync();
171
- }
172
-
173
- function testFetchAsync() {
174
- // Test 6: async fetch() (callback) with ROW_ARRAY_SIZE=5
175
- // fetch() returns an array of up to ROW_ARRAY_SIZE rows per callback
176
- console.log("\nTest 6: async fetch() callback with SQL_ATTR_ROW_ARRAY_SIZE = 5");
177
- var stmt6 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
178
- stmt6.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
179
- var result6 = stmt6.executeSync();
180
- var allRows6 = [];
181
- var blockCount6 = 0;
182
-
183
- function fetchNext() {
184
- result6.fetch(function(err, block) {
185
- if (err) {
186
- console.log(" ERROR:", err);
187
- assert.fail("fetch() should not error");
188
- return;
189
- }
190
- if (block) {
191
- blockCount6++;
192
- assert.ok(Array.isArray(block), "fetch() should return an array when ROW_ARRAY_SIZE > 1");
193
- assert.ok(block.length <= 5, "Block should have at most ROW_ARRAY_SIZE rows");
194
- console.log(" Block " + blockCount6 + ": " + block.length + " rows");
195
- console.log(" Block data = ", block);
196
- for (var i = 0; i < block.length; i++) {
197
- allRows6.push(block[i]);
198
- }
199
- fetchNext();
200
- } else {
201
- console.log(" Total: " + allRows6.length + " rows in " + blockCount6 + " blocks (expected 20 rows, 4 blocks)");
202
- assert.equal(allRows6.length, 20, "fetch() should return 20 total rows");
203
- assert.equal(blockCount6, 4, "Should fetch 4 blocks of 5 rows each");
204
- for (var i = 0; i < 20; i++) {
205
- assert.equal(allRows6[i].ID, i + 1);
206
- }
207
- console.log(" PASS: All 20 rows correctly returned via async fetch() in 4 blocks.");
208
- result6.closeSync();
209
- stmt6.closeSync();
210
-
211
- testFetchNAsync();
212
- }
213
- });
214
- }
215
- fetchNext();
216
- }
217
-
218
- function testFetchNAsync() {
219
- // Test 7: async fetchN() (callback) with ROW_ARRAY_SIZE=5
220
- console.log("\nTest 7: async fetchN() callback with SQL_ATTR_ROW_ARRAY_SIZE = 5");
221
- var stmt7 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
222
- stmt7.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
223
- var result7 = stmt7.executeSync();
224
-
225
- result7.fetchN(10, function(err, batch1) {
226
- if (err) { console.log(" ERROR:", err); assert.fail("fetchN should not error"); }
227
- console.log(" Batch 1: " + batch1.length + " rows (expected 10)");
228
- assert.equal(batch1.length, 10, "fetchN(10) should return 10 rows");
229
- for (var i = 0; i < 10; i++) {
230
- assert.equal(batch1[i].ID, i + 1);
231
- }
232
-
233
- result7.fetchN(10, function(err, batch2) {
234
- if (err) { console.log(" ERROR:", err); assert.fail("fetchN should not error"); }
235
- console.log(" Batch 2: " + batch2.length + " rows (expected 10)");
236
- assert.equal(batch2.length, 10, "fetchN(10) should return 10 rows");
237
- for (var i = 0; i < 10; i++) {
238
- assert.equal(batch2[i].ID, i + 11);
239
- }
240
-
241
- result7.fetchN(10, function(err, batch3) {
242
- if (err) { console.log(" ERROR:", err); assert.fail("fetchN should not error"); }
243
- console.log(" Batch 3: " + batch3.length + " rows (expected 0)");
244
- assert.equal(batch3.length, 0, "fetchN(10) after all rows should return 0");
245
-
246
- console.log(" PASS: async fetchN() correctly batched all 20 rows.");
247
- result7.closeSync();
248
- stmt7.closeSync();
249
-
250
- testAsyncAwait();
251
- });
252
- });
253
- });
254
- }
255
-
256
- function testAsyncAwait() {
257
- // Test 8: async/await with all APIs and ROW_ARRAY_SIZE=5
258
- console.log("\nTest 8: async/await with SQL_ATTR_ROW_ARRAY_SIZE = 5");
259
- asyncAwaitTests().then(function() {
260
- cleanup();
261
- }).catch(function(err) {
262
- console.log(" async/await test error:", err);
263
- assert.fail("async/await tests should not error");
264
- });
265
- }
266
-
267
- async function asyncAwaitTests() {
268
- // 8a: fetchAll via Promise/await
269
- console.log(" 8a: await fetchAll()");
270
- var stmt8a = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
271
- stmt8a.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
272
- var result8a = stmt8a.executeSync();
273
- var data8a = await result8a.fetchAll();
274
- console.log(" Returned " + data8a.length + " rows (expected 20)");
275
- assert.equal(data8a.length, 20, "await fetchAll() should return 20 rows");
276
- for (var i = 0; i < 20; i++) {
277
- assert.equal(data8a[i].ID, i + 1);
278
- }
279
- console.log(" PASS");
280
- result8a.closeSync();
281
- stmt8a.closeSync();
282
-
283
- // 8b: fetch via Promise/await loop - returns array of rows per block
284
- console.log(" 8b: await fetch() blocks");
285
- var stmt8b = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
286
- stmt8b.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
287
- var result8b = stmt8b.executeSync();
288
- var rows8b = [];
289
- var blockCount8b = 0;
290
- var block8b;
291
- while ((block8b = await result8b.fetch()) !== null) {
292
- blockCount8b++;
293
- assert.ok(Array.isArray(block8b), "await fetch() should return an array when ROW_ARRAY_SIZE > 1");
294
- console.log(" Block data = ", block8b);
295
- for (var i = 0; i < block8b.length; i++) {
296
- rows8b.push(block8b[i]);
297
- }
298
- }
299
- console.log(" Returned " + rows8b.length + " rows in " + blockCount8b + " blocks (expected 20 rows, 4 blocks)");
300
- assert.equal(rows8b.length, 20, "await fetch() should return 20 total rows");
301
- assert.equal(blockCount8b, 4, "Should fetch 4 blocks of 5 rows each");
302
- for (var i = 0; i < 20; i++) {
303
- assert.equal(rows8b[i].ID, i + 1);
304
- }
305
- console.log(" PASS");
306
- result8b.closeSync();
307
- stmt8b.closeSync();
308
-
309
- // 8c: fetchN via Promise/await batches
310
- console.log(" 8c: await fetchN() batches");
311
- var stmt8c = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
312
- stmt8c.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
313
- var result8c = stmt8c.executeSync();
314
- var b1 = await result8c.fetchN(7);
315
- console.log(" Batch 1: " + b1.length + " rows (expected 7)");
316
- assert.equal(b1.length, 7, "await fetchN(7) should return 7 rows");
317
- assert.equal(b1[0].ID, 1);
318
- assert.equal(b1[6].ID, 7);
319
-
320
- var b2 = await result8c.fetchN(7);
321
- console.log(" Batch 2: " + b2.length + " rows (expected 7)");
322
- assert.equal(b2.length, 7, "await fetchN(7) should return 7 rows");
323
- assert.equal(b2[0].ID, 8);
324
- assert.equal(b2[6].ID, 14);
325
-
326
- var b3 = await result8c.fetchN(7);
327
- console.log(" Batch 3: " + b3.length + " rows (expected 6)");
328
- assert.equal(b3.length, 6, "await fetchN(7) should return remaining 6 rows");
329
- assert.equal(b3[0].ID, 15);
330
- assert.equal(b3[5].ID, 20);
331
-
332
- var b4 = await result8c.fetchN(7);
333
- console.log(" Batch 4: " + b4.length + " rows (expected 0)");
334
- assert.equal(b4.length, 0, "await fetchN(7) after all rows should return 0");
335
-
336
- console.log(" PASS");
337
- result8c.closeSync();
338
- stmt8c.closeSync();
339
-
340
- // 8d: full async/await using ibmdb.open Promise
341
- console.log(" 8d: full async/await with ibmdb.open");
342
- var conn2 = await ibmdb.open(cn);
343
- var stmt8d = conn2.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
344
- stmt8d.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
345
- var result8d = stmt8d.executeSync();
346
- var data8d = await result8d.fetchAll();
347
- assert.equal(data8d.length, 20, "full async/await should return 20 rows");
348
- for (var i = 0; i < 20; i++) {
349
- assert.equal(data8d[i].ID, i + 1);
350
- assert.equal(data8d[i].NAME, "Row" + (i + 1));
351
- }
352
- console.log(" Returned " + data8d.length + " rows - PASS");
353
- result8d.closeSync();
354
- stmt8d.closeSync();
355
- await conn2.close();
356
- console.log(" PASS: All async/await tests passed.");
357
- }
358
-
359
- function cleanup() {
360
- conn.querySync("DROP TABLE " + tableName);
361
- conn.closeSync();
362
- console.log("\nAll tests passed! Connection closed.");
363
- }
364
- });
1
+ // Test for issue #977:
2
+ // When SQL_ATTR_ROW_ARRAY_SIZE > 1, ibm_db should use SQLBindCol-based
3
+ // block fetch to correctly return all rows. With 20 rows and
4
+ // ROW_ARRAY_SIZE=5, all 20 rows must be returned.
5
+
6
+ var common = require("./common")
7
+ , ibmdb = require("../")
8
+ , assert = require("assert")
9
+ , cn = common.connectionString
10
+ ;
11
+
12
+ var tableName = "TEST_ISSUE977";
13
+
14
+ ibmdb.open(cn, function(err, conn) {
15
+ if (err) { console.log(err); return; }
16
+ console.log("Connection opened successfully.");
17
+
18
+ // Drop table if exists
19
+ try { conn.querySync("DROP TABLE " + tableName); } catch(e) {}
20
+
21
+ // Create table and insert 20 rows
22
+ conn.querySync("CREATE TABLE " + tableName +
23
+ " (ID INTEGER, NAME VARCHAR(20))");
24
+ for (var i = 1; i <= 20; i++) {
25
+ conn.querySync("INSERT INTO " + tableName +
26
+ " VALUES (" + i + ", 'Row" + i + "')");
27
+ }
28
+ console.log("Inserted 20 rows into " + tableName);
29
+
30
+ // Verify all 20 rows exist using normal querySync (no ROW_ARRAY_SIZE)
31
+ var allRows = conn.querySync("SELECT * FROM " + tableName + " ORDER BY ID");
32
+ console.log("\nTest 0: querySync without ROW_ARRAY_SIZE = " +
33
+ allRows.length + " rows (expected 20)");
34
+ assert.equal(allRows.length, 20);
35
+
36
+ testFetchAllSync();
37
+
38
+ function testFetchAllSync() {
39
+ // Test 1: prepare + setAttrSync(ROW_ARRAY_SIZE, 5) + fetchAllSync
40
+ console.log("\nTest 1: fetchAllSync with SQL_ATTR_ROW_ARRAY_SIZE = 5");
41
+ var stmt = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
42
+ stmt.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
43
+ var result = stmt.executeSync();
44
+ var data = result.fetchAllSync();
45
+ console.log(" Returned " + data.length + " rows (expected 20)");
46
+ assert.equal(data.length, 20, "fetchAllSync should return 20 rows");
47
+ // Verify all rows are present and in order
48
+ for (var i = 0; i < 20; i++) {
49
+ assert.equal(data[i].ID, i + 1,
50
+ "Row " + i + " should have ID=" + (i + 1));
51
+ assert.equal(data[i].NAME, "Row" + (i + 1));
52
+ }
53
+ console.log(" Data = ", data);
54
+ console.log(" PASS: All 20 rows correctly returned with proper data.");
55
+ result.closeSync();
56
+ stmt.closeSync();
57
+
58
+ testFetchAll();
59
+ }
60
+
61
+ function testFetchAll() {
62
+ // Test 2: prepare + setAttrSync(ROW_ARRAY_SIZE, 5) + async fetchAll
63
+ console.log("\nTest 2: async fetchAll with SQL_ATTR_ROW_ARRAY_SIZE = 5");
64
+ var stmt2 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
65
+ stmt2.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
66
+ var result2 = stmt2.executeSync();
67
+
68
+ result2.fetchAll(function(err, data2) {
69
+ if (err) {
70
+ console.log(" ERROR:", err);
71
+ assert.fail("fetchAll should not error");
72
+ }
73
+ console.log(" Returned " + data2.length + " rows (expected 20)");
74
+ assert.equal(data2.length, 20, "fetchAll should return 20 rows");
75
+ for (var i = 0; i < 20; i++) {
76
+ assert.equal(data2[i].ID, i + 1);
77
+ }
78
+ console.log(" PASS: All 20 rows correctly returned.");
79
+ result2.closeSync();
80
+ stmt2.closeSync();
81
+
82
+ testFetchSync();
83
+ });
84
+ }
85
+
86
+ function testFetchSync() {
87
+ // Test 3: prepare + setAttrSync(ROW_ARRAY_SIZE, 5) + fetchSync loop
88
+ // fetchSync returns an array of up to ROW_ARRAY_SIZE rows per call
89
+ console.log("\nTest 3: fetchSync loop with SQL_ATTR_ROW_ARRAY_SIZE = 5");
90
+ var stmt3 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
91
+ stmt3.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
92
+ var result3 = stmt3.executeSync();
93
+
94
+ var allRows = [];
95
+ var blockCount = 0;
96
+ var block;
97
+ while ((block = result3.fetchSync()) !== null) {
98
+ blockCount++;
99
+ assert.ok(Array.isArray(block), "fetchSync should return an array when ROW_ARRAY_SIZE > 1");
100
+ assert.ok(block.length <= 5, "Block should have at most ROW_ARRAY_SIZE rows");
101
+ console.log(" Block " + blockCount + ": " + block.length + " rows");
102
+ console.log(" Block data = ", block);
103
+ for (var i = 0; i < block.length; i++) {
104
+ allRows.push(block[i]);
105
+ }
106
+ }
107
+ console.log(" Total: " + allRows.length + " rows in " + blockCount + " blocks (expected 20 rows, 4 blocks)");
108
+ assert.equal(allRows.length, 20, "fetchSync should return 20 total rows");
109
+ assert.equal(blockCount, 4, "Should fetch 4 blocks of 5 rows each");
110
+ for (var i = 0; i < 20; i++) {
111
+ assert.equal(allRows[i].ID, i + 1);
112
+ }
113
+ console.log(" PASS: All 20 rows correctly returned in 4 blocks of 5.");
114
+ result3.closeSync();
115
+ stmt3.closeSync();
116
+
117
+ testFetchNSync();
118
+ }
119
+
120
+ function testFetchNSync() {
121
+ // Test 4: prepare + setAttrSync(ROW_ARRAY_SIZE, 5) + fetchNSync
122
+ console.log("\nTest 4: fetchNSync(10) with SQL_ATTR_ROW_ARRAY_SIZE = 5");
123
+ var stmt4 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
124
+ stmt4.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
125
+ var result4 = stmt4.executeSync();
126
+
127
+ var batch1 = result4.fetchNSync(10);
128
+ console.log(" Batch 1: " + batch1.length + " rows (expected 10)");
129
+ assert.equal(batch1.length, 10, "fetchNSync(10) should return 10 rows");
130
+ console.log(" Batch 1 data = ", batch1);
131
+ for (var i = 0; i < 10; i++) {
132
+ assert.equal(batch1[i].ID, i + 1);
133
+ }
134
+
135
+ var batch2 = result4.fetchNSync(10);
136
+ console.log(" Batch 2: " + batch2.length + " rows (expected 10)");
137
+ assert.equal(batch2.length, 10, "fetchNSync(10) should return 10 rows");
138
+ console.log(" Batch 2 data = ", batch2);
139
+ for (var i = 0; i < 10; i++) {
140
+ assert.equal(batch2[i].ID, i + 11);
141
+ }
142
+
143
+ var batch3 = result4.fetchNSync(10);
144
+ console.log(" Batch 3: " + batch3.length + " rows (expected 0)");
145
+ assert.equal(batch3.length, 0, "fetchNSync(10) after all rows should return 0");
146
+
147
+ console.log(" PASS: fetchNSync correctly batched all 20 rows.");
148
+ result4.closeSync();
149
+ stmt4.closeSync();
150
+
151
+ testFetchArrayMode();
152
+ }
153
+
154
+ function testFetchArrayMode() {
155
+ // Test 5: fetchAllSync with FETCH_ARRAY mode and ROW_ARRAY_SIZE=5
156
+ console.log("\nTest 5: fetchAllSync FETCH_ARRAY with SQL_ATTR_ROW_ARRAY_SIZE = 5");
157
+ var stmt5 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
158
+ stmt5.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
159
+ var result5 = stmt5.executeSync();
160
+ var data5 = result5.fetchAllSync({fetchMode: 3}); // FETCH_ARRAY = 3
161
+ console.log(" Returned " + data5.length + " rows (expected 20)");
162
+ assert.equal(data5.length, 20, "fetchAllSync FETCH_ARRAY should return 20 rows");
163
+ assert.equal(data5[0][0], 1, "First row ID should be 1");
164
+ assert.equal(data5[0][1], "Row1", "First row NAME should be 'Row1'");
165
+ assert.equal(data5[19][0], 20, "Last row ID should be 20");
166
+ console.log(" PASS: All 20 rows correctly returned as arrays.");
167
+ result5.closeSync();
168
+ stmt5.closeSync();
169
+
170
+ testFetchAsync();
171
+ }
172
+
173
+ function testFetchAsync() {
174
+ // Test 6: async fetch() (callback) with ROW_ARRAY_SIZE=5
175
+ // fetch() returns an array of up to ROW_ARRAY_SIZE rows per callback
176
+ console.log("\nTest 6: async fetch() callback with SQL_ATTR_ROW_ARRAY_SIZE = 5");
177
+ var stmt6 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
178
+ stmt6.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
179
+ var result6 = stmt6.executeSync();
180
+ var allRows6 = [];
181
+ var blockCount6 = 0;
182
+
183
+ function fetchNext() {
184
+ result6.fetch(function(err, block) {
185
+ if (err) {
186
+ console.log(" ERROR:", err);
187
+ assert.fail("fetch() should not error");
188
+ return;
189
+ }
190
+ if (block) {
191
+ blockCount6++;
192
+ assert.ok(Array.isArray(block), "fetch() should return an array when ROW_ARRAY_SIZE > 1");
193
+ assert.ok(block.length <= 5, "Block should have at most ROW_ARRAY_SIZE rows");
194
+ console.log(" Block " + blockCount6 + ": " + block.length + " rows");
195
+ console.log(" Block data = ", block);
196
+ for (var i = 0; i < block.length; i++) {
197
+ allRows6.push(block[i]);
198
+ }
199
+ fetchNext();
200
+ } else {
201
+ console.log(" Total: " + allRows6.length + " rows in " + blockCount6 + " blocks (expected 20 rows, 4 blocks)");
202
+ assert.equal(allRows6.length, 20, "fetch() should return 20 total rows");
203
+ assert.equal(blockCount6, 4, "Should fetch 4 blocks of 5 rows each");
204
+ for (var i = 0; i < 20; i++) {
205
+ assert.equal(allRows6[i].ID, i + 1);
206
+ }
207
+ console.log(" PASS: All 20 rows correctly returned via async fetch() in 4 blocks.");
208
+ result6.closeSync();
209
+ stmt6.closeSync();
210
+
211
+ testFetchNAsync();
212
+ }
213
+ });
214
+ }
215
+ fetchNext();
216
+ }
217
+
218
+ function testFetchNAsync() {
219
+ // Test 7: async fetchN() (callback) with ROW_ARRAY_SIZE=5
220
+ console.log("\nTest 7: async fetchN() callback with SQL_ATTR_ROW_ARRAY_SIZE = 5");
221
+ var stmt7 = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
222
+ stmt7.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
223
+ var result7 = stmt7.executeSync();
224
+
225
+ result7.fetchN(10, function(err, batch1) {
226
+ if (err) { console.log(" ERROR:", err); assert.fail("fetchN should not error"); }
227
+ console.log(" Batch 1: " + batch1.length + " rows (expected 10)");
228
+ assert.equal(batch1.length, 10, "fetchN(10) should return 10 rows");
229
+ for (var i = 0; i < 10; i++) {
230
+ assert.equal(batch1[i].ID, i + 1);
231
+ }
232
+
233
+ result7.fetchN(10, function(err, batch2) {
234
+ if (err) { console.log(" ERROR:", err); assert.fail("fetchN should not error"); }
235
+ console.log(" Batch 2: " + batch2.length + " rows (expected 10)");
236
+ assert.equal(batch2.length, 10, "fetchN(10) should return 10 rows");
237
+ for (var i = 0; i < 10; i++) {
238
+ assert.equal(batch2[i].ID, i + 11);
239
+ }
240
+
241
+ result7.fetchN(10, function(err, batch3) {
242
+ if (err) { console.log(" ERROR:", err); assert.fail("fetchN should not error"); }
243
+ console.log(" Batch 3: " + batch3.length + " rows (expected 0)");
244
+ assert.equal(batch3.length, 0, "fetchN(10) after all rows should return 0");
245
+
246
+ console.log(" PASS: async fetchN() correctly batched all 20 rows.");
247
+ result7.closeSync();
248
+ stmt7.closeSync();
249
+
250
+ testAsyncAwait();
251
+ });
252
+ });
253
+ });
254
+ }
255
+
256
+ function testAsyncAwait() {
257
+ // Test 8: async/await with all APIs and ROW_ARRAY_SIZE=5
258
+ console.log("\nTest 8: async/await with SQL_ATTR_ROW_ARRAY_SIZE = 5");
259
+ asyncAwaitTests().then(function() {
260
+ cleanup();
261
+ }).catch(function(err) {
262
+ console.log(" async/await test error:", err);
263
+ assert.fail("async/await tests should not error");
264
+ });
265
+ }
266
+
267
+ async function asyncAwaitTests() {
268
+ // 8a: fetchAll via Promise/await
269
+ console.log(" 8a: await fetchAll()");
270
+ var stmt8a = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
271
+ stmt8a.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
272
+ var result8a = stmt8a.executeSync();
273
+ var data8a = await result8a.fetchAll();
274
+ console.log(" Returned " + data8a.length + " rows (expected 20)");
275
+ assert.equal(data8a.length, 20, "await fetchAll() should return 20 rows");
276
+ for (var i = 0; i < 20; i++) {
277
+ assert.equal(data8a[i].ID, i + 1);
278
+ }
279
+ console.log(" PASS");
280
+ result8a.closeSync();
281
+ stmt8a.closeSync();
282
+
283
+ // 8b: fetch via Promise/await loop - returns array of rows per block
284
+ console.log(" 8b: await fetch() blocks");
285
+ var stmt8b = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
286
+ stmt8b.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
287
+ var result8b = stmt8b.executeSync();
288
+ var rows8b = [];
289
+ var blockCount8b = 0;
290
+ var block8b;
291
+ while ((block8b = await result8b.fetch()) !== null) {
292
+ blockCount8b++;
293
+ assert.ok(Array.isArray(block8b), "await fetch() should return an array when ROW_ARRAY_SIZE > 1");
294
+ console.log(" Block data = ", block8b);
295
+ for (var i = 0; i < block8b.length; i++) {
296
+ rows8b.push(block8b[i]);
297
+ }
298
+ }
299
+ console.log(" Returned " + rows8b.length + " rows in " + blockCount8b + " blocks (expected 20 rows, 4 blocks)");
300
+ assert.equal(rows8b.length, 20, "await fetch() should return 20 total rows");
301
+ assert.equal(blockCount8b, 4, "Should fetch 4 blocks of 5 rows each");
302
+ for (var i = 0; i < 20; i++) {
303
+ assert.equal(rows8b[i].ID, i + 1);
304
+ }
305
+ console.log(" PASS");
306
+ result8b.closeSync();
307
+ stmt8b.closeSync();
308
+
309
+ // 8c: fetchN via Promise/await batches
310
+ console.log(" 8c: await fetchN() batches");
311
+ var stmt8c = conn.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
312
+ stmt8c.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
313
+ var result8c = stmt8c.executeSync();
314
+ var b1 = await result8c.fetchN(7);
315
+ console.log(" Batch 1: " + b1.length + " rows (expected 7)");
316
+ assert.equal(b1.length, 7, "await fetchN(7) should return 7 rows");
317
+ assert.equal(b1[0].ID, 1);
318
+ assert.equal(b1[6].ID, 7);
319
+
320
+ var b2 = await result8c.fetchN(7);
321
+ console.log(" Batch 2: " + b2.length + " rows (expected 7)");
322
+ assert.equal(b2.length, 7, "await fetchN(7) should return 7 rows");
323
+ assert.equal(b2[0].ID, 8);
324
+ assert.equal(b2[6].ID, 14);
325
+
326
+ var b3 = await result8c.fetchN(7);
327
+ console.log(" Batch 3: " + b3.length + " rows (expected 6)");
328
+ assert.equal(b3.length, 6, "await fetchN(7) should return remaining 6 rows");
329
+ assert.equal(b3[0].ID, 15);
330
+ assert.equal(b3[5].ID, 20);
331
+
332
+ var b4 = await result8c.fetchN(7);
333
+ console.log(" Batch 4: " + b4.length + " rows (expected 0)");
334
+ assert.equal(b4.length, 0, "await fetchN(7) after all rows should return 0");
335
+
336
+ console.log(" PASS");
337
+ result8c.closeSync();
338
+ stmt8c.closeSync();
339
+
340
+ // 8d: full async/await using ibmdb.open Promise
341
+ console.log(" 8d: full async/await with ibmdb.open");
342
+ var conn2 = await ibmdb.open(cn);
343
+ var stmt8d = conn2.prepareSync("SELECT * FROM " + tableName + " ORDER BY ID");
344
+ stmt8d.setAttrSync(ibmdb.SQL_ATTR_ROW_ARRAY_SIZE, 5);
345
+ var result8d = stmt8d.executeSync();
346
+ var data8d = await result8d.fetchAll();
347
+ assert.equal(data8d.length, 20, "full async/await should return 20 rows");
348
+ for (var i = 0; i < 20; i++) {
349
+ assert.equal(data8d[i].ID, i + 1);
350
+ assert.equal(data8d[i].NAME, "Row" + (i + 1));
351
+ }
352
+ console.log(" Returned " + data8d.length + " rows - PASS");
353
+ result8d.closeSync();
354
+ stmt8d.closeSync();
355
+ await conn2.close();
356
+ console.log(" PASS: All async/await tests passed.");
357
+ }
358
+
359
+ function cleanup() {
360
+ conn.querySync("DROP TABLE " + tableName);
361
+ conn.closeSync();
362
+ console.log("\nAll tests passed! Connection closed.");
363
+ }
364
+ });