@sap/async-xsjs 1.0.2

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 (178) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +37 -0
  3. package/README.md +445 -0
  4. package/differences.md +162 -0
  5. package/docs/$.Application.html +262 -0
  6. package/docs/$.Session.html +674 -0
  7. package/docs/$.db.CallableStatement.html +2524 -0
  8. package/docs/$.db.Connection.html +511 -0
  9. package/docs/$.db.ParameterMetaData.html +805 -0
  10. package/docs/$.db.PreparedStatement.html +1796 -0
  11. package/docs/$.db.ResultSet.html +1308 -0
  12. package/docs/$.db.ResultSetMetaData.html +800 -0
  13. package/docs/$.db.SQLException.html +259 -0
  14. package/docs/$.db.html +773 -0
  15. package/docs/$.hdb.ColumnMetadata.html +438 -0
  16. package/docs/$.hdb.Connection.html +663 -0
  17. package/docs/$.hdb.ProcedureResult.html +280 -0
  18. package/docs/$.hdb.ResultSet.html +324 -0
  19. package/docs/$.hdb.ResultSetIterator.html +315 -0
  20. package/docs/$.hdb.ResultSetMetaData.html +259 -0
  21. package/docs/$.hdb.SQLException.html +259 -0
  22. package/docs/$.hdb.html +557 -0
  23. package/docs/$.html +471 -0
  24. package/docs/$.jobs.Job.html +783 -0
  25. package/docs/$.jobs.JobLog.html +380 -0
  26. package/docs/$.jobs.JobSchedules.html +852 -0
  27. package/docs/$.jobs.html +238 -0
  28. package/docs/$.net.Destination.html +304 -0
  29. package/docs/$.net.Mail.Part.html +510 -0
  30. package/docs/$.net.Mail.html +504 -0
  31. package/docs/$.net.SMTPConnection.html +347 -0
  32. package/docs/$.net.html +749 -0
  33. package/docs/$.net.http.Client.html +562 -0
  34. package/docs/$.net.http.Destination.html +237 -0
  35. package/docs/$.net.http.Request.html +567 -0
  36. package/docs/$.net.http.html +292 -0
  37. package/docs/$.security.AntiVirus.html +361 -0
  38. package/docs/$.security.Store.html +636 -0
  39. package/docs/$.security.crypto.html +414 -0
  40. package/docs/$.security.html +247 -0
  41. package/docs/$.security.x509.html +373 -0
  42. package/docs/$.text.analysis.Session.html +983 -0
  43. package/docs/$.text.analysis.html +242 -0
  44. package/docs/$.text.html +246 -0
  45. package/docs/$.text.mining.Session.html +2018 -0
  46. package/docs/$.text.mining.html +242 -0
  47. package/docs/$.trace.html +525 -0
  48. package/docs/$.util.SAXParser.html +955 -0
  49. package/docs/$.util.Zip.html +474 -0
  50. package/docs/$.util.codec.html +414 -0
  51. package/docs/$.util.compression.html +357 -0
  52. package/docs/$.util.html +325 -0
  53. package/docs/$.util.sql.html +290 -0
  54. package/docs/$.web.Body.html +333 -0
  55. package/docs/$.web.EntityList.html +296 -0
  56. package/docs/$.web.TupelList.html +496 -0
  57. package/docs/$.web.WebEntityRequest.html +393 -0
  58. package/docs/$.web.WebEntityResponse.html +392 -0
  59. package/docs/$.web.WebRequest.html +560 -0
  60. package/docs/$.web.WebResponse.html +609 -0
  61. package/docs/$.web.html +246 -0
  62. package/docs/Copyright-SAP.html +39 -0
  63. package/docs/Disclaimer-SAP.html +55 -0
  64. package/docs/index.html +232 -0
  65. package/docs/styles/jsdoc-default.css +382 -0
  66. package/lib/AppConfig.js +36 -0
  67. package/lib/AuditLogger.js +41 -0
  68. package/lib/cacert.js +26 -0
  69. package/lib/ctypes.js +153 -0
  70. package/lib/destinations/dest-provider.js +57 -0
  71. package/lib/index.js +235 -0
  72. package/lib/jobs/Action.js +40 -0
  73. package/lib/jobs/Job.js +100 -0
  74. package/lib/jobs/JobManager.js +150 -0
  75. package/lib/jobs/JobsRuntime.js +133 -0
  76. package/lib/jobs/SqlScriptJobRunner.js +36 -0
  77. package/lib/jobs/XsjsJobRunner.js +78 -0
  78. package/lib/jobs/index.js +11 -0
  79. package/lib/logging.js +16 -0
  80. package/lib/middleware.js +125 -0
  81. package/lib/odata/ODataService.js +125 -0
  82. package/lib/odata/index.js +7 -0
  83. package/lib/odata/service-factory.js +26 -0
  84. package/lib/passport-noauth.js +17 -0
  85. package/lib/routes.js +115 -0
  86. package/lib/runtime.js +740 -0
  87. package/lib/sandbox.js +40 -0
  88. package/lib/utils/XsJsFunctionRunner.js +57 -0
  89. package/lib/utils/XsJsLibFunctionRunner.js +57 -0
  90. package/lib/utils/buffer-utils.js +77 -0
  91. package/lib/utils/compression-utils.js +14 -0
  92. package/lib/utils/date-utils.js +104 -0
  93. package/lib/utils/errors/HttpError.js +20 -0
  94. package/lib/utils/errors/wrap-app-error.js +18 -0
  95. package/lib/utils/index.js +17 -0
  96. package/lib/utils/xs-function-runner.js +51 -0
  97. package/lib/utils/xs-types.js +21 -0
  98. package/lib/utils/xspath.js +36 -0
  99. package/lib/utils/xsstack.js +28 -0
  100. package/lib/views/error.html +28 -0
  101. package/lib/xsjs/Application.js +28 -0
  102. package/lib/xsjs/Locale.js +53 -0
  103. package/lib/xsjs/Session.js +31 -0
  104. package/lib/xsjs/constants.js +71 -0
  105. package/lib/xsjs/db/common/DbBase.js +85 -0
  106. package/lib/xsjs/db/common/DbOptions.js +163 -0
  107. package/lib/xsjs/db/common/arguments-validation.js +102 -0
  108. package/lib/xsjs/db/common/connection.js +12 -0
  109. package/lib/xsjs/db/common/enums.js +93 -0
  110. package/lib/xsjs/db/common/execute-batch.js +38 -0
  111. package/lib/xsjs/db/common/parse-time.js +139 -0
  112. package/lib/xsjs/db/dbapi/CallableStatement.js +192 -0
  113. package/lib/xsjs/db/dbapi/Connection.js +78 -0
  114. package/lib/xsjs/db/dbapi/DB.js +39 -0
  115. package/lib/xsjs/db/dbapi/ParameterMetaData.js +118 -0
  116. package/lib/xsjs/db/dbapi/PreparedStatement.js +78 -0
  117. package/lib/xsjs/db/dbapi/ResultSet.js +220 -0
  118. package/lib/xsjs/db/dbapi/ResultSetMetaData.js +116 -0
  119. package/lib/xsjs/db/dbapi/Statement.js +514 -0
  120. package/lib/xsjs/db/dbapi/conversions.js +113 -0
  121. package/lib/xsjs/db/dbapi/fetch-rows.js +32 -0
  122. package/lib/xsjs/db/hdbapi/Connection.js +525 -0
  123. package/lib/xsjs/db/hdbapi/HDB.js +32 -0
  124. package/lib/xsjs/db/hdbapi/ResultSetIterator.js +40 -0
  125. package/lib/xsjs/db/hdbapi/convert.js +77 -0
  126. package/lib/xsjs/db/hdbapi/table-string-parser.js +52 -0
  127. package/lib/xsjs/db/index.js +4 -0
  128. package/lib/xsjs/index.js +13 -0
  129. package/lib/xsjs/jobs/Job.js +228 -0
  130. package/lib/xsjs/jobs/Jobs.js +11 -0
  131. package/lib/xsjs/jobs/Logs.js +127 -0
  132. package/lib/xsjs/jobs/Schedule.js +110 -0
  133. package/lib/xsjs/jobs/Schedules.js +108 -0
  134. package/lib/xsjs/net/Destination.js +43 -0
  135. package/lib/xsjs/net/http/Client.js +220 -0
  136. package/lib/xsjs/net/http/HTTP.js +72 -0
  137. package/lib/xsjs/net/index.js +5 -0
  138. package/lib/xsjs/net/smtp/Mail.js +38 -0
  139. package/lib/xsjs/net/smtp/Part.js +30 -0
  140. package/lib/xsjs/net/smtp/SMTPConnection.js +39 -0
  141. package/lib/xsjs/net/smtp/index.js +18 -0
  142. package/lib/xsjs/net/smtp/nodemailer-util.js +77 -0
  143. package/lib/xsjs/require.js +39 -0
  144. package/lib/xsjs/security/AntiVirus.js +31 -0
  145. package/lib/xsjs/security/Store.js +119 -0
  146. package/lib/xsjs/security/crypto.js +23 -0
  147. package/lib/xsjs/security/index.js +5 -0
  148. package/lib/xsjs/security/x509.js +12 -0
  149. package/lib/xsjs/text/analysis/Session.js +128 -0
  150. package/lib/xsjs/text/index.js +30 -0
  151. package/lib/xsjs/text/mining/Session.js +82 -0
  152. package/lib/xsjs/trace/trace.js +41 -0
  153. package/lib/xsjs/util/SAXParser.js +174 -0
  154. package/lib/xsjs/util/Zip.js +220 -0
  155. package/lib/xsjs/util/codec.js +33 -0
  156. package/lib/xsjs/util/compression.js +24 -0
  157. package/lib/xsjs/util/index.js +22 -0
  158. package/lib/xsjs/web/BasicWebEntity.js +41 -0
  159. package/lib/xsjs/web/EntityList.js +11 -0
  160. package/lib/xsjs/web/TupelLists/CookiesTupelList.js +47 -0
  161. package/lib/xsjs/web/TupelLists/HeadersTupelList.js +55 -0
  162. package/lib/xsjs/web/TupelLists/ParametersTupelList.js +83 -0
  163. package/lib/xsjs/web/TupelLists/TupelListBase.js +45 -0
  164. package/lib/xsjs/web/WebBody.js +135 -0
  165. package/lib/xsjs/web/WebEntityRequest.js +40 -0
  166. package/lib/xsjs/web/WebEntityResponse.js +26 -0
  167. package/lib/xsjs/web/WebRequest.js +209 -0
  168. package/lib/xsjs/web/WebResponse.js +183 -0
  169. package/lib/xsjs/web/index.js +4 -0
  170. package/lib/xsjs/web/utils/HeadersParser.js +53 -0
  171. package/lib/xsjs/web/utils/HttpRequestParser.js +93 -0
  172. package/lib/xsjs/web/utils/MultipartParser.js +163 -0
  173. package/lib/xsjs/web/utils/MultipartResponseBuilder.js +73 -0
  174. package/lib/xsjs/web/utils/SetCookieParser.js +32 -0
  175. package/lib/xsjslib/TextBundleWrapper.js +46 -0
  176. package/lib/xsjslib/index.js +11 -0
  177. package/npm-shrinkwrap.json +11540 -0
  178. package/package.json +84 -0
@@ -0,0 +1,514 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var util = require('util');
5
+ var types = require('@sap/hana-client/extension/TypeCode');
6
+ var hanaPromise = require('@sap/hana-client/extension/Promise');
7
+ var FunctionCode = require('@sap/hana-client/extension/FunctionCode');
8
+ var ctypes = require('../../../ctypes');
9
+ var parser = require('../common/parse-time');
10
+ var ResultSet = require('./ResultSet');
11
+ var bufferUtils = require('../../../utils/buffer-utils');
12
+ var xsTypes = require('../../../utils/xs-types');
13
+ var ParameterMetaData = require('./ParameterMetaData');
14
+ var argumentsUtil = require('../common/arguments-validation');
15
+ var fetchRows = require('./fetch-rows');
16
+ var INTEGER_TYPE = argumentsUtil.INTEGER_TYPE;
17
+
18
+ module.exports = Statement;
19
+
20
+ function Statement(statement) {
21
+ this._statement = statement;
22
+ this._parameters = [];
23
+ this._parameterInfo = statement.getParameterInfo();
24
+ this._results = undefined;
25
+ this._rowsCursor = 0;
26
+ this._resultset = undefined;
27
+ }
28
+
29
+ /**
30
+ * Executes a common statement
31
+ * @returns {boolean} True if the execution yielded a result set (i.e. if a SELECT statement was executed), false if not
32
+ * @throws Throws an error if the object the method is being called on is not valid.
33
+ */
34
+
35
+ Statement.prototype.execute = async function () {
36
+ var self = this;
37
+
38
+ async function executeStatement() {
39
+ var functionCode = self._statement.functionCode();
40
+ switch (functionCode) {
41
+ case FunctionCode.NIL:
42
+ case FunctionCode.DDL:
43
+ case FunctionCode.INSERT:
44
+ case FunctionCode.UPDATE:
45
+ case FunctionCode.DELETE:
46
+ case FunctionCode.SELECT:
47
+ case FunctionCode.SELECT_FOR_UPDATE:
48
+ try {
49
+ var rez = await hanaPromise.execute(self._statement, self._parameters, {rowsAsArray: true});
50
+ if (functionCode === FunctionCode.INSERT || functionCode === FunctionCode.UPDATE || functionCode === FunctionCode.DELETE) {
51
+ return {rowsAffected: rez};
52
+ }
53
+
54
+ if (functionCode === FunctionCode.SELECT || functionCode === FunctionCode.SELECT_FOR_UPDATE) {
55
+ return {setsOfRows: [{rows: rez, columnInfo: self._statement.getColumnInfo()}]};
56
+ }
57
+ return {};
58
+ } catch (e) {
59
+ throw e;
60
+ }
61
+
62
+ case FunctionCode.DB_PROCEDURE_CALL:
63
+ case FunctionCode.DB_PROCEDURE_CALL_WITH_RESULT:
64
+ var resultSet;
65
+ var result = {};
66
+ try {
67
+ resultSet = await hanaPromise.executeQuery(self._statement, self._parameters);
68
+ result.parameters = await transformProcParameters(self._statement);
69
+ if (!resultSet.getColumnCount()) {
70
+ return result;
71
+ }
72
+ } catch (e) {
73
+ throw e;
74
+ }
75
+ var setsOfRows = [];
76
+ await fetchAllResults(setsOfRows, resultSet);
77
+ try {
78
+ resultSet.close();
79
+ result.setsOfRows = setsOfRows;
80
+ return result;
81
+ } catch (e) {
82
+ throw e;
83
+ }
84
+ default:
85
+ throw new Error('Invalid or unsupported FunctionCode ' + functionCode);
86
+ }
87
+ }
88
+
89
+ this._results = await executeStatement();
90
+ return !!this._results.setsOfRows;
91
+ };
92
+
93
+ /**
94
+ * Closes the statement
95
+ * @throws Throws an error if the object the method is being called on is not valid.
96
+ */
97
+ Statement.prototype.close = async function () {
98
+ await this._statement.drop();
99
+ };
100
+
101
+ /**
102
+ * Checks if the statement is closed.
103
+ * @returns {boolean} Returns true if the statement is already closed, false if not
104
+ * @throws Throws an error if the object the method is being called on is not valid.
105
+ */
106
+ Statement.prototype.isClosed = function () {
107
+ return !this._statement.isValid();
108
+ };
109
+
110
+ /**
111
+ * Returns a resultset representing a table output parameter
112
+ * @returns {db.ResultSet} ResultSet of the next output table parameter
113
+ * @throws Throws an error if the object the method is being called on is not valid.
114
+ */
115
+ Statement.prototype.getResultSet = function () {
116
+ if (this._resultset) {
117
+ return this._resultset;
118
+ }
119
+ var setsOfRows = this._results && this._results.setsOfRows;
120
+ if (setsOfRows && this._rowsCursor < setsOfRows.length) {
121
+ this._resultset = new ResultSet(this._results.setsOfRows[this._rowsCursor]);
122
+ return this._resultset;
123
+ }
124
+ };
125
+
126
+ /**
127
+ * Checks if more resultsets are available and prepares the next resultset for retrieval
128
+ * @returns {boolean} True if the next resultset is available
129
+ * @throws Throws an error if the object the method is being called on is not valid.
130
+ */
131
+ Statement.prototype.getMoreResults = function () {
132
+ var setsOfRows = this._results && this._results.setsOfRows;
133
+ if (setsOfRows && this._rowsCursor < (setsOfRows.length - 1)) {
134
+ this._resultset = undefined;
135
+ ++this._rowsCursor;
136
+ return true;
137
+ }
138
+ return false;
139
+ };
140
+
141
+ /**
142
+ * Returns the metadata of the prepared statement
143
+ * @returns {db.ParameterMetaData} ParameterMetaData object
144
+ * @throws Throws an error if the object the method is being called on is not valid.
145
+ */
146
+ Statement.prototype.getParameterMetaData = function () {
147
+ return new ParameterMetaData(this._parameterInfo);
148
+ };
149
+
150
+ /**
151
+ * Sets an integer parameter used for BIGINT column types
152
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
153
+ * @param {integer} value The number value to be set for this parameter
154
+ * @throws Throws an error on invalid parameters.
155
+ */
156
+ Statement.prototype.setBigInt = function (columnIndex, value) {
157
+ argumentsUtil.validateSetterArgs(arguments, 2);
158
+ var bigInt;
159
+ if (value === undefined) {
160
+ bigInt = '-9223372036854775808';
161
+ } else if (value === null || value === '') {
162
+ bigInt = 0;
163
+ } else if (value instanceof ctypes.Int64) {
164
+ bigInt = value.toString();
165
+ }
166
+ if (bigInt !== undefined) {
167
+ return this._parameters[columnIndex - 1] = bigInt;
168
+ }
169
+
170
+ if (_.isObject(value)) {
171
+ throw new Error('Second argument is not an Int64 object');
172
+ }
173
+
174
+ if (_.isString(value)) {
175
+ value = Number.parseFloat(value);
176
+ if (Number.isNaN(value)) {
177
+ throw new Error('Could not convert second argument to double');
178
+ }
179
+ }
180
+ argumentsUtil.validateNumber(value);
181
+ argumentsUtil.validateIntegerBoundaries(INTEGER_TYPE.BIG_INT, value);
182
+ this._parameters[columnIndex - 1] = argumentsUtil.numberToInteger(value);
183
+ };
184
+
185
+ /**
186
+ * Sets an integer parameter used for TINYINT, SMALLINT, INT column types
187
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
188
+ * @param {integer} value The integer value to be set for this parameter
189
+ * @throws Throws an error on invalid parameters.
190
+ */
191
+ Statement.prototype.setInteger = function (columnIndex, value) {
192
+ argumentsUtil.validateSetterArgs(arguments, 2);
193
+ argumentsUtil.validateNumber(value);
194
+ argumentsUtil.validateIntegerBoundaries(INTEGER_TYPE.INTEGER, value);
195
+ this._parameters[columnIndex - 1] = argumentsUtil.numberToInteger(value);
196
+ };
197
+ Statement.prototype.setInt = Statement.prototype.setInteger;
198
+
199
+ /**
200
+ * Sets an integer parameter used for SMALLINT column types
201
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
202
+ * @param {integer} value The integer value to be set for this parameter
203
+ * @throws Throws an error on invalid parameters.
204
+ */
205
+ Statement.prototype.setSmallInt = function (columnIndex, value) {
206
+ argumentsUtil.validateSetterArgs(arguments, 2);
207
+ argumentsUtil.validateInteger(value);
208
+ argumentsUtil.validateIntegerBoundaries(INTEGER_TYPE.SMALL_INT, value);
209
+ this._parameters[columnIndex - 1] = value;
210
+ };
211
+
212
+ /**
213
+ * Sets an integer parameter used for TINYINT column types
214
+ * @param {integer} columnIndex The index of the parameter in the prepared statement, <b>starting from 1</b>
215
+ * @param {integer} value The integer value to be set for this parameter (unsigned char: min 0, max 255)
216
+ * @throws Throws an error on invalid parameters.
217
+ */
218
+ Statement.prototype.setTinyInt = function (columnIndex, value) {
219
+ argumentsUtil.validateSetterArgs(arguments, 2);
220
+ argumentsUtil.validateInteger(value);
221
+ argumentsUtil.validateIntegerBoundaries(INTEGER_TYPE.TINY_INT, value);
222
+ this._parameters[columnIndex - 1] = value;
223
+ };
224
+
225
+ /**
226
+ * setDouble sets a double parameter used for FLOAT and DOUBLE column types.
227
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
228
+ * @param {number} value The number value to be set for this parameter
229
+ * @throws Throws an error on invalid parameters.
230
+ */
231
+ Statement.prototype.setDouble = function (columnIndex, value) {
232
+ argumentsUtil.validateSetterArgs(arguments, 2);
233
+ argumentsUtil.validateNumber(value);
234
+ if (!Number.isFinite(value)) {
235
+ throw new Error('Second argument is +/-Infinity');
236
+ }
237
+ this._parameters[columnIndex - 1] = value;
238
+ };
239
+
240
+ /**
241
+ * setFloat sets a float parameter used for FLOAT column types.
242
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
243
+ * @param {number} value The number value to be set for this parameter
244
+ * @throws Throws an error on invalid parameters.
245
+ */
246
+ Statement.prototype.setFloat = Statement.prototype.setDouble;
247
+
248
+ /**
249
+ * setDecimal sets a decimal parameter used for DECIMAL column types.
250
+ * @param {integer} index The index of the parameter in the prepared statement <b>starting from 1</b>
251
+ * @param {number} value The number value to be set for this parameter
252
+ * @throws Throws an error on invalid parameters.
253
+ */
254
+ Statement.prototype.setDecimal = function (columnIndex, value) {
255
+ argumentsUtil.validateSetterArgs(arguments, 2);
256
+ if (!_.isNumber(value) && !_.isString(value)) {
257
+ throw new Error('Expected either a number or a string as second argument');
258
+ }
259
+ if (_.isNumber(value) && !Number.isFinite(value)) {
260
+ throw new Error('Second argument is +/-Infinity');
261
+ }
262
+ this._parameters[columnIndex - 1] = value.toString();
263
+ };
264
+
265
+ /**
266
+ * setReal sets a real parameter used for REAL column types.
267
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
268
+ * @param {number} value The number value to be set for this parameter
269
+ * @throws Throws an error on invalid parameters.
270
+ */
271
+ Statement.prototype.setReal = Statement.prototype.setDouble;
272
+
273
+ /**
274
+ * setBlob is used to specify the values for CHAR, VARCHAR, NCHAR, NVARCHAR, BINARY, and VARBINARY column types.
275
+ * @param {integer} columnIndex The index of the parameter in the prepared statement, <b>starting from 1</b>
276
+ * @param {ArrayBuffer} value The ArrayBuffer object to be set for this parameter, can also be an Array of integers or a string.
277
+ * @throws Throws an error on invalid parameters.
278
+ */
279
+ Statement.prototype.setBlob = function (columnIndex, value) {
280
+ argumentsUtil.validateSetterArgs(arguments, 2);
281
+ if (bufferUtils.isBinary(value)) {
282
+ value = bufferUtils.toBuffer(value);
283
+ } else if (xsTypes.isWebBody(value)) {
284
+ value = bufferUtils.bodyToBuffer(value);
285
+ } else if (xsTypes.isZip(value)) {
286
+ value = bufferUtils.toBuffer(value.asArrayBuffer());
287
+ } else {
288
+ throw new Error('Expected ArrayBuffer, WebBody or a Zip object as second argument');
289
+ }
290
+
291
+ this._parameters[columnIndex - 1] = value;
292
+ };
293
+
294
+ /**
295
+ * setClob is used to specify the values for CLOB column types.
296
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
297
+ * @param {string} value The string value to be set for this parameter
298
+ * @throws Throws an error on invalid parameters.
299
+ */
300
+ Statement.prototype.setClob = function (columnIndex, value) {
301
+ argumentsUtil.validateSetterArgs(arguments, 2);
302
+ argumentsUtil.validateString(value);
303
+ this._parameters[columnIndex - 1] = value;
304
+ };
305
+
306
+ /**
307
+ * setNClob is used to specify the values for NCLOB column types.
308
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
309
+ * @param {string} value The string value to be set for this parameter
310
+ * @throws Throws an error on invalid parameters.
311
+ */
312
+ Statement.prototype.setNClob = Statement.prototype.setClob;
313
+
314
+ /**
315
+ * Sets a string parameter used for CHAR, VARCHAR column types; ASCII only, not suitable for strings containing Unicode characters <br>
316
+ * This function can be used to store strings containing ASCII and a subset of Unicode (namely BMP; the first 0xFFFF characters). <br>
317
+ * This function does not convert data; to improve performance, it stores data directly in the database. <br>
318
+ * Note that special characters (in Unicode SMP or SIP) can cause the read operation to fail.
319
+ * For more information see {@link http://en.wikipedia.org/wiki/Plane_%28Unicode%29|Plane (Unicode)}. <br>
320
+ * If also need special unicode characters or if you are not sure what this means it is safer to use setNString.
321
+ * @param {integer} columnIndex The index of the parameter in the statement <b>starting from 1</b>
322
+ * @param {string} value The string value to be set for this parameter
323
+ * @throws Throws an error on invalid parameters.
324
+ */
325
+ Statement.prototype.setString = function (columnIndex, value) {
326
+ argumentsUtil.validateSetterArgs(arguments, 2);
327
+ if (value !== undefined && !_.isString(value)) {
328
+ throw new Error('Expected undefined or string as second argument');
329
+ }
330
+ this._parameters[columnIndex - 1] = (value === undefined) ? null : value;
331
+ };
332
+
333
+ /**
334
+ * Sets a string parameter used for NCHAR, NVARCHAR parameter types, which should be used for strings containing unicode characters. <br>
335
+ * This function converts the given unicode string into a storable format. Make sure you use getNString to read the data.
336
+ * If you use getString on a column you wrote with setNString, an exception is thrown if the string contains unicode characters lager than 0xFFFF.
337
+ * @param {integer} columnIndex The index of the parameter <b>starting from 1</b>
338
+ * @param {string} value The string value to be set for this parameter
339
+ * @throws Throws an error on invalid parameters.
340
+ */
341
+ Statement.prototype.setNString = Statement.prototype.setString;
342
+
343
+ /**
344
+ * Sets an array buffer parameter used for BINARY, VARBINARY column types. <br> Remark: the BINARY type is deprecated - its behavior in row store and column store differs in that row store may pad with zeros.
345
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
346
+ * @param {ArrayBuffer} value The ArrayBuffer object to be set for this parameter.
347
+ * @throws Throws an error on invalid parameters.
348
+ */
349
+ Statement.prototype.setBString = function (columnIndex, value) {
350
+ argumentsUtil.validateSetterArgs(arguments, 2);
351
+ if (value === undefined) {
352
+ return this._parameters[columnIndex - 1] = null;
353
+ }
354
+ if (bufferUtils.isBinary(value)) {
355
+ value = bufferUtils.toBuffer(value);
356
+ } else if (xsTypes.isWebBody(value)) {
357
+ value = bufferUtils.bodyToBuffer(value);
358
+ } else {
359
+ throw new Error('Expected undefined, ArrayBuffer or WebBody as second argument');
360
+ }
361
+
362
+ this._parameters[columnIndex - 1] = value;
363
+ };
364
+
365
+ /**
366
+ * setText is used to specify the values for TEXT column types.
367
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
368
+ * @param {string} value The string value to be set for this parameter
369
+ * @throws Throws an error on invalid parameters.
370
+ */
371
+ Statement.prototype.setText = Statement.prototype.setClob;
372
+
373
+ /**
374
+ * Sets a Date parameter for DATE columns, but works with TIME and TIMESTAMP. It is not possible to set the time with setDate; you can only set the date.
375
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
376
+ * @param {Date|string} value The date to be set for this parameter <br/>
377
+ * The parameter can be either a Date object, a string in default ptime format (YYYY-MM-DD), or a string in the optionally specified format.<br/>
378
+ * For example: 'yyyymmdd' or 'yyyy-mm-dd' or 'yyyy/mm/dd'
379
+ * <ul>
380
+ * <li>Y,YY,YYY,YYYY-year</li>
381
+ * <li>D-day</li>
382
+ * <li>J-julian day</li>
383
+ * <li>MONTH-by name,MON-abbr.</li>
384
+ * <li>M-month</li>
385
+ * <li>Q-quarter</li>
386
+ * <li>RM-roman numeral month</li>
387
+ * <li>W-week of month</li>
388
+ * <li>WW-week of year.</li>
389
+ * </ul>
390
+ * Note that when you construct a new Date JavaScript object, the month number starts from <b>0</b> (not 1).<br>
391
+ * For example the following statement represents <em>1st of Jan, 2010</em>:<br>
392
+ * <i>new Date(2010,0,1);</i>
393
+ * @param {string} [format=""] One of the following formats: <br/>
394
+ * @throws Throws an error on invalid parameters.
395
+ */
396
+ Statement.prototype.setDate = function (columnIndex, value, format) {
397
+ argumentsUtil.validateSetterArgs(arguments, 2);
398
+ argumentsUtil.validateDateTime(value);
399
+ if (!util.isDate(value)) {
400
+ value = parser.parseDateTime(value, format);
401
+ }
402
+ switch (this._parameterInfo[columnIndex - 1].nativeType) {
403
+ case types.SECONDDATE:
404
+ case types.LONGDATE:
405
+ value = new Date(value);
406
+ value.setHours(0, 0, 0, 0); // setDate truncates the time
407
+ value = parser.formatDateTime(value);
408
+ break;
409
+ case types.SECONDTIME:
410
+ value = '00:00:00';
411
+ break;
412
+ default:
413
+ value = parser.formatDate(value);
414
+ }
415
+ this._parameters[columnIndex - 1] = value;
416
+ };
417
+
418
+ /**
419
+ * Sets a Time parameter used for TIME column types (hour, min, sec). You cannot set milliseconds (mls).
420
+ * @param {integer} columnIndex The index of the parameter in the prepared statement, <b>starting from 1</b>
421
+ * @param {Date|string} value The Date value to be set for this parameter <br>
422
+ * <ul>
423
+ * <li>HH:MI:SS.FF AM</li>
424
+ * <li>HH24:MI:SS.FF</li>
425
+ * <li>HH:MI:SS AM</li>
426
+ * <li>HH24:MI:SS</li>
427
+ * <li>HH:MI AM</li>
428
+ * <li>HH24:MI</li>
429
+ * <li>HH24:MI:SS.FF Z</li>
430
+ * <li>HH24:MI:SS Z</li>
431
+ * </ul>
432
+ * @param {string} [format=""] One of the following formats:<br/>
433
+ * @throws Throws an error on invalid parameters.
434
+ */
435
+ Statement.prototype.setTime = function (columnIndex, value, format) {
436
+ argumentsUtil.validateSetterArgs(arguments, 2);
437
+ argumentsUtil.validateDateTime(value);
438
+ if (!util.isDate(value)) {
439
+ value = parser.parseDateTime(value, format);
440
+ }
441
+ switch (this._parameterInfo[columnIndex - 1].nativeType) {
442
+ case types.SECONDDATE:
443
+ case types.LONGDATE:
444
+ value = parser.formatDateTime(value);
445
+ break;
446
+ case types.DAYDATE:
447
+ value = '0000-00-00';
448
+ break;
449
+ default:
450
+ value = parser.formatTime(value);
451
+ }
452
+ this._parameters[columnIndex - 1] = value;
453
+ };
454
+
455
+ /**
456
+ * Sets a Timestamp parameter used for TIMESTAMP column types
457
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
458
+ * @param {Date|string} value The timestamp value to be set for this parameter
459
+ * The default format is: <b>date</b> <b>separator</b> <b>time</b>, for example, <br>
460
+ * 2001-01-02 01:02:03.123, where <b>date</b> is the format to use for the date value <br>
461
+ * (see setDate), <b>separator</b> can be a space, a comma, or the letter T, and <br>
462
+ * <b>time</b> is the format to use for the time value (see setTime).<br>
463
+ * Examples:<br>
464
+ * 2001-01-02 01:02:03.123<br>
465
+ * 2001-01-02,01:02:03.123<br>
466
+ * 2001-01-02T01:02:03.123<br>
467
+ * <i>st.setTimestamp(4,"01.02.2003 01:02:03.123", "DD.MM.YYYY HH:MI:SS.FF");</i>
468
+ * @param {string} [format=""] Optional, see also setDate and setTime
469
+ * @throws Throws an error on invalid parameters.
470
+ */
471
+ Statement.prototype.setTimestamp = function (columnIndex, value, format) {
472
+ argumentsUtil.validateSetterArgs(arguments, 2);
473
+ argumentsUtil.validateDateTime(value);
474
+ if (!util.isDate(value)) {
475
+ value = parser.parseDateTime(value, format);
476
+ }
477
+ switch (this._parameterInfo[columnIndex - 1].nativeType) {
478
+ case types.SECONDTIME:
479
+ value = parser.formatTime(value);
480
+ break;
481
+ case types.DAYDATE:
482
+ value = parser.formatDate(value);
483
+ break;
484
+ default:
485
+ value = parser.formatDateTime(value);
486
+ }
487
+ this._parameters[columnIndex - 1] = value;
488
+ };
489
+
490
+ /**
491
+ * setNull is used to set a Null parameter used for all column types.
492
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
493
+ * @throws Throws an error on invalid parameters.
494
+ */
495
+ Statement.prototype.setNull = function (columnIndex) {
496
+ argumentsUtil.validateSetterArgs(arguments, 1);
497
+ this._parameters[columnIndex - 1] = null;
498
+ };
499
+
500
+ function transformProcParameters(statement) {
501
+ return statement.getParameterInfo().map(function (paramInfo, index) {
502
+ return statement.getParameterValue(index);
503
+ });
504
+ }
505
+
506
+ async function fetchAllResults(collection, resultSet) {
507
+ var rows = await fetchRows(resultSet, 'array');
508
+ collection.push({rows: rows, columnInfo: resultSet.getColumnInfo()});
509
+ var hasNextResultSet = await hanaPromise.nextResult(resultSet);
510
+ if (!hasNextResultSet) {
511
+ return;
512
+ }
513
+ await fetchAllResults (collection, resultSet);
514
+ }
@@ -0,0 +1,113 @@
1
+ 'use strict';
2
+
3
+ var argumentsUtil = require('../common/arguments-validation');
4
+ var ctypes = require('../../../ctypes');
5
+ var _ = require('lodash');
6
+ var bufferUtils = require('../../../utils/buffer-utils');
7
+ var dateUtils = require('../../../utils/date-utils');
8
+ var types = require('@sap/hana-client/extension/TypeCode');
9
+ var VError = require('verror');
10
+ var moment = require('moment');
11
+
12
+ module.exports = {
13
+ getInteger(value) {
14
+ if (value === null) {
15
+ return null;
16
+ }
17
+
18
+ var parsedValue = parseInt(value);
19
+ argumentsUtil.validateParsedInteger(parsedValue, value);
20
+ argumentsUtil.validateIntegerBoundaries(argumentsUtil.INTEGER_TYPE.BIG_INT, parsedValue);
21
+ return parsedValue;
22
+ },
23
+
24
+ getBigInt(value) {
25
+ if (value === null) {
26
+ return null;
27
+ }
28
+
29
+ var parsedValue = parseInt(value);
30
+ argumentsUtil.validateParsedInteger(parsedValue, value);
31
+ value = _.isNumber(value) ? parsedValue : value;
32
+ return ctypes.Int64(value);
33
+ },
34
+
35
+ getString(value, dbType) {
36
+ if (value === null) {
37
+ return null;
38
+ }
39
+
40
+ if (bufferUtils.isBinary(value)) {
41
+ throw new VError('Unsupported type conversion from %s to string', typeof value);
42
+ }
43
+ if (dbType === types.LONGDATE) {
44
+ return dateUtils.normalizeDateTimeString(value);
45
+ }
46
+ return value.toString();
47
+ },
48
+
49
+ getBlob(value, dbType) {
50
+ if (value === null) {
51
+ return null;
52
+ }
53
+ if (dbType === types.CLOB || dbType === types.NCLOB ||
54
+ dbType === types.TEXT || dbType === types.BINTEXT) {
55
+ return bufferUtils.toArrayBuffer(bufferUtils.toBuffer(value));
56
+ }
57
+ if (!bufferUtils.isBinary(value)) {
58
+ throw new VError('Unsupported type conversion from %s to ArrayBuffer', typeof value);
59
+ }
60
+ return bufferUtils.toArrayBuffer(value);
61
+ },
62
+
63
+ getClob(value, dbType) {
64
+ if (value === null) {
65
+ return value;
66
+ }
67
+ if (dbType === types.LONGDATE) {
68
+ return dateUtils.normalizeDateTimeString(value);
69
+ }
70
+ if (_.isString(value)) {
71
+ return value;
72
+ }
73
+ if (bufferUtils.isBuffer(value)) {
74
+ return value.toString('utf8');
75
+ }
76
+ throw new VError('Unsupported type conversion from %s to string', typeof value);
77
+ },
78
+
79
+ getDate(value) {
80
+ if (value === null) {
81
+ return null;
82
+ }
83
+ argumentsUtil.validateDateValue(value);
84
+ var dateTime = moment(value, moment.ISO_8601);
85
+ if (!dateTime.isValid()) {
86
+ throw new VError('Unsupported type conversion from string "%s" to a valid date object', value);
87
+ }
88
+ return dateTime.toDate();
89
+ },
90
+
91
+ getTime(value) {
92
+ if (value === null) {
93
+ return null;
94
+ }
95
+ argumentsUtil.validateDateValue(value);
96
+ var validTimeMatch = value.match(/(\d{2}):(\d{2}):(\d{2})(\.(\d+))?/);
97
+ if (!validTimeMatch) {
98
+ return module.exports.getDate(value);
99
+ }
100
+ return new Date(-1, 11, 31, +validTimeMatch[1], +validTimeMatch[2], +validTimeMatch[3], 0);
101
+ },
102
+
103
+ getDecimal(value) {
104
+ if (value === null) {
105
+ return null;
106
+ }
107
+ var parsedValue = parseFloat(value);
108
+ if (_.isNaN(parsedValue)) {
109
+ throw new VError('Unsupported type conversion from %s to number. Not a valid number value: "%s"', typeof value, value);
110
+ }
111
+ return parsedValue;
112
+ }
113
+ };
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var dbStream = require('@sap/hana-client/extension/Stream');
4
+
5
+ module.exports = fetchRowsPromise;
6
+
7
+ function fetchRowsPromise (resultSet, streamType) {
8
+ return new Promise ((resolve, reject) => {
9
+ var rows = [];
10
+
11
+ var stream = (streamType === 'array') ?
12
+ dbStream.createArrayStream(resultSet) :
13
+ dbStream.createObjectStream(resultSet);
14
+
15
+ stream.on('readable', function () {
16
+ var data;
17
+ while ((data = stream.read()) !== null) {
18
+ rows.push(data);
19
+ }
20
+ });
21
+
22
+ stream.once('error', function (err) {
23
+ stream.removeAllListeners();
24
+ reject(err);
25
+ });
26
+
27
+ stream.on('end', function () {
28
+ stream.removeAllListeners();
29
+ resolve(rows);
30
+ });
31
+ });
32
+ }