@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.
- package/README.md +12 -10
- package/lib/Db2PluginLifeCycle.d.ts +11 -9
- package/lib/Db2PluginLifeCycle.js +18 -13
- package/lib/Db2PluginLifeCycle.js.map +1 -1
- package/node_modules/axios/CHANGELOG.md +62 -0
- package/node_modules/axios/README.md +233 -5
- package/node_modules/axios/dist/axios.js +387 -89
- package/node_modules/axios/dist/axios.min.js +3 -3
- package/node_modules/axios/dist/axios.min.js.map +1 -1
- package/node_modules/axios/dist/browser/axios.cjs +458 -98
- package/node_modules/axios/dist/esm/axios.js +458 -98
- package/node_modules/axios/dist/esm/axios.min.js +2 -2
- package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
- package/node_modules/axios/dist/node/axios.cjs +568 -116
- package/node_modules/axios/index.d.cts +4 -0
- package/node_modules/axios/index.d.ts +4 -0
- package/node_modules/axios/lib/adapters/fetch.js +64 -11
- package/node_modules/axios/lib/adapters/http.js +134 -50
- package/node_modules/axios/lib/adapters/xhr.js +52 -3
- package/node_modules/axios/lib/core/Axios.js +19 -14
- package/node_modules/axios/lib/core/InterceptorManager.js +107 -8
- package/node_modules/axios/lib/core/buildFullPath.js +1 -13
- package/node_modules/axios/lib/core/dispatchRequest.js +8 -2
- package/node_modules/axios/lib/core/mergeConfig.js +1 -1
- package/node_modules/axios/lib/core/methodList.js +17 -0
- package/node_modules/axios/lib/defaults/index.js +2 -1
- package/node_modules/axios/lib/env/data.js +1 -1
- package/node_modules/axios/lib/helpers/Http2Sessions.js +2 -0
- package/node_modules/axios/lib/helpers/HttpStatusCode.js +11 -1
- package/node_modules/axios/lib/helpers/fromDataURI.js +5 -4
- package/node_modules/axios/lib/helpers/normalizeURLForProtocolCheck.js +24 -0
- package/node_modules/axios/lib/helpers/progressEventReducer.js +1 -1
- package/node_modules/axios/lib/helpers/resolveConfig.js +4 -2
- package/node_modules/axios/lib/helpers/shouldBypassProxy.js +182 -6
- package/node_modules/axios/lib/helpers/throttle.js +3 -2
- package/node_modules/axios/lib/helpers/toFormData.js +14 -21
- package/node_modules/axios/lib/utils.js +134 -13
- package/node_modules/axios/package.json +1 -1
- package/node_modules/ibm_db/APIDocumentation.md +2883 -2024
- package/node_modules/ibm_db/LICENSE +23 -23
- package/node_modules/ibm_db/README.md +735 -735
- package/node_modules/ibm_db/binding.gyp +99 -98
- package/node_modules/ibm_db/installer/driverInstall.js +984 -958
- package/node_modules/ibm_db/installer/ifx.sh +38 -38
- package/node_modules/ibm_db/installer/setenv.sh +23 -23
- package/node_modules/ibm_db/installer/testODBCConnection.bat +51 -51
- package/node_modules/ibm_db/installer/testODBCConnection.sh +61 -61
- package/node_modules/ibm_db/lib/climacros.js +431 -431
- package/node_modules/ibm_db/lib/odbc.js +4293 -3487
- package/node_modules/ibm_db/lib/simple-queue.js +41 -41
- package/node_modules/ibm_db/package.json +70 -70
- package/node_modules/ibm_db/src/odbc.cpp +1495 -1396
- package/node_modules/ibm_db/src/odbc.h +477 -473
- package/node_modules/ibm_db/src/odbc_connection.cpp +1762 -1612
- package/node_modules/ibm_db/src/odbc_connection.h +228 -215
- package/node_modules/ibm_db/src/odbc_result.cpp +1547 -1547
- package/node_modules/ibm_db/src/odbc_result.h +152 -152
- package/node_modules/ibm_db/src/odbc_statement.cpp +2047 -861
- package/node_modules/ibm_db/src/odbc_statement.h +257 -135
- package/node_modules/ibm_db/src/strptime.c +389 -389
- package/node_modules/ibm_db/src/strptime.h +46 -46
- package/node_modules/ibm_db/test/README +23 -23
- package/node_modules/ibm_db/test/bench-insert.js +62 -62
- package/node_modules/ibm_db/test/bench-insertBatch10.js +74 -74
- package/node_modules/ibm_db/test/bench-insertBatch100.js +75 -75
- package/node_modules/ibm_db/test/bench-insertBatch1000.js +75 -75
- package/node_modules/ibm_db/test/bench-insertBatch10000.js +75 -75
- package/node_modules/ibm_db/test/bench-prepare-bind-execute-closeSync.js +60 -60
- package/node_modules/ibm_db/test/bench-prepare-bind-executeNonQuery.js +53 -53
- package/node_modules/ibm_db/test/bench-prepare-bindSync-execute-closeSync.js +50 -50
- package/node_modules/ibm_db/test/bench-prepare-bindSync-executeNonQuery.js +48 -48
- package/node_modules/ibm_db/test/bench-prepare-execute-closeSync.js +51 -51
- package/node_modules/ibm_db/test/bench-prepare-executeNonQuery.js +47 -47
- package/node_modules/ibm_db/test/bench-prepare-not.js +43 -43
- package/node_modules/ibm_db/test/bench-query-fetch.js +59 -59
- package/node_modules/ibm_db/test/bench-query-fetchAll.js +49 -49
- package/node_modules/ibm_db/test/bench-query-fetchAllSync.js +43 -43
- package/node_modules/ibm_db/test/bench-query.js +40 -40
- package/node_modules/ibm_db/test/bench-querySync-fetchArray.js +28 -28
- package/node_modules/ibm_db/test/bench-querySync.js +29 -29
- package/node_modules/ibm_db/test/common.d.ts +10 -10
- package/node_modules/ibm_db/test/common.js +127 -127
- package/node_modules/ibm_db/test/config.json +7 -7
- package/node_modules/ibm_db/test/config.zos.json +4 -4
- package/node_modules/ibm_db/test/data/sample1.txt +9 -9
- package/node_modules/ibm_db/test/data/trc.fmt +30114 -30114
- package/node_modules/ibm_db/test/nodeEE-leak-huge-query.js +152 -152
- package/node_modules/ibm_db/test/nodeEE-leak-multiple-query-multiple-connections.js +148 -148
- package/node_modules/ibm_db/test/nodeEE-leak-multiple-query-pool-connections.js +154 -154
- package/node_modules/ibm_db/test/nodeEE-leak-multiple-query.js +133 -133
- package/node_modules/ibm_db/test/nodeEE-stress-async-waterfall-multiple-connections.js +174 -174
- package/node_modules/ibm_db/test/nodeEE-stress-async-waterfall.js +169 -169
- package/node_modules/ibm_db/test/nodeEE-stress-mixed-query-multiple-connections.js +159 -159
- package/node_modules/ibm_db/test/nodeEE-stress-mixed-query.js +148 -148
- package/node_modules/ibm_db/test/odbc-bench.c +123 -123
- package/node_modules/ibm_db/test/perfTest.js +53 -53
- package/node_modules/ibm_db/test/quick-example.sh +30 -30
- package/node_modules/ibm_db/test/quick-example.ts +80 -80
- package/node_modules/ibm_db/test/run-bench.js +96 -96
- package/node_modules/ibm_db/test/run-nodeEE.js +132 -132
- package/node_modules/ibm_db/test/run-tests.js +132 -138
- package/node_modules/ibm_db/test/sql-cli.js +28 -28
- package/node_modules/ibm_db/test/test-all-data-types.js +109 -109
- package/node_modules/ibm_db/test/test-array-insert.js +178 -178
- package/node_modules/ibm_db/test/test-async-await.js +105 -105
- package/node_modules/ibm_db/test/test-attributes.js +34 -34
- package/node_modules/ibm_db/test/test-bad-pool-connection-prepare-execute.js +57 -57
- package/node_modules/ibm_db/test/test-basic-test.js +138 -138
- package/node_modules/ibm_db/test/test-binary-array-insert.js +73 -73
- package/node_modules/ibm_db/test/test-blob-from-file.js +90 -90
- package/node_modules/ibm_db/test/test-blob-insert.js +144 -144
- package/node_modules/ibm_db/test/test-blob-stream-insert.js +321 -299
- package/node_modules/ibm_db/test/test-blob-to-file.js +370 -370
- package/node_modules/ibm_db/test/test-block-fetch.js +364 -364
- package/node_modules/ibm_db/test/test-blocking-issue210.js +123 -123
- package/node_modules/ibm_db/test/test-call-async.js +64 -64
- package/node_modules/ibm_db/test/test-call-stmt.js +53 -53
- package/node_modules/ibm_db/test/test-cancel.js +703 -0
- package/node_modules/ibm_db/test/test-chinese-char.js +59 -59
- package/node_modules/ibm_db/test/test-connection.js +306 -0
- package/node_modules/ibm_db/test/test-date.js +32 -32
- package/node_modules/ibm_db/test/test-dbclob.js +93 -93
- package/node_modules/ibm_db/test/test-decimals.js +135 -135
- package/node_modules/ibm_db/test/test-describe-metadata.js +148 -0
- package/node_modules/ibm_db/test/test-executeFile.js +167 -167
- package/node_modules/ibm_db/test/test-executeFileSync.js +85 -85
- package/node_modules/ibm_db/test/test-fetch-apis.js +146 -146
- package/node_modules/ibm_db/test/test-fetchN.js +130 -130
- package/node_modules/ibm_db/test/test-getinfo.js +197 -197
- package/node_modules/ibm_db/test/test-ibm-db-issue14.js +58 -58
- package/node_modules/ibm_db/test/test-ibm-db-issue17.js +54 -54
- package/node_modules/ibm_db/test/test-ibm-db-issue18.js +54 -54
- package/node_modules/ibm_db/test/test-issue-1059-fetchAll-undefined.js +67 -67
- package/node_modules/ibm_db/test/test-issue-1080-array-blob-insert.js +40 -0
- package/node_modules/ibm_db/test/test-issue-54.js +39 -39
- package/node_modules/ibm_db/test/test-issue-get-column-value-2.js +44 -44
- package/node_modules/ibm_db/test/test-issue211.js +80 -80
- package/node_modules/ibm_db/test/test-issue253.js +39 -39
- package/node_modules/ibm_db/test/test-max-pool-size.js +96 -96
- package/node_modules/ibm_db/test/test-memory-leaks-new-objects.js +32 -32
- package/node_modules/ibm_db/test/test-multi-open-query-close.js +75 -75
- package/node_modules/ibm_db/test/test-param-put-data.js +713 -0
- package/node_modules/ibm_db/test/test-pool-idle-connection.js +72 -72
- package/node_modules/ibm_db/test/test-pool-operations.js +325 -0
- package/node_modules/ibm_db/test/test-pool-stale-connections.js +111 -111
- package/node_modules/ibm_db/test/test-pool-uncommited.js +33 -33
- package/node_modules/ibm_db/test/test-prepare-execute.js +339 -0
- package/node_modules/ibm_db/test/test-prepareSync-multiple-execution.js +93 -93
- package/node_modules/ibm_db/test/test-primary-foreign-keys.js +246 -0
- package/node_modules/ibm_db/test/test-procedures.js +243 -0
- package/node_modules/ibm_db/test/test-promise-all-data-types.js +42 -42
- package/node_modules/ibm_db/test/test-query-operations.js +405 -0
- package/node_modules/ibm_db/test/test-quick-example.js +25 -25
- package/node_modules/ibm_db/test/test-row-array-insert.js +167 -167
- package/node_modules/ibm_db/test/test-sp-array.js +54 -54
- package/node_modules/ibm_db/test/test-sp-dbc-6000.js +88 -88
- package/node_modules/ibm_db/test/test-sp-memleak.js +136 -136
- package/node_modules/ibm_db/test/test-sp-resultset-execute.js +269 -269
- package/node_modules/ibm_db/test/test-sp-resultset.js +228 -228
- package/node_modules/ibm_db/test/test-transactions.js +261 -0
- package/node_modules/ibm_db/test/test-typescript.js +48 -48
- package/node_modules/ibm_db/test/test-xml-datatype.js +70 -70
- package/node_modules/ibm_db/test/testWebApp.js +56 -56
- package/node_modules/ibm_db/test/trace +51 -51
- package/node_modules/ibm_db/test/typescript-apis-test.js +978 -978
- package/node_modules/ibm_db/test/webapp.html +17 -17
- package/node_modules/ibm_db/test/webapp.js +79 -79
- package/node_modules/ibm_db/typescript/README.md +28 -28
- package/node_modules/ibm_db/typescript/dist/Database.d.ts +26 -0
- package/node_modules/ibm_db/typescript/dist/ODBCStatement.d.ts +93 -0
- package/package.json +10 -6
- package/node_modules/ibm_db/test/disabled/test-binding-statement-rebinding.js +0 -59
- package/node_modules/ibm_db/test/disabled/test-open-dont-close.js +0 -12
- package/node_modules/ibm_db/test/disabled/test-param-select-with-booleans-only.js +0 -21
- package/node_modules/ibm_db/test/disabled/test-param-select-with-decimals-only.js +0 -20
- package/node_modules/ibm_db/test/disabled/test-param-select-with-null.js +0 -21
- package/node_modules/ibm_db/test/disabled/test-param-select-with-nulls-mixed.js +0 -23
- package/node_modules/ibm_db/test/disabled/test-param-select-with-numbers-mixed.js +0 -22
- package/node_modules/ibm_db/test/disabled/test-param-select-with-numbers-only.js +0 -24
- package/node_modules/ibm_db/test/disabled/test-param-select-with-strings-only.js +0 -23
- package/node_modules/ibm_db/test/disabled/test-param-select-with-unicode.js +0 -15
- package/node_modules/ibm_db/test/disabled/test-prepare-bind-execute-closeSync.js +0 -62
- package/node_modules/ibm_db/test/disabled/test-prepare-bind-execute-error.js +0 -49
- package/node_modules/ibm_db/test/disabled/test-prepare-bind-execute-long-string.js +0 -63
- package/node_modules/ibm_db/test/disabled/test-prepare-bind-executeNonQuery.js +0 -63
- package/node_modules/ibm_db/test/disabled/test-prepare-bindSync-execute-closeSync.js +0 -46
- package/node_modules/ibm_db/test/disabled/test-prepare-bindSync-executeNonQuery.js +0 -50
- package/node_modules/ibm_db/test/disabled/test-prepare.js +0 -34
- package/node_modules/ibm_db/test/disabled/test-prepareSync.js +0 -29
- package/node_modules/ibm_db/test/disabled/test-query-select-fetchAll.js +0 -23
- package/node_modules/ibm_db/test/disabled/test-query-select-fetchAllSync.js +0 -23
- package/node_modules/ibm_db/test/disabled/test-query-select-unicode.js +0 -15
- package/node_modules/ibm_db/test/disabled/test-querySync-select-unicode.js +0 -20
- package/node_modules/ibm_db/test/test-affected-rows.js +0 -55
- package/node_modules/ibm_db/test/test-bad-connection-string.js +0 -30
- package/node_modules/ibm_db/test/test-binding-connection-timeOut.js +0 -31
- package/node_modules/ibm_db/test/test-binding-statement-executeSync.js +0 -84
- package/node_modules/ibm_db/test/test-binding-transaction-commit.js +0 -79
- package/node_modules/ibm_db/test/test-binding-transaction-commitSync.js +0 -53
- package/node_modules/ibm_db/test/test-closed.js +0 -14
- package/node_modules/ibm_db/test/test-connection-object.js +0 -16
- package/node_modules/ibm_db/test/test-describe-column.js +0 -92
- package/node_modules/ibm_db/test/test-describe-database.js +0 -18
- package/node_modules/ibm_db/test/test-describe-table.js +0 -31
- package/node_modules/ibm_db/test/test-domains-open.js +0 -19
- package/node_modules/ibm_db/test/test-global-open-close.js +0 -11
- package/node_modules/ibm_db/test/test-instantiate-one-and-end.js +0 -9
- package/node_modules/ibm_db/test/test-multi-open-close.js +0 -45
- package/node_modules/ibm_db/test/test-multi-openSync-closeSync.js +0 -52
- package/node_modules/ibm_db/test/test-open-close.js +0 -29
- package/node_modules/ibm_db/test/test-open-connectTimeout.js +0 -33
- package/node_modules/ibm_db/test/test-openSync.js +0 -31
- package/node_modules/ibm_db/test/test-pool-close.js +0 -120
- package/node_modules/ibm_db/test/test-pool-connect.js +0 -36
- package/node_modules/ibm_db/test/test-pool-rollbackTransaction.js +0 -35
- package/node_modules/ibm_db/test/test-prepareSync-bad-sql.js +0 -34
- package/node_modules/ibm_db/test/test-promise-open-close.js +0 -33
- package/node_modules/ibm_db/test/test-query-create-table-fetchSync.js +0 -23
- package/node_modules/ibm_db/test/test-query-create-table.js +0 -12
- package/node_modules/ibm_db/test/test-query-drop-table.js +0 -13
- package/node_modules/ibm_db/test/test-query-insert.js +0 -38
- package/node_modules/ibm_db/test/test-query-select-fetch.js +0 -21
- package/node_modules/ibm_db/test/test-query-select-fetchMode-array.js +0 -17
- package/node_modules/ibm_db/test/test-query-select.js +0 -64
- package/node_modules/ibm_db/test/test-queryResult.js +0 -35
- package/node_modules/ibm_db/test/test-queryStream.js +0 -43
- package/node_modules/ibm_db/test/test-querySync-select-with-exception.js +0 -25
- package/node_modules/ibm_db/test/test-querySync-select.js +0 -28
- package/node_modules/ibm_db/test/test-require-and-end.js +0 -8
- package/node_modules/ibm_db/test/test-statement-close.js +0 -118
- package/node_modules/ibm_db/test/test-transaction-commit-sync.js +0 -54
- package/node_modules/ibm_db/test/test-transaction-commit.js +0 -79
|
@@ -1,370 +1,370 @@
|
|
|
1
|
-
// Test for issue #962: SELECT BLOB/CLOB directly to file using SQLBindFileToCol.
|
|
2
|
-
// Tests result.bindFileToColSync() and result.bindFileToCol() APIs which bind
|
|
3
|
-
// LOB columns to output files so the CLI driver writes data directly to disk
|
|
4
|
-
// during fetch, without loading the entire LOB into JS memory.
|
|
5
|
-
//
|
|
6
|
-
// Also demonstrates queryStream() for row-level streaming.
|
|
7
|
-
|
|
8
|
-
var common = require("./common")
|
|
9
|
-
, ibmdb = require("../")
|
|
10
|
-
, assert = require("assert")
|
|
11
|
-
, fs = require("fs")
|
|
12
|
-
, path = require("path")
|
|
13
|
-
, cn = common.connectionString
|
|
14
|
-
;
|
|
15
|
-
|
|
16
|
-
var tableName = "TEST_BLOB_TO_FILE";
|
|
17
|
-
var dataDir = path.join(__dirname, "data");
|
|
18
|
-
|
|
19
|
-
// Ensure data directory exists
|
|
20
|
-
if (!fs.existsSync(dataDir)) {
|
|
21
|
-
fs.mkdirSync(dataDir, { recursive: true });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Source files for INSERT
|
|
25
|
-
var srcImage = path.join(dataDir, "phool.jpg");
|
|
26
|
-
var srcText = path.join(dataDir, "trc.fmt");
|
|
27
|
-
var srcDoc = path.join(dataDir, "sampledoc.docx");
|
|
28
|
-
|
|
29
|
-
var srcImageSize = fs.statSync(srcImage).size;
|
|
30
|
-
var srcTextSize = fs.statSync(srcText).size;
|
|
31
|
-
var srcDocSize = fs.statSync(srcDoc).size;
|
|
32
|
-
|
|
33
|
-
console.log("Source file sizes: image=" + srcImageSize +
|
|
34
|
-
", text=" + srcTextSize + ", doc=" + srcDocSize);
|
|
35
|
-
|
|
36
|
-
ibmdb.open(cn, function(err, conn) {
|
|
37
|
-
if (err) { console.log(err); process.exit(-1); }
|
|
38
|
-
console.log("Connection opened.");
|
|
39
|
-
|
|
40
|
-
// Setup table
|
|
41
|
-
try { conn.querySync("DROP TABLE " + tableName); } catch(e) {}
|
|
42
|
-
conn.querySync("CREATE TABLE " + tableName +
|
|
43
|
-
" (ID INTEGER, PHOTO BLOB(1M), TRACE CLOB(1M), DOCUMENT BLOB(1M))");
|
|
44
|
-
|
|
45
|
-
// Insert data using ParamType:"FILE" (existing feature)
|
|
46
|
-
var stmt = conn.prepareSync("INSERT INTO " + tableName +
|
|
47
|
-
" (ID, PHOTO, TRACE, DOCUMENT) VALUES (?, ?, ?, ?)");
|
|
48
|
-
stmt.executeSync([
|
|
49
|
-
1,
|
|
50
|
-
{ ParamType: "FILE", DataType: "BLOB", Data: srcImage },
|
|
51
|
-
{ ParamType: "FILE", DataType: "CLOB", Data: srcText },
|
|
52
|
-
{ ParamType: "FILE", DataType: "BLOB", Data: srcDoc }
|
|
53
|
-
]);
|
|
54
|
-
stmt.closeSync();
|
|
55
|
-
console.log("Inserted row with BLOB/CLOB data from files.");
|
|
56
|
-
|
|
57
|
-
// Also insert a row with NULL LOBs
|
|
58
|
-
conn.querySync("INSERT INTO " + tableName +
|
|
59
|
-
" (ID, PHOTO, TRACE, DOCUMENT) VALUES (2, NULL, NULL, NULL)");
|
|
60
|
-
console.log("Inserted row with NULL LOBs.");
|
|
61
|
-
|
|
62
|
-
testBindFileToCol();
|
|
63
|
-
|
|
64
|
-
// ======================================================================
|
|
65
|
-
// Test 1: fetchAllSync with bindFileToColSync
|
|
66
|
-
// ======================================================================
|
|
67
|
-
function testBindFileToCol() {
|
|
68
|
-
console.log("\n--- Test 1: fetchAllSync with bindFileToColSync ---");
|
|
69
|
-
|
|
70
|
-
var outImage = path.join(dataDir, "test1_photo.jpg");
|
|
71
|
-
var outText = path.join(dataDir, "test1_trace.fmt");
|
|
72
|
-
var outDoc = path.join(dataDir, "test1_doc.docx");
|
|
73
|
-
|
|
74
|
-
// Clean up any previous output files
|
|
75
|
-
[outImage, outText, outDoc].forEach(function(f) {
|
|
76
|
-
try { fs.unlinkSync(f); } catch(e) {}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
80
|
-
" WHERE ID = 1 ORDER BY ID");
|
|
81
|
-
var result = s.executeSync();
|
|
82
|
-
|
|
83
|
-
// Bind LOB columns to output files BEFORE fetching
|
|
84
|
-
// Column numbers: 1=ID, 2=PHOTO, 3=TRACE, 4=DOCUMENT
|
|
85
|
-
result.bindFileToColSync(2, outImage, ibmdb.SQL_FILE_OVERWRITE);
|
|
86
|
-
result.bindFileToColSync(3, outText, ibmdb.SQL_FILE_OVERWRITE);
|
|
87
|
-
result.bindFileToColSync(4, outDoc); // Passing ibmdb.SQL_FILE_OVERWRITE is optional, it's the default value.
|
|
88
|
-
|
|
89
|
-
var data = result.fetchAllSync();
|
|
90
|
-
result.closeSync();
|
|
91
|
-
s.closeSync();
|
|
92
|
-
|
|
93
|
-
console.log(" Row data:", JSON.stringify(data[0]));
|
|
94
|
-
assert.equal(data.length, 1, "Should return 1 row");
|
|
95
|
-
assert.equal(data[0].ID, 1, "ID should be 1");
|
|
96
|
-
|
|
97
|
-
// The PHOTO/TRACE/DOCUMENT columns should contain the file paths
|
|
98
|
-
assert.equal(data[0].PHOTO, outImage,
|
|
99
|
-
"PHOTO column should contain the output file path");
|
|
100
|
-
assert.equal(data[0].TRACE, outText,
|
|
101
|
-
"TRACE column should contain the output file path");
|
|
102
|
-
assert.equal(data[0].DOCUMENT, outDoc,
|
|
103
|
-
"DOCUMENT column should contain the output file path");
|
|
104
|
-
|
|
105
|
-
// Verify output file sizes match source files
|
|
106
|
-
var outImageSize = fs.statSync(outImage).size;
|
|
107
|
-
var outTextSize = fs.statSync(outText).size;
|
|
108
|
-
var outDocSize = fs.statSync(outDoc).size;
|
|
109
|
-
|
|
110
|
-
console.log(" Output sizes: image=" + outImageSize +
|
|
111
|
-
", text=" + outTextSize + ", doc=" + outDocSize);
|
|
112
|
-
|
|
113
|
-
assert.equal(outImageSize, srcImageSize,
|
|
114
|
-
"Output image size should match source");
|
|
115
|
-
assert.equal(outTextSize, srcTextSize,
|
|
116
|
-
"Output text size should match source");
|
|
117
|
-
assert.equal(outDocSize, srcDocSize,
|
|
118
|
-
"Output doc size should match source");
|
|
119
|
-
|
|
120
|
-
// Verify binary content of image matches
|
|
121
|
-
var srcBuf = fs.readFileSync(srcImage);
|
|
122
|
-
var outBuf = fs.readFileSync(outImage);
|
|
123
|
-
assert.ok(srcBuf.equals(outBuf),
|
|
124
|
-
"Output image content should match source exactly");
|
|
125
|
-
|
|
126
|
-
console.log(" PASS: All LOB data written directly to files.");
|
|
127
|
-
|
|
128
|
-
// Clean up
|
|
129
|
-
[outImage, outText, outDoc].forEach(function(f) {
|
|
130
|
-
try { fs.unlinkSync(f); } catch(e) {}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
testBindFileToColNull();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// ======================================================================
|
|
137
|
-
// Test 2: bindFileToColSync with NULL LOB columns
|
|
138
|
-
// ======================================================================
|
|
139
|
-
function testBindFileToColNull() {
|
|
140
|
-
console.log("\n--- Test 2: bindFileToColSync with NULL LOBs ---");
|
|
141
|
-
|
|
142
|
-
var outImage = path.join(dataDir, "test2_photo.jpg");
|
|
143
|
-
|
|
144
|
-
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
145
|
-
" WHERE ID = 2 ORDER BY ID");
|
|
146
|
-
var result = s.executeSync();
|
|
147
|
-
|
|
148
|
-
result.bindFileToColSync(2, outImage, ibmdb.SQL_FILE_OVERWRITE);
|
|
149
|
-
|
|
150
|
-
var data = result.fetchAllSync();
|
|
151
|
-
result.closeSync();
|
|
152
|
-
s.closeSync();
|
|
153
|
-
|
|
154
|
-
console.log(" Row data:", JSON.stringify(data[0]));
|
|
155
|
-
assert.equal(data.length, 1, "Should return 1 row");
|
|
156
|
-
assert.equal(data[0].ID, 2, "ID should be 2");
|
|
157
|
-
assert.equal(data[0].PHOTO, null, "NULL PHOTO should return null");
|
|
158
|
-
|
|
159
|
-
// Output file should not exist (or be empty) for NULL data
|
|
160
|
-
console.log(" PASS: NULL LOB column returns null, no file written.");
|
|
161
|
-
|
|
162
|
-
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
163
|
-
|
|
164
|
-
testBindFileAppend();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// ======================================================================
|
|
168
|
-
// Test 3: SQL_FILE_APPEND - append to existing file
|
|
169
|
-
// ======================================================================
|
|
170
|
-
function testBindFileAppend() {
|
|
171
|
-
console.log("\n--- Test 3: SQL_FILE_APPEND mode ---");
|
|
172
|
-
|
|
173
|
-
var outFile = path.join(dataDir, "test3_appended.txt");
|
|
174
|
-
try { fs.unlinkSync(outFile); } catch(e) {}
|
|
175
|
-
|
|
176
|
-
// Write some initial content
|
|
177
|
-
fs.writeFileSync(outFile, "HEADER:");
|
|
178
|
-
var headerSize = fs.statSync(outFile).size;
|
|
179
|
-
|
|
180
|
-
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
181
|
-
" WHERE ID = 1 ORDER BY ID");
|
|
182
|
-
var result = s.executeSync();
|
|
183
|
-
|
|
184
|
-
// Bind TRACE column (CLOB) in APPEND mode
|
|
185
|
-
result.bindFileToColSync(3, outFile, ibmdb.SQL_FILE_APPEND);
|
|
186
|
-
|
|
187
|
-
var data = result.fetchAllSync();
|
|
188
|
-
result.closeSync();
|
|
189
|
-
s.closeSync();
|
|
190
|
-
|
|
191
|
-
var finalSize = fs.statSync(outFile).size;
|
|
192
|
-
console.log(" Header size: " + headerSize +
|
|
193
|
-
", Final size: " + finalSize +
|
|
194
|
-
", Expected: " + (headerSize + srcTextSize));
|
|
195
|
-
assert.equal(finalSize, headerSize + srcTextSize,
|
|
196
|
-
"Appended file size should be header + CLOB data");
|
|
197
|
-
|
|
198
|
-
console.log(" PASS: SQL_FILE_APPEND correctly appends LOB data.");
|
|
199
|
-
|
|
200
|
-
try { fs.unlinkSync(outFile); } catch(e) {}
|
|
201
|
-
|
|
202
|
-
testFetchSyncWithFile();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// ======================================================================
|
|
206
|
-
// Test 4: fetchSync (single row) with bindFileToColSync
|
|
207
|
-
// ======================================================================
|
|
208
|
-
function testFetchSyncWithFile() {
|
|
209
|
-
console.log("\n--- Test 4: fetchSync with bindFileToColSync ---");
|
|
210
|
-
|
|
211
|
-
var outImage = path.join(dataDir, "test4_photo.jpg");
|
|
212
|
-
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
213
|
-
|
|
214
|
-
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
215
|
-
" WHERE ID = 1 ORDER BY ID");
|
|
216
|
-
var result = s.executeSync();
|
|
217
|
-
|
|
218
|
-
result.bindFileToColSync(2, outImage, ibmdb.SQL_FILE_OVERWRITE);
|
|
219
|
-
|
|
220
|
-
var row = result.fetchSync();
|
|
221
|
-
assert.notEqual(row, null, "fetchSync should return a row");
|
|
222
|
-
console.log(" Row ID:", row.ID, "PHOTO:", row.PHOTO);
|
|
223
|
-
assert.equal(row.PHOTO, outImage,
|
|
224
|
-
"PHOTO should contain file path");
|
|
225
|
-
|
|
226
|
-
// Verify file was written
|
|
227
|
-
var outSize = fs.statSync(outImage).size;
|
|
228
|
-
assert.equal(outSize, srcImageSize, "Image sizes should match");
|
|
229
|
-
|
|
230
|
-
// No more rows
|
|
231
|
-
var row2 = result.fetchSync();
|
|
232
|
-
assert.equal(row2, null, "No more rows expected");
|
|
233
|
-
|
|
234
|
-
result.closeSync();
|
|
235
|
-
s.closeSync();
|
|
236
|
-
console.log(" PASS: fetchSync + bindFileToColSync works.");
|
|
237
|
-
|
|
238
|
-
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
239
|
-
|
|
240
|
-
testAsyncBindFileToCol();
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// ======================================================================
|
|
244
|
-
// Test 5: async bindFileToCol() with callback
|
|
245
|
-
// ======================================================================
|
|
246
|
-
function testAsyncBindFileToCol() {
|
|
247
|
-
console.log("\n--- Test 5: async bindFileToCol() with callback ---");
|
|
248
|
-
|
|
249
|
-
var outImage = path.join(dataDir, "test5_photo.jpg");
|
|
250
|
-
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
251
|
-
|
|
252
|
-
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
253
|
-
" WHERE ID = 1 ORDER BY ID");
|
|
254
|
-
var result = s.executeSync();
|
|
255
|
-
|
|
256
|
-
result.bindFileToCol(2, outImage, ibmdb.SQL_FILE_OVERWRITE, function(err) {
|
|
257
|
-
if (err) { console.log("ERROR:", err); assert.fail(); }
|
|
258
|
-
|
|
259
|
-
result.fetch(function(err, row) {
|
|
260
|
-
if (err) { console.log("ERROR:", err); assert.fail(); }
|
|
261
|
-
assert.notEqual(row, null, "Should get a row");
|
|
262
|
-
console.log(" Row ID:", row.ID, "PHOTO:", row.PHOTO);
|
|
263
|
-
assert.equal(row.PHOTO, outImage);
|
|
264
|
-
|
|
265
|
-
var outSize = fs.statSync(outImage).size;
|
|
266
|
-
assert.equal(outSize, srcImageSize);
|
|
267
|
-
|
|
268
|
-
result.fetch(function(err, row2) {
|
|
269
|
-
assert.equal(row2, null, "No more rows");
|
|
270
|
-
result.closeSync();
|
|
271
|
-
s.closeSync();
|
|
272
|
-
console.log(" PASS: async bindFileToCol() + fetch() works.");
|
|
273
|
-
|
|
274
|
-
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
275
|
-
|
|
276
|
-
testQueryStream();
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// ======================================================================
|
|
283
|
-
// Test 6: queryStream for row-level streaming
|
|
284
|
-
// ======================================================================
|
|
285
|
-
function testQueryStream() {
|
|
286
|
-
console.log("\n--- Test 6: queryStream for row-level streaming ---");
|
|
287
|
-
console.log(" queryStream() streams rows (not LOB columns).");
|
|
288
|
-
console.log(" Each row still has full LOB data in memory.");
|
|
289
|
-
console.log(" For large LOBs, use bindFileToColSync instead.");
|
|
290
|
-
|
|
291
|
-
var rows = [];
|
|
292
|
-
var stream = conn.queryStream("SELECT ID, TRACE FROM " + tableName +
|
|
293
|
-
" ORDER BY ID");
|
|
294
|
-
|
|
295
|
-
stream.on("data", function(row) {
|
|
296
|
-
rows.push(row);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
stream.on("error", function(err) {
|
|
300
|
-
console.log(" Stream error:", err);
|
|
301
|
-
assert.fail("Stream should not error");
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
stream.on("end", function() {
|
|
305
|
-
console.log(" Streamed " + rows.length + " rows");
|
|
306
|
-
assert.equal(rows.length, 2, "Should stream 2 rows");
|
|
307
|
-
assert.equal(rows[0].ID, 1);
|
|
308
|
-
assert.equal(rows[1].ID, 2);
|
|
309
|
-
|
|
310
|
-
// Row 1 has CLOB data, Row 2 has NULL
|
|
311
|
-
assert.notEqual(rows[0].TRACE, null, "Row 1 TRACE should have data");
|
|
312
|
-
assert.equal(rows[1].TRACE, null, "Row 2 TRACE should be null");
|
|
313
|
-
|
|
314
|
-
console.log(" PASS: queryStream streams rows successfully.");
|
|
315
|
-
console.log(" NOTE: queryStream loads LOB data into memory per row.");
|
|
316
|
-
console.log(" For zero-copy LOB handling, use bindFileToColSync.");
|
|
317
|
-
|
|
318
|
-
testAsyncAwaitFetchToFile();
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// ======================================================================
|
|
323
|
-
// Test 7: async/await with bindFileToCol (Promise)
|
|
324
|
-
// ======================================================================
|
|
325
|
-
function testAsyncAwaitFetchToFile() {
|
|
326
|
-
console.log("\n--- Test 7: async/await with bindFileToCol ---");
|
|
327
|
-
|
|
328
|
-
asyncTests().then(function() {
|
|
329
|
-
cleanup();
|
|
330
|
-
}).catch(function(err) {
|
|
331
|
-
console.log(" Error:", err);
|
|
332
|
-
assert.fail("async/await test failed");
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
async function asyncTests() {
|
|
337
|
-
var outImage = path.join(dataDir, "test7_photo.jpg");
|
|
338
|
-
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
339
|
-
|
|
340
|
-
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
341
|
-
" WHERE ID = 1 ORDER BY ID");
|
|
342
|
-
var result = s.executeSync();
|
|
343
|
-
|
|
344
|
-
// await the async bindFileToCol (Promise version)
|
|
345
|
-
await result.bindFileToCol(2, outImage, ibmdb.SQL_FILE_OVERWRITE);
|
|
346
|
-
|
|
347
|
-
var data = await result.fetchAll();
|
|
348
|
-
result.closeSync();
|
|
349
|
-
s.closeSync();
|
|
350
|
-
|
|
351
|
-
assert.equal(data.length, 1);
|
|
352
|
-
assert.equal(data[0].PHOTO, outImage);
|
|
353
|
-
|
|
354
|
-
var outSize = fs.statSync(outImage).size;
|
|
355
|
-
assert.equal(outSize, srcImageSize);
|
|
356
|
-
|
|
357
|
-
console.log(" PASS: async/await bindFileToCol + fetchAll works.");
|
|
358
|
-
|
|
359
|
-
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// ======================================================================
|
|
363
|
-
// Cleanup
|
|
364
|
-
// ======================================================================
|
|
365
|
-
function cleanup() {
|
|
366
|
-
conn.querySync("DROP TABLE " + tableName);
|
|
367
|
-
conn.closeSync();
|
|
368
|
-
console.log("\nAll tests passed! Connection closed.");
|
|
369
|
-
}
|
|
370
|
-
});
|
|
1
|
+
// Test for issue #962: SELECT BLOB/CLOB directly to file using SQLBindFileToCol.
|
|
2
|
+
// Tests result.bindFileToColSync() and result.bindFileToCol() APIs which bind
|
|
3
|
+
// LOB columns to output files so the CLI driver writes data directly to disk
|
|
4
|
+
// during fetch, without loading the entire LOB into JS memory.
|
|
5
|
+
//
|
|
6
|
+
// Also demonstrates queryStream() for row-level streaming.
|
|
7
|
+
|
|
8
|
+
var common = require("./common")
|
|
9
|
+
, ibmdb = require("../")
|
|
10
|
+
, assert = require("assert")
|
|
11
|
+
, fs = require("fs")
|
|
12
|
+
, path = require("path")
|
|
13
|
+
, cn = common.connectionString
|
|
14
|
+
;
|
|
15
|
+
|
|
16
|
+
var tableName = "TEST_BLOB_TO_FILE";
|
|
17
|
+
var dataDir = path.join(__dirname, "data");
|
|
18
|
+
|
|
19
|
+
// Ensure data directory exists
|
|
20
|
+
if (!fs.existsSync(dataDir)) {
|
|
21
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Source files for INSERT
|
|
25
|
+
var srcImage = path.join(dataDir, "phool.jpg");
|
|
26
|
+
var srcText = path.join(dataDir, "trc.fmt");
|
|
27
|
+
var srcDoc = path.join(dataDir, "sampledoc.docx");
|
|
28
|
+
|
|
29
|
+
var srcImageSize = fs.statSync(srcImage).size;
|
|
30
|
+
var srcTextSize = fs.statSync(srcText).size;
|
|
31
|
+
var srcDocSize = fs.statSync(srcDoc).size;
|
|
32
|
+
|
|
33
|
+
console.log("Source file sizes: image=" + srcImageSize +
|
|
34
|
+
", text=" + srcTextSize + ", doc=" + srcDocSize);
|
|
35
|
+
|
|
36
|
+
ibmdb.open(cn, function(err, conn) {
|
|
37
|
+
if (err) { console.log(err); process.exit(-1); }
|
|
38
|
+
console.log("Connection opened.");
|
|
39
|
+
|
|
40
|
+
// Setup table
|
|
41
|
+
try { conn.querySync("DROP TABLE " + tableName); } catch(e) {}
|
|
42
|
+
conn.querySync("CREATE TABLE " + tableName +
|
|
43
|
+
" (ID INTEGER, PHOTO BLOB(1M), TRACE CLOB(1M), DOCUMENT BLOB(1M))");
|
|
44
|
+
|
|
45
|
+
// Insert data using ParamType:"FILE" (existing feature)
|
|
46
|
+
var stmt = conn.prepareSync("INSERT INTO " + tableName +
|
|
47
|
+
" (ID, PHOTO, TRACE, DOCUMENT) VALUES (?, ?, ?, ?)");
|
|
48
|
+
stmt.executeSync([
|
|
49
|
+
1,
|
|
50
|
+
{ ParamType: "FILE", DataType: "BLOB", Data: srcImage },
|
|
51
|
+
{ ParamType: "FILE", DataType: "CLOB", Data: srcText },
|
|
52
|
+
{ ParamType: "FILE", DataType: "BLOB", Data: srcDoc }
|
|
53
|
+
]);
|
|
54
|
+
stmt.closeSync();
|
|
55
|
+
console.log("Inserted row with BLOB/CLOB data from files.");
|
|
56
|
+
|
|
57
|
+
// Also insert a row with NULL LOBs
|
|
58
|
+
conn.querySync("INSERT INTO " + tableName +
|
|
59
|
+
" (ID, PHOTO, TRACE, DOCUMENT) VALUES (2, NULL, NULL, NULL)");
|
|
60
|
+
console.log("Inserted row with NULL LOBs.");
|
|
61
|
+
|
|
62
|
+
testBindFileToCol();
|
|
63
|
+
|
|
64
|
+
// ======================================================================
|
|
65
|
+
// Test 1: fetchAllSync with bindFileToColSync
|
|
66
|
+
// ======================================================================
|
|
67
|
+
function testBindFileToCol() {
|
|
68
|
+
console.log("\n--- Test 1: fetchAllSync with bindFileToColSync ---");
|
|
69
|
+
|
|
70
|
+
var outImage = path.join(dataDir, "test1_photo.jpg");
|
|
71
|
+
var outText = path.join(dataDir, "test1_trace.fmt");
|
|
72
|
+
var outDoc = path.join(dataDir, "test1_doc.docx");
|
|
73
|
+
|
|
74
|
+
// Clean up any previous output files
|
|
75
|
+
[outImage, outText, outDoc].forEach(function(f) {
|
|
76
|
+
try { fs.unlinkSync(f); } catch(e) {}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
80
|
+
" WHERE ID = 1 ORDER BY ID");
|
|
81
|
+
var result = s.executeSync();
|
|
82
|
+
|
|
83
|
+
// Bind LOB columns to output files BEFORE fetching
|
|
84
|
+
// Column numbers: 1=ID, 2=PHOTO, 3=TRACE, 4=DOCUMENT
|
|
85
|
+
result.bindFileToColSync(2, outImage, ibmdb.SQL_FILE_OVERWRITE);
|
|
86
|
+
result.bindFileToColSync(3, outText, ibmdb.SQL_FILE_OVERWRITE);
|
|
87
|
+
result.bindFileToColSync(4, outDoc); // Passing ibmdb.SQL_FILE_OVERWRITE is optional, it's the default value.
|
|
88
|
+
|
|
89
|
+
var data = result.fetchAllSync();
|
|
90
|
+
result.closeSync();
|
|
91
|
+
s.closeSync();
|
|
92
|
+
|
|
93
|
+
console.log(" Row data:", JSON.stringify(data[0]));
|
|
94
|
+
assert.equal(data.length, 1, "Should return 1 row");
|
|
95
|
+
assert.equal(data[0].ID, 1, "ID should be 1");
|
|
96
|
+
|
|
97
|
+
// The PHOTO/TRACE/DOCUMENT columns should contain the file paths
|
|
98
|
+
assert.equal(data[0].PHOTO, outImage,
|
|
99
|
+
"PHOTO column should contain the output file path");
|
|
100
|
+
assert.equal(data[0].TRACE, outText,
|
|
101
|
+
"TRACE column should contain the output file path");
|
|
102
|
+
assert.equal(data[0].DOCUMENT, outDoc,
|
|
103
|
+
"DOCUMENT column should contain the output file path");
|
|
104
|
+
|
|
105
|
+
// Verify output file sizes match source files
|
|
106
|
+
var outImageSize = fs.statSync(outImage).size;
|
|
107
|
+
var outTextSize = fs.statSync(outText).size;
|
|
108
|
+
var outDocSize = fs.statSync(outDoc).size;
|
|
109
|
+
|
|
110
|
+
console.log(" Output sizes: image=" + outImageSize +
|
|
111
|
+
", text=" + outTextSize + ", doc=" + outDocSize);
|
|
112
|
+
|
|
113
|
+
assert.equal(outImageSize, srcImageSize,
|
|
114
|
+
"Output image size should match source");
|
|
115
|
+
assert.equal(outTextSize, srcTextSize,
|
|
116
|
+
"Output text size should match source");
|
|
117
|
+
assert.equal(outDocSize, srcDocSize,
|
|
118
|
+
"Output doc size should match source");
|
|
119
|
+
|
|
120
|
+
// Verify binary content of image matches
|
|
121
|
+
var srcBuf = fs.readFileSync(srcImage);
|
|
122
|
+
var outBuf = fs.readFileSync(outImage);
|
|
123
|
+
assert.ok(srcBuf.equals(outBuf),
|
|
124
|
+
"Output image content should match source exactly");
|
|
125
|
+
|
|
126
|
+
console.log(" PASS: All LOB data written directly to files.");
|
|
127
|
+
|
|
128
|
+
// Clean up
|
|
129
|
+
[outImage, outText, outDoc].forEach(function(f) {
|
|
130
|
+
try { fs.unlinkSync(f); } catch(e) {}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
testBindFileToColNull();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ======================================================================
|
|
137
|
+
// Test 2: bindFileToColSync with NULL LOB columns
|
|
138
|
+
// ======================================================================
|
|
139
|
+
function testBindFileToColNull() {
|
|
140
|
+
console.log("\n--- Test 2: bindFileToColSync with NULL LOBs ---");
|
|
141
|
+
|
|
142
|
+
var outImage = path.join(dataDir, "test2_photo.jpg");
|
|
143
|
+
|
|
144
|
+
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
145
|
+
" WHERE ID = 2 ORDER BY ID");
|
|
146
|
+
var result = s.executeSync();
|
|
147
|
+
|
|
148
|
+
result.bindFileToColSync(2, outImage, ibmdb.SQL_FILE_OVERWRITE);
|
|
149
|
+
|
|
150
|
+
var data = result.fetchAllSync();
|
|
151
|
+
result.closeSync();
|
|
152
|
+
s.closeSync();
|
|
153
|
+
|
|
154
|
+
console.log(" Row data:", JSON.stringify(data[0]));
|
|
155
|
+
assert.equal(data.length, 1, "Should return 1 row");
|
|
156
|
+
assert.equal(data[0].ID, 2, "ID should be 2");
|
|
157
|
+
assert.equal(data[0].PHOTO, null, "NULL PHOTO should return null");
|
|
158
|
+
|
|
159
|
+
// Output file should not exist (or be empty) for NULL data
|
|
160
|
+
console.log(" PASS: NULL LOB column returns null, no file written.");
|
|
161
|
+
|
|
162
|
+
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
163
|
+
|
|
164
|
+
testBindFileAppend();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ======================================================================
|
|
168
|
+
// Test 3: SQL_FILE_APPEND - append to existing file
|
|
169
|
+
// ======================================================================
|
|
170
|
+
function testBindFileAppend() {
|
|
171
|
+
console.log("\n--- Test 3: SQL_FILE_APPEND mode ---");
|
|
172
|
+
|
|
173
|
+
var outFile = path.join(dataDir, "test3_appended.txt");
|
|
174
|
+
try { fs.unlinkSync(outFile); } catch(e) {}
|
|
175
|
+
|
|
176
|
+
// Write some initial content
|
|
177
|
+
fs.writeFileSync(outFile, "HEADER:");
|
|
178
|
+
var headerSize = fs.statSync(outFile).size;
|
|
179
|
+
|
|
180
|
+
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
181
|
+
" WHERE ID = 1 ORDER BY ID");
|
|
182
|
+
var result = s.executeSync();
|
|
183
|
+
|
|
184
|
+
// Bind TRACE column (CLOB) in APPEND mode
|
|
185
|
+
result.bindFileToColSync(3, outFile, ibmdb.SQL_FILE_APPEND);
|
|
186
|
+
|
|
187
|
+
var data = result.fetchAllSync();
|
|
188
|
+
result.closeSync();
|
|
189
|
+
s.closeSync();
|
|
190
|
+
|
|
191
|
+
var finalSize = fs.statSync(outFile).size;
|
|
192
|
+
console.log(" Header size: " + headerSize +
|
|
193
|
+
", Final size: " + finalSize +
|
|
194
|
+
", Expected: " + (headerSize + srcTextSize));
|
|
195
|
+
assert.equal(finalSize, headerSize + srcTextSize,
|
|
196
|
+
"Appended file size should be header + CLOB data");
|
|
197
|
+
|
|
198
|
+
console.log(" PASS: SQL_FILE_APPEND correctly appends LOB data.");
|
|
199
|
+
|
|
200
|
+
try { fs.unlinkSync(outFile); } catch(e) {}
|
|
201
|
+
|
|
202
|
+
testFetchSyncWithFile();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ======================================================================
|
|
206
|
+
// Test 4: fetchSync (single row) with bindFileToColSync
|
|
207
|
+
// ======================================================================
|
|
208
|
+
function testFetchSyncWithFile() {
|
|
209
|
+
console.log("\n--- Test 4: fetchSync with bindFileToColSync ---");
|
|
210
|
+
|
|
211
|
+
var outImage = path.join(dataDir, "test4_photo.jpg");
|
|
212
|
+
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
213
|
+
|
|
214
|
+
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
215
|
+
" WHERE ID = 1 ORDER BY ID");
|
|
216
|
+
var result = s.executeSync();
|
|
217
|
+
|
|
218
|
+
result.bindFileToColSync(2, outImage, ibmdb.SQL_FILE_OVERWRITE);
|
|
219
|
+
|
|
220
|
+
var row = result.fetchSync();
|
|
221
|
+
assert.notEqual(row, null, "fetchSync should return a row");
|
|
222
|
+
console.log(" Row ID:", row.ID, "PHOTO:", row.PHOTO);
|
|
223
|
+
assert.equal(row.PHOTO, outImage,
|
|
224
|
+
"PHOTO should contain file path");
|
|
225
|
+
|
|
226
|
+
// Verify file was written
|
|
227
|
+
var outSize = fs.statSync(outImage).size;
|
|
228
|
+
assert.equal(outSize, srcImageSize, "Image sizes should match");
|
|
229
|
+
|
|
230
|
+
// No more rows
|
|
231
|
+
var row2 = result.fetchSync();
|
|
232
|
+
assert.equal(row2, null, "No more rows expected");
|
|
233
|
+
|
|
234
|
+
result.closeSync();
|
|
235
|
+
s.closeSync();
|
|
236
|
+
console.log(" PASS: fetchSync + bindFileToColSync works.");
|
|
237
|
+
|
|
238
|
+
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
239
|
+
|
|
240
|
+
testAsyncBindFileToCol();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ======================================================================
|
|
244
|
+
// Test 5: async bindFileToCol() with callback
|
|
245
|
+
// ======================================================================
|
|
246
|
+
function testAsyncBindFileToCol() {
|
|
247
|
+
console.log("\n--- Test 5: async bindFileToCol() with callback ---");
|
|
248
|
+
|
|
249
|
+
var outImage = path.join(dataDir, "test5_photo.jpg");
|
|
250
|
+
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
251
|
+
|
|
252
|
+
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
253
|
+
" WHERE ID = 1 ORDER BY ID");
|
|
254
|
+
var result = s.executeSync();
|
|
255
|
+
|
|
256
|
+
result.bindFileToCol(2, outImage, ibmdb.SQL_FILE_OVERWRITE, function(err) {
|
|
257
|
+
if (err) { console.log("ERROR:", err); assert.fail(); }
|
|
258
|
+
|
|
259
|
+
result.fetch(function(err, row) {
|
|
260
|
+
if (err) { console.log("ERROR:", err); assert.fail(); }
|
|
261
|
+
assert.notEqual(row, null, "Should get a row");
|
|
262
|
+
console.log(" Row ID:", row.ID, "PHOTO:", row.PHOTO);
|
|
263
|
+
assert.equal(row.PHOTO, outImage);
|
|
264
|
+
|
|
265
|
+
var outSize = fs.statSync(outImage).size;
|
|
266
|
+
assert.equal(outSize, srcImageSize);
|
|
267
|
+
|
|
268
|
+
result.fetch(function(err, row2) {
|
|
269
|
+
assert.equal(row2, null, "No more rows");
|
|
270
|
+
result.closeSync();
|
|
271
|
+
s.closeSync();
|
|
272
|
+
console.log(" PASS: async bindFileToCol() + fetch() works.");
|
|
273
|
+
|
|
274
|
+
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
275
|
+
|
|
276
|
+
testQueryStream();
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ======================================================================
|
|
283
|
+
// Test 6: queryStream for row-level streaming
|
|
284
|
+
// ======================================================================
|
|
285
|
+
function testQueryStream() {
|
|
286
|
+
console.log("\n--- Test 6: queryStream for row-level streaming ---");
|
|
287
|
+
console.log(" queryStream() streams rows (not LOB columns).");
|
|
288
|
+
console.log(" Each row still has full LOB data in memory.");
|
|
289
|
+
console.log(" For large LOBs, use bindFileToColSync instead.");
|
|
290
|
+
|
|
291
|
+
var rows = [];
|
|
292
|
+
var stream = conn.queryStream("SELECT ID, TRACE FROM " + tableName +
|
|
293
|
+
" ORDER BY ID");
|
|
294
|
+
|
|
295
|
+
stream.on("data", function(row) {
|
|
296
|
+
rows.push(row);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
stream.on("error", function(err) {
|
|
300
|
+
console.log(" Stream error:", err);
|
|
301
|
+
assert.fail("Stream should not error");
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
stream.on("end", function() {
|
|
305
|
+
console.log(" Streamed " + rows.length + " rows");
|
|
306
|
+
assert.equal(rows.length, 2, "Should stream 2 rows");
|
|
307
|
+
assert.equal(rows[0].ID, 1);
|
|
308
|
+
assert.equal(rows[1].ID, 2);
|
|
309
|
+
|
|
310
|
+
// Row 1 has CLOB data, Row 2 has NULL
|
|
311
|
+
assert.notEqual(rows[0].TRACE, null, "Row 1 TRACE should have data");
|
|
312
|
+
assert.equal(rows[1].TRACE, null, "Row 2 TRACE should be null");
|
|
313
|
+
|
|
314
|
+
console.log(" PASS: queryStream streams rows successfully.");
|
|
315
|
+
console.log(" NOTE: queryStream loads LOB data into memory per row.");
|
|
316
|
+
console.log(" For zero-copy LOB handling, use bindFileToColSync.");
|
|
317
|
+
|
|
318
|
+
testAsyncAwaitFetchToFile();
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ======================================================================
|
|
323
|
+
// Test 7: async/await with bindFileToCol (Promise)
|
|
324
|
+
// ======================================================================
|
|
325
|
+
function testAsyncAwaitFetchToFile() {
|
|
326
|
+
console.log("\n--- Test 7: async/await with bindFileToCol ---");
|
|
327
|
+
|
|
328
|
+
asyncTests().then(function() {
|
|
329
|
+
cleanup();
|
|
330
|
+
}).catch(function(err) {
|
|
331
|
+
console.log(" Error:", err);
|
|
332
|
+
assert.fail("async/await test failed");
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async function asyncTests() {
|
|
337
|
+
var outImage = path.join(dataDir, "test7_photo.jpg");
|
|
338
|
+
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
339
|
+
|
|
340
|
+
var s = conn.prepareSync("SELECT * FROM " + tableName +
|
|
341
|
+
" WHERE ID = 1 ORDER BY ID");
|
|
342
|
+
var result = s.executeSync();
|
|
343
|
+
|
|
344
|
+
// await the async bindFileToCol (Promise version)
|
|
345
|
+
await result.bindFileToCol(2, outImage, ibmdb.SQL_FILE_OVERWRITE);
|
|
346
|
+
|
|
347
|
+
var data = await result.fetchAll();
|
|
348
|
+
result.closeSync();
|
|
349
|
+
s.closeSync();
|
|
350
|
+
|
|
351
|
+
assert.equal(data.length, 1);
|
|
352
|
+
assert.equal(data[0].PHOTO, outImage);
|
|
353
|
+
|
|
354
|
+
var outSize = fs.statSync(outImage).size;
|
|
355
|
+
assert.equal(outSize, srcImageSize);
|
|
356
|
+
|
|
357
|
+
console.log(" PASS: async/await bindFileToCol + fetchAll works.");
|
|
358
|
+
|
|
359
|
+
try { fs.unlinkSync(outImage); } catch(e) {}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ======================================================================
|
|
363
|
+
// Cleanup
|
|
364
|
+
// ======================================================================
|
|
365
|
+
function cleanup() {
|
|
366
|
+
conn.querySync("DROP TABLE " + tableName);
|
|
367
|
+
conn.closeSync();
|
|
368
|
+
console.log("\nAll tests passed! Connection closed.");
|
|
369
|
+
}
|
|
370
|
+
});
|