@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,139 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+ var moment = require('moment');
5
+
6
+ // This is a workaround for the output that moment js produces when you try to instantiate a Javascript specific date via the moment constructor.
7
+ moment.createFromInputFallback = function(config) {
8
+ config._d = new Date(NaN);
9
+ };
10
+
11
+ exports.formatDate = function(date) {
12
+ // see node_modules/hdb/lib/protocol/Writer.js for the expected format
13
+ return zpad(date.getFullYear(), 4) + '-' + zpad(date.getMonth() + 1, 2) + '-' + zpad(date.getDate(), 2);
14
+ };
15
+
16
+ exports.formatTime = function(date) {
17
+ // see node_modules/hdb/lib/protocol/Writer.js for the expected format
18
+ return zpad(date.getHours(), 2) + ':' + zpad(date.getMinutes(), 2) + ':' +
19
+ zpad(date.getSeconds(), 2);
20
+ };
21
+
22
+ exports.formatDateTime = function(date) {
23
+ // see node_modules/hdb/lib/protocol/Writer.js for the expected format
24
+ return exports.formatDate(date) + 'T' + exports.formatTime(date) + '.' + zpad(date.getMilliseconds(), 3);
25
+ };
26
+
27
+ exports.parseDateTime = function(value, format) {
28
+ if (!format && isAbabFormat(value)) {
29
+ format = 'YYYYMMDD';
30
+ }
31
+
32
+ if (format) {
33
+ // Change the format if it is HANA Specific so that moment understands it.
34
+ var HANA_TO_MOMENTJS_MAPPING = {
35
+ // RM not supported !!! W and WW are not supported !!!
36
+ MM: 'M',
37
+ DD: 'D',
38
+ MONTH: 'MMMM',
39
+ MON: 'MMM',
40
+ HH24: 'H',
41
+ HH12: 'h',
42
+ MI: 'm',
43
+ SS: 's',
44
+ AM: 'A',
45
+ PM: 'A'
46
+ };
47
+
48
+ Object.keys(HANA_TO_MOMENTJS_MAPPING).forEach(function(hanaFormat) {
49
+ var momentFormat = HANA_TO_MOMENTJS_MAPPING[hanaFormat];
50
+ format = format.replace(hanaFormat, momentFormat);
51
+ });
52
+
53
+ // Fractional seconds. Example: HH:MI:SS.FFX, where X e {1, 2, ..., 7}. NOTE: In XS1 X represented the digits of fractional second. In XS Advanced they are always 3 digit.
54
+ format = format.replace(/FF\d/, 'SSS');
55
+
56
+ var momentDate = moment(value, format);
57
+ if (!momentDate.isValid()) {
58
+ throw new TypeError(util.format('Provided timestamp value: %s does not match the given format: %s or invalid format.', value, format));
59
+ }
60
+
61
+ return momentDate.toDate();
62
+ }
63
+
64
+ // Do not allow hours like '14:00:00 PM'. Note: third part of expression produces moment js output.
65
+ if (isNaN(Date.parse(value)) && value.indexOf('T') < 0 && !moment(value).isValid()) {
66
+ throw new TypeError(util.format('Provided timestamp value: %s is not valid.', value));
67
+ }
68
+
69
+ var separators = findDateSeparators(value);
70
+ // If date is DD MM YYYY, which is moment js specific, switch it to YYYY MM DD
71
+ value = exchangeYearAndDate(separators, value);
72
+
73
+ // If timestamp is not moment specific we can't just pass it to the moment constructor, so we need format.
74
+ if (!timestampIsMomentSpecific(value)) {
75
+ format = 'Y' + separators[0] + 'M' + separators[1] + 'D h:m:s.SSS A';
76
+ }
77
+
78
+ return moment(value, format).toDate();
79
+ };
80
+
81
+
82
+ // ABAP Data Type, DATS format is in form YYYYMMDD
83
+ var ABAP_TIMESTAMP_LENGTH = 8;
84
+
85
+ function isAbabFormat(value) {
86
+ var eightDigits = new RegExp('\\d{' + ABAP_TIMESTAMP_LENGTH + '}');
87
+
88
+ return (value.length === ABAP_TIMESTAMP_LENGTH && eightDigits.test(value));
89
+ }
90
+
91
+ function findDateSeparators(timestamp) {
92
+ var index = 0;
93
+ var separators = [];
94
+
95
+ while (separators.length < 2) {
96
+ var currentChar = timestamp[index];
97
+ // If the char at this position is separator
98
+ if (currentChar === '-' || currentChar === '/') {
99
+ separators.push(currentChar);
100
+ }
101
+ index++;
102
+ }
103
+ return separators;
104
+ }
105
+
106
+ function exchangeYearAndDate(separators, timestamp) {
107
+ var separatorIndexes = [timestamp.indexOf(separators[0]), timestamp.lastIndexOf(separators[1]) + 1];
108
+ var dateLastIndex = timestamp.split(' ')[0].split('T')[0].length;
109
+ var newTimestamp = timestamp;
110
+
111
+ var year = timestamp.slice(separatorIndexes[1], dateLastIndex);
112
+ if (year.length > 2) {
113
+ var month = timestamp.slice(separatorIndexes[0], separatorIndexes[1]);
114
+ var day = timestamp.slice(0, separatorIndexes[0]);
115
+ var restOfTheTimestamp = timestamp.slice(dateLastIndex);
116
+
117
+ newTimestamp = year + month + day + restOfTheTimestamp;
118
+ }
119
+ return newTimestamp;
120
+ }
121
+
122
+ function timestampIsMomentSpecific(timestamp) {
123
+ var momentSpecificCharacters = ['+', 'W', 'Z'];
124
+ var isMomentSpecific = false;
125
+ momentSpecificCharacters.forEach(function(character) {
126
+ if (timestamp.indexOf(character) > -1) {
127
+ isMomentSpecific = true;
128
+ }
129
+ });
130
+ return isMomentSpecific;
131
+ }
132
+
133
+ function zpad(n, digits) {
134
+ var s = n + '';
135
+ while (s.length < digits) {
136
+ s = '0' + s;
137
+ }
138
+ return s;
139
+ }
@@ -0,0 +1,192 @@
1
+ 'use strict';
2
+
3
+ var _ = require('lodash');
4
+ var util = require('util');
5
+ var Statement = require('./Statement');
6
+ var conversions = require('./conversions');
7
+
8
+ module.exports = CallableStatement;
9
+
10
+ util.inherits(CallableStatement, Statement);
11
+
12
+ function CallableStatement(statement) {
13
+ Statement.call(this, statement);
14
+ }
15
+
16
+ /**
17
+ * Returns an integer value of a TINYINT, SMALLINT, INT or BIGINT parameter types
18
+ * An exception will be thrown if the value is bigger than 9007199254740992 (2^53) or smaller than -9007199254740992 (-2^53).
19
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
20
+ * @returns {integer} Integer representation
21
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
22
+ */
23
+ CallableStatement.prototype.getInteger = function (columnIndex) {
24
+ return conversions.getInteger(getValue.call(this, columnIndex));
25
+ };
26
+
27
+ CallableStatement.prototype.getInt = CallableStatement.prototype.getInteger;
28
+
29
+ /**
30
+ * Returns an Int64 value of a BIGINT parameter
31
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
32
+ * @returns {ctypes.Int64} ctypes.Int64
33
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
34
+ */
35
+ CallableStatement.prototype.getBigInt = function (columnIndex) {
36
+ return conversions.getBigInt(getValue.call(this, columnIndex));
37
+ };
38
+
39
+ /**
40
+ * Returns a string value of a CHAR or VARCHAR parameter; ASCII only, not suitable for strings containing unicode characters.
41
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
42
+ * @returns {string} String representation
43
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
44
+ */
45
+ CallableStatement.prototype.getString = function (columnIndex) {
46
+ return conversions.getString(getValue.call(this, columnIndex),
47
+ this._parameterInfo[columnIndex - 1].nativeType);
48
+ };
49
+
50
+ /**
51
+ * Returns the string value of an NCHAR, an NVARCHAR, or a SHORTTEXT parameter
52
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
53
+ * @returns {string} String representation
54
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
55
+ */
56
+ CallableStatement.prototype.getNString = CallableStatement.prototype.getString;
57
+
58
+ /**
59
+ * Returns a number value of a DECIMAL parameter
60
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
61
+ * @returns {number} Number representation
62
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
63
+ */
64
+ CallableStatement.prototype.getDecimal = function (columnIndex) {
65
+ return conversions.getDecimal(getValue.call(this, columnIndex));
66
+ };
67
+
68
+ /**
69
+ * Returns a number value of the specified column. getReal is used for REAL column types.
70
+ * @param {integer} columnIndex The target column <b>starting from 1</b>
71
+ * @returns {number} Number representation
72
+ * @throws Throws an error if the index parameter is not valid.
73
+ */
74
+ CallableStatement.prototype.getReal = CallableStatement.prototype.getDecimal;
75
+
76
+ /**
77
+ * Returns a number value of the specified column. getFloat is used for FLOAT column types.
78
+ * @param {integer} columnIndex The target column <b>starting from 1</b>
79
+ * @returns {number} Number representation
80
+ * @throws Throws an error if the index parameter is not valid.
81
+ */
82
+ CallableStatement.prototype.getFloat = CallableStatement.prototype.getDecimal;
83
+
84
+ /**
85
+ * Returns a number value of a DOUBLE, FLOAT or REAL parameter
86
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
87
+ * @returns {number} Number representation
88
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
89
+ */
90
+ CallableStatement.prototype.getDouble = CallableStatement.prototype.getDecimal;
91
+
92
+ /**
93
+ * Returns the ArrayBuffer value of a BLOB specified parameter
94
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
95
+ * @returns {ArrayBuffer} Blob representation
96
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
97
+ */
98
+ CallableStatement.prototype.getBlob = function (columnIndex) {
99
+ return conversions.getBlob(getValue.call(this, columnIndex),
100
+ this._parameterInfo[columnIndex - 1].nativeType);
101
+ };
102
+
103
+ /**
104
+ * Returns an ArrayBuffer object of the specified column. getBString is used for BINARY and VARBINARY column types.
105
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
106
+ * @returns {ArrayBuffer} value ArrayBuffer object
107
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
108
+ */
109
+ CallableStatement.prototype.getBString = CallableStatement.prototype.getBlob;
110
+
111
+ /**
112
+ * Returns the string value of a CLOB parameter
113
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
114
+ * @returns {string} String representation
115
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
116
+ */
117
+ CallableStatement.prototype.getClob = function (columnIndex) {
118
+ return conversions.getClob(getValue.call(this, columnIndex),
119
+ this._parameterInfo[columnIndex - 1].nativeType);
120
+ };
121
+
122
+
123
+ /**
124
+ * Returns the string value of a NCLOB or TEXT parameter
125
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
126
+ * @returns {string} String representation
127
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
128
+ */
129
+ CallableStatement.prototype.getNClob = CallableStatement.prototype.getClob;
130
+
131
+ /**
132
+ * Returns the string value of a TEXT parameter
133
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
134
+ * @returns {string} String representation
135
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
136
+ */
137
+ CallableStatement.prototype.getText = CallableStatement.prototype.getClob;
138
+
139
+ /**
140
+ * Used to retrieve the value of a DATE parameter
141
+ * @param {integer} index The index of the parameter, <b>starting from 1</b>
142
+ * @returns {Date} A JavaScript date object representing the value
143
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
144
+ */
145
+ CallableStatement.prototype.getDate = function (columnIndex) {
146
+ return conversions.getDate(getValue.call(this, columnIndex));
147
+ };
148
+
149
+
150
+ /**
151
+ * Used to retrieve the value of a TIME parameter
152
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
153
+ * @returns {Date} A JavaScript date object representing the value
154
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
155
+ */
156
+ CallableStatement.prototype.getTime = function (columnIndex) {
157
+ return conversions.getTime(getValue.call(this, columnIndex));
158
+ };
159
+
160
+ /**
161
+ * Used to retrieve the value of a SECONDDATE parameter
162
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
163
+ * @returns {Date} A JavaScript date object representing the value
164
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
165
+ */
166
+ CallableStatement.prototype.getSeconddate = CallableStatement.prototype.getDate;
167
+
168
+ /**
169
+ * Used to retrieve the value of a TIMESTAMP parameter. <br>
170
+ * As this type contains only time information and no date, the JavaScript's date object will always be 1 Jan 1970 plus the time offset.<br>
171
+ * For example: if the stored value is 10:00:00, the JavaScript date object will specify: 1 Jan 1970 10:00:00
172
+ *
173
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
174
+ * @returns {Date} A JavaScript date object representing the value
175
+ * @throws Throws an error if the index parameter is not valid or the SQL type of the queried parameter does not match.
176
+ */
177
+ CallableStatement.prototype.getTimestamp = CallableStatement.prototype.getDate;
178
+
179
+ function getValue(columnIndex) {
180
+ if (!this._results) {
181
+ throw new Error('Callable statement not executed');
182
+ }
183
+ if (!_.isNumber(columnIndex)) {
184
+ throw new Error('Index should be a number');
185
+ }
186
+ const paramLength = this._results.parameters.length;
187
+ if (columnIndex < 1 || columnIndex > paramLength) {
188
+ throw new Error(`Index should be within 1 - ${paramLength}`);
189
+ }
190
+ return this._results.parameters[columnIndex - 1];
191
+ }
192
+
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ var assert = require('assert');
4
+ var PreparedStatement = require('./PreparedStatement');
5
+ var CallableStatement = require('./CallableStatement');
6
+
7
+ exports = module.exports = Connection;
8
+
9
+ function Connection(client) {
10
+ assert(typeof client === 'object', 'Valid hdb.client should be provided to create $.db.Connection');
11
+ this._client = client;
12
+ }
13
+
14
+ /**
15
+ * Prepares a statement for execution
16
+ * @param {string} statement The SQL statement to be prepared
17
+ * @returns {PreparedStatement} PreparedStatement object that represents the prepared statement
18
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.`
19
+ */
20
+ Connection.prototype.prepareStatement = async function (statement) {
21
+ return new PreparedStatement(await this._client.prepare(statement));
22
+ };
23
+
24
+ /**
25
+ * Prepares a stored procedure for execution
26
+ *
27
+ * @example
28
+ * var myCallableStatement = myconnection.prepareCall("{call myprocedure(?)}");
29
+ *
30
+ * @param {string} statement The SQL statement to be prepared
31
+ * @returns {CallableStatement} CallableStatement The object used to represent the callable statement
32
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
33
+ */
34
+ Connection.prototype.prepareCall = async function (statement) {
35
+ return new CallableStatement(await this._client.prepare(statement));
36
+ };
37
+
38
+ /**
39
+ * Changes the auto-commit flag of the connection
40
+ * @param {integer} enable An integer value, which can be either 0 (false) or 1 (true)
41
+ * @throws Throws an error if the object the method is being called on is not valid.
42
+ */
43
+ Connection.prototype.setAutoCommit = function (enable) {
44
+ this._client.setAutoCommit(enable);
45
+ };
46
+
47
+ /**
48
+ * Commits the changes.
49
+ * @throws Throws an error if the object the method is being called on is not valid.
50
+ */
51
+ Connection.prototype.commit = async function () {
52
+ await this._client.commit();
53
+ };
54
+
55
+ /**
56
+ * Rolls back the changes.
57
+ * @throws Throws an error if the object the method is being called on is not valid.
58
+ */
59
+ Connection.prototype.rollback = async function () {
60
+ await this._client.rollback();
61
+ };
62
+
63
+ /**
64
+ * Closes the connection.
65
+ * @throws Throws an error if the object the method is being called on is not valid.
66
+ */
67
+ Connection.prototype.close = async function () {
68
+ await this._client.close();
69
+ };
70
+
71
+ /**
72
+ * Checks if the connection is closed.
73
+ * @returns {boolean} Returns true if the connection is already closed, false if not
74
+ * @throws Throws an error if the object the method is being called on is not valid.
75
+ */
76
+ Connection.prototype.isClosed = function () {
77
+ return this._client.state() === 'disconnected';
78
+ };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+ var ResultSet = require('./ResultSet');
5
+ var Connection = require('./Connection');
6
+ var ResultSetMetaData = require('./ResultSetMetaData');
7
+ var DbBase = require('../common/DbBase');
8
+
9
+ module.exports = DB;
10
+
11
+ function DB(dbReqOptions) {
12
+
13
+ DbBase.call(this, dbReqOptions);
14
+
15
+ this.ResultSet = ResultSet.prototype;
16
+ this.ResultSetMetaData = ResultSetMetaData.prototype;
17
+ this.getConnection = async function (arg, isolationLevel) {
18
+ var userOptions;
19
+ switch (typeof arg) {
20
+ case 'undefined':
21
+ userOptions = { isolationLevel: isolationLevel };
22
+ break;
23
+ case 'number':
24
+ userOptions = { isolationLevel: arg };
25
+ break;
26
+ case 'string':
27
+ userOptions = { sqlcc: arg, isolationLevel: isolationLevel };
28
+ break;
29
+ case 'object':
30
+ userOptions = arg || {};
31
+ break;
32
+ default:
33
+ throw new TypeError('Invalid parameters for "$.db.getConnection", check function signature in the documentation');
34
+ }
35
+ return new Connection(await this._getClient(userOptions));
36
+ };
37
+ }
38
+
39
+ util.inherits(DB, DbBase);
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ var enums = require('../common/enums');
4
+ var TypeCode = require('@sap/hana-client/extension/TypeCode');
5
+ var isString = require('lodash').isString;
6
+
7
+ module.exports = ParameterMetaData;
8
+
9
+ function ParameterMetaData(parameters) {
10
+ this._parameters = parameters;
11
+ }
12
+
13
+ /**
14
+ * Returns the number of the parameters in the prepared statement
15
+ * @returns {integer} The number of the parameters in the prepared statement
16
+ * @throws Throws an error if the object the method is being called on is not valid.
17
+ */
18
+ ParameterMetaData.prototype.getParameterCount = function () {
19
+ return this._parameters.length;
20
+ };
21
+
22
+ /**
23
+ * Returns the name of the specified parameter
24
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
25
+ * @returns {string} The name of the specified parameter
26
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
27
+ */
28
+ ParameterMetaData.prototype.getParameterName = function (columnIndex) {
29
+ return this._parameters[columnIndex - 1].name;
30
+ };
31
+
32
+ /**
33
+ * Returns the mode of the specified parameter
34
+ * @todo provide an enumeration
35
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
36
+ * @returns {integer} The mode of the specified parameter
37
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
38
+ */
39
+ ParameterMetaData.prototype.getParameterMode = function (columnIndex) {
40
+ return enums.convert.toXscParameterMode(this._parameters[columnIndex - 1].direction);
41
+ };
42
+
43
+ /**
44
+ * Returns the type (db.types) of the specified parameter
45
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
46
+ * @returns {db.types} The type
47
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
48
+ * @see types
49
+ */
50
+ ParameterMetaData.prototype.getParameterType = function (columnIndex) {
51
+ return enums.convert.toXscType(this._parameters[columnIndex - 1].nativeType);
52
+ };
53
+
54
+ /**
55
+ * Returns the typename of the specified parameter
56
+ * @param {integer} columnIndex is the index of the parameter in the prepared statement <b>starting from 1</b>
57
+ * @returns {string} The typename of the specified parameter
58
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
59
+ */
60
+ ParameterMetaData.prototype.getParameterTypeName = function (columnIndex) {
61
+ var nativeTypeName = this._parameters[columnIndex - 1].nativeTypeName;
62
+
63
+ if (!isString(nativeTypeName)) {
64
+ nativeTypeName = Object.keys(TypeCode).find(key => TypeCode[key] === nativeTypeName);
65
+ }
66
+
67
+ return enums.convert.toXscTypeName(nativeTypeName);
68
+ };
69
+
70
+ /**
71
+ * Returns the designated parameter's number of decimal digits
72
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
73
+ * @returns {string} The designated parameter's number of decimal digits
74
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
75
+ */
76
+ ParameterMetaData.prototype.getPrecision = function (columnIndex) {
77
+ return this._parameters[columnIndex - 1].precision;
78
+ };
79
+
80
+ /**
81
+ * Returns the designated parameter's scale
82
+ * @param {integer} columnIndex The index of the parameter in the prepared statement <b>starting from 1</b>
83
+ * @returns {string} The designated parameter's scale
84
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
85
+ */
86
+ ParameterMetaData.prototype.getScale = function (columnIndex) {
87
+ return this._parameters[columnIndex - 1].scale;
88
+ };
89
+
90
+ /**
91
+ * Checks if the specified parameter is nullable
92
+ * @param {integer} index The index of the parameter, <b>starting from 1</b>
93
+ * @returns {integer} 1: true, 0: false
94
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
95
+ */
96
+ ParameterMetaData.prototype.isNullable = function (index) { // eslint-disable-line no-unused-vars
97
+ throw new Error('Not implemented yet');
98
+ };
99
+
100
+ /**
101
+ * Checks if the specified parameter is signed
102
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
103
+ * @returns {integer} 1: true, 0: false
104
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
105
+ */
106
+ ParameterMetaData.prototype.isSigned = function (index) { // eslint-disable-line no-unused-vars
107
+ throw new Error('Not implemented yet');
108
+ };
109
+
110
+ /**
111
+ * Checks if the specified parameter has a default value
112
+ * @param {integer} index The index of the parameter <b>starting from 1</b>
113
+ * @returns {integer} 1: true, 0: false
114
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
115
+ */
116
+ ParameterMetaData.prototype.hasDefault = function (index) { // eslint-disable-line no-unused-vars
117
+ throw new Error('Not implemented yet');
118
+ };
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+ var Statement = require('./Statement');
5
+ var ResultSetMetaData = require('./ResultSetMetaData');
6
+ var executeBatchPromise = require('../common/execute-batch').executeBatchPromise;
7
+
8
+ module.exports = PreparedStatement;
9
+
10
+ util.inherits(PreparedStatement, Statement);
11
+
12
+ function PreparedStatement(statement) {
13
+ Statement.call(this, statement);
14
+ this._batchParameters = [];
15
+ }
16
+
17
+ /**
18
+ * Executes an SQL statement
19
+ * @returns {db.ResultSet} ResultSet Holds the result of the executed SQL statement
20
+ * @throws Throws an error if the object the method is being called on is not valid.
21
+ */
22
+ PreparedStatement.prototype.executeQuery = async function () {
23
+ await this.execute();
24
+ return this.getResultSet();
25
+ };
26
+
27
+ /**
28
+ * Executes an update statement
29
+ * @returns {integer} The number of changed rows resulting from the update statement
30
+ * @throws Throws an error if the object the method is being called on is not valid.
31
+ */
32
+ PreparedStatement.prototype.executeUpdate = async function () {
33
+ await this.execute();
34
+ return this._results.rowsAffected;
35
+ };
36
+
37
+
38
+ /**
39
+ * Reserves space for batch insertion
40
+ * @param {integer} size The number (count) of batch insertions that will be performed
41
+ * @throws Throws an error on invalid parameters or if the object the method is being called on is not valid.
42
+ */
43
+ PreparedStatement.prototype.setBatchSize = function (size) { // eslint-disable-line no-unused-vars
44
+
45
+ };
46
+
47
+
48
+ /**
49
+ * Adds last parameter values and iterates to the next batch slot
50
+ * @throws Throws an error if the statement if setBatchSize has not been called successfully or if the object the method is being called on is not valid.
51
+ */
52
+ PreparedStatement.prototype.addBatch = function () {
53
+ this._batchParameters.push(this._parameters);
54
+ this._parameters = [];
55
+ };
56
+
57
+
58
+ /**
59
+ * Executes a batch insertion. Use setBatchSize and addBatch to prepare for batch execution.
60
+ * @returns {array} Array with integers representing the number of updated rows per batch
61
+ * @throws Throws an error if the object the method is being called on is not valid.
62
+ */
63
+ PreparedStatement.prototype.executeBatch = async function () {
64
+ var result = await executeBatchPromise.call(null, this._statement, this._batchParameters);
65
+ this._batchParameters = [];
66
+ return result;
67
+ };
68
+
69
+
70
+ /**
71
+ * Returns the metadata of the ResultSet
72
+ * @returns {db.ResultSetMetaData} ResultSetMetaData object
73
+ * @deprecated Use getMetaData on ResultSet.
74
+ * @see ResultSet#getMetaData
75
+ */
76
+ PreparedStatement.prototype.getMetaData = function () {
77
+ return new ResultSetMetaData(this._statement.getColumnInfo());
78
+ };