stimulsoft-data-adapter 2023.3.3 → 2023.4.1

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.
@@ -1,14 +1,14 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2023.3.3
4
- Build date: 2023.08.23
3
+ Version: 2023.4.1
4
+ Build date: 2023.10.06
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
  exports.process = function (command, onResult) {
8
8
  var end = function (result) {
9
9
  try {
10
10
  if (db) db.detach();
11
- result.adapterVersion = "2023.3.3";
11
+ result.adapterVersion = "2023.4.1";
12
12
  onResult(result);
13
13
  }
14
14
  catch (e) {
package/MSSQLAdapter.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2023.3.3
4
- Build date: 2023.08.23
3
+ Version: 2023.4.1
4
+ Build date: 2023.10.06
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
  exports.process = function (command, onResult) {
8
8
  var end = function (result) {
9
9
  try {
10
10
  if (connection) connection.close();
11
- result.adapterVersion = "2023.3.3";
11
+ result.adapterVersion = "2023.4.1";
12
12
  onResult(result);
13
13
  }
14
14
  catch (e) {
package/MySQLAdapter.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2023.3.3
4
- Build date: 2023.08.23
3
+ Version: 2023.4.1
4
+ Build date: 2023.10.06
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
  exports.process = function (command, onResult) {
@@ -13,7 +13,7 @@ exports.process = function (command, onResult) {
13
13
  catch (e) {
14
14
  }
15
15
  finally {
16
- result.adapterVersion = "2023.3.3";
16
+ result.adapterVersion = "2023.4.1";
17
17
  onResult(result);
18
18
  }
19
19
  }
@@ -0,0 +1,210 @@
1
+ /*
2
+ Stimulsoft.Reports.JS
3
+ Version: 2023.3.3
4
+ Build date: 2023.08.23
5
+ License: https://www.stimulsoft.com/en/licensing/reports
6
+ */
7
+ exports.process = function (command, onResult) {
8
+ var end = function (result) {
9
+ result.adapterVersion = "2023.3.3";
10
+ onResult(result);
11
+ }
12
+
13
+ var onError = function (message) {
14
+ end({ success: false, notice: message });
15
+ }
16
+
17
+ try {
18
+ var connect = function (error, connection) {
19
+ if (error) onError(error.message);
20
+ else onConnect(connection);
21
+ }
22
+
23
+ var onConnect = function (connection) {
24
+ if (command.queryString) {
25
+ if (command.command == "Execute")
26
+ command.queryString = "BEGIN " + command.queryString + "(" + command.parameters.map(parameter => "@" + parameter.name).join(", ") + "); END;";
27
+
28
+ var { queryString, parameters } = applyQueryParameters(command.queryString, command.parameters, command.escapeQueryParameters);
29
+ query(connection, queryString, parameters);
30
+ }
31
+ else end({ success: true });
32
+ }
33
+
34
+ var query = function (connection, queryString, parameters) {
35
+ var args = [queryString];
36
+ if (parameters) args.push(parameters);
37
+
38
+ connection.execute(...args, function (error, result) {
39
+ if (error) onError(error.message);
40
+ else {
41
+ onQuery(result);
42
+ }
43
+ });
44
+ }
45
+
46
+ var onQuery = function (result) {
47
+ var columns = [];
48
+ var rows = [];
49
+ var types = [];
50
+
51
+ for (var column of result.metaData) {
52
+ columns.push(column.name);
53
+
54
+ switch (column.dbTypeName) {
55
+ case "BFILE":
56
+ case "BLOB":
57
+ case "LONGRAW":
58
+ case "RAW":
59
+ types.push("array"); break;
60
+
61
+ case "DATE":
62
+ case "TIMESTAMP":
63
+ case "TIMESTAMPWITHLOCALTIMEZONE":
64
+ case "TIMESTAMPWITHTIMEZONE":
65
+ types.push("datetime"); break;
66
+
67
+ case "INTERVALDAYTOSECOND":
68
+ types.push("time"); break;
69
+
70
+ case "INTERVALYEARTOMONTH":
71
+ types.push("int"); break;
72
+
73
+ case "NUMBER":
74
+ case "BINARY_DOUBLE":
75
+ case "BINARY_FLOAT":
76
+ case "BINARY_INTEGER":
77
+ types.push("number"); break;
78
+
79
+ default:
80
+ types.push("string"); break;
81
+ }
82
+ }
83
+
84
+ for (var record of result.rows) {
85
+ var row = [];
86
+
87
+ for (var columnIndex in record) {
88
+ var value = record[columnIndex];
89
+ if (value instanceof Uint8Array) value = Buffer.from(result.rows[recordIndex][columnIndex]).toString('base64');
90
+ if (value instanceof Date) value = date.toISOString();
91
+
92
+ row.push(value);
93
+ }
94
+
95
+ rows.push(row);
96
+ }
97
+
98
+ end({ success: true, columns: columns, rows: rows, types: types });
99
+ }
100
+
101
+ var getConnectionStringInfo = function (connectionString) {
102
+ var info = { database: "", userId: "", password: "", charset: "AL32UTF8", privilege: "" };
103
+
104
+
105
+ for (var propertyIndex in connectionString.split(";")) {
106
+ var property = connectionString.split(";")[propertyIndex];
107
+ if (property) {
108
+ var match = property.split("=");
109
+ if (match && match.length >= 2) {
110
+ match[0] = match[0].trim().toLowerCase();
111
+ match[1] = match[1].trim();
112
+
113
+ switch (match[0]) {
114
+ case "database":
115
+ case "data source":
116
+ info["database"] = match.splice(1, match.length).join("=");
117
+ break;
118
+
119
+ case "uid":
120
+ case "user":
121
+ case "user id":
122
+ info["userId"] = match[1];
123
+ break;
124
+
125
+ case "pwd":
126
+ case "password":
127
+ info["password"] = match[1];
128
+ break;
129
+
130
+ case "charset":
131
+ info["charset"] = match[1];
132
+ break;
133
+
134
+ case "dba privilege":
135
+ case "privilege":
136
+ var value = match[1].toLowerCase();
137
+ info["privilege"] = "OCI_DEFAULT";
138
+ if (value == "sysoper" || value == "oci_sysoper") info["privilege"] = "OCI_SYSOPER";
139
+ if (value == "sysdba" || value == "oci_sysdba") info["privilege"] = "OCI_SYSDBA";
140
+ break;
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ return info;
147
+ };
148
+
149
+ var applyQueryParameters = function (baseSqlCommand, baseParameters, escapeQueryParameters) {
150
+ var parameters = null;
151
+ var result = "";
152
+
153
+ if (baseSqlCommand != null && baseSqlCommand.indexOf("@") > -1) {
154
+ while (baseSqlCommand.indexOf("@") >= 0 && baseParameters != null && baseParameters.length > 0) {
155
+ result += baseSqlCommand.substring(0, baseSqlCommand.indexOf("@"));
156
+ baseSqlCommand = baseSqlCommand.substring(baseSqlCommand.indexOf("@") + 1);
157
+
158
+ var parameterName = "";
159
+
160
+ while (baseSqlCommand.length > 0) {
161
+ var char = baseSqlCommand.charAt(0);
162
+ if (char.length === 1 && char.match(/[a-zA-Z0-9_-]/i)) {
163
+ parameterName += char;
164
+ baseSqlCommand = baseSqlCommand.substring(1);
165
+ }
166
+ else break;
167
+ }
168
+
169
+ var parameter = baseParameters.find(parameter => parameter.name.toLowerCase() == parameterName.toLowerCase());
170
+ if (parameter) {
171
+ if (parameter.index == null) {
172
+ var parameterValue = parameter.value;
173
+ if (parameter.typeGroup == "number") parameterValue = +parameter.value;
174
+ else if (parameter.typeGroup == "datetime") parameterValue = new Date(parameter.value);
175
+ if (parameters == null) parameter = {};
176
+ parameters[parameter.name] = parameterValue;
177
+ }
178
+ result += ':' + parameter.name;
179
+ }
180
+ else
181
+ result += "@" + parameterName;
182
+ }
183
+ }
184
+
185
+ return { queryString: result + baseSqlCommand, parameters };
186
+ }
187
+
188
+ command.connectionStringInfo = getConnectionStringInfo(command.connectionString);
189
+ var oracledb = require('oracledb');
190
+ try {
191
+ oracledb.initOracleClient();
192
+ }
193
+ catch (e) {
194
+ var utils = require("oracledb/lib/thin/util.js");
195
+ utils.CLIENT_INFO.program = utils.CLIENT_INFO.program.split("(").join("_").split(")").join("_");
196
+ }
197
+
198
+ var connection;
199
+
200
+ oracledb.getConnection({
201
+ user: command.connectionStringInfo.userId,
202
+ password: command.connectionStringInfo.password,
203
+ connectString: command.connectionStringInfo.database
204
+ }, connect);
205
+
206
+ }
207
+ catch (e) {
208
+ onError(e.stack);
209
+ }
210
+ }
@@ -1,14 +1,14 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2023.3.3
4
- Build date: 2023.08.23
3
+ Version: 2023.4.1
4
+ Build date: 2023.10.06
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
  exports.process = function (command, onResult) {
8
8
  var end = function (result) {
9
9
  try {
10
10
  if (client) client.end();
11
- result.adapterVersion = "2023.3.3";
11
+ result.adapterVersion = "2023.4.1";
12
12
  onResult(result);
13
13
  }
14
14
  catch (e) {
@@ -210,7 +210,7 @@ exports.process = function (command, onResult) {
210
210
  case "uid":
211
211
  case "user":
212
212
  case "user id":
213
- info["userId"] = match[1];
213
+ info["user"] = match[1];
214
214
  break;
215
215
 
216
216
  case "pwd":
@@ -272,15 +272,15 @@ exports.process = function (command, onResult) {
272
272
  }
273
273
 
274
274
  var pg = require('pg');
275
- if (command.connectionString.startsWith("postgres://")) command.postgreConnectionString = command.connectionString
275
+ if (command.connectionString.startsWith("postgres://")) {
276
+ var parse = require('pg-connection-string').parse;
277
+ command.connectionStringInfo = parse(command.connectionString);
278
+ }
276
279
  else {
277
280
  command.connectionStringInfo = getConnectionStringInfo(command.connectionString);
278
-
279
- command.postgreConnectionString = "postgres://" + command.connectionStringInfo.userId + ":" + command.connectionStringInfo.password + "@" + command.connectionStringInfo.host;
280
- if (command.connectionStringInfo.port != null) command.postgreConnectionString += ":" + command.connectionStringInfo.port;
281
- command.postgreConnectionString += "/" + command.connectionStringInfo.database;
282
281
  }
283
- var client = new pg.Client(command.postgreConnectionString);
282
+
283
+ var client = new pg.Client(command.connectionStringInfo);
284
284
 
285
285
  connect();
286
286
  }
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2023.3.3
4
- Build date: 2023.08.23
3
+ Version: 2023.4.1
4
+ Build date: 2023.10.06
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
 
@@ -25,9 +25,9 @@ function process(command, onResult) {
25
25
  var onProcessHandler = onProcess.bind(null, onResult, command.encryptResult);
26
26
 
27
27
  if (command.command === "GetSupportedAdapters") {
28
- onProcessHandler({ success: true, types: ["MySQL", "MS SQL", "Firebird", "PostgreSQL"] });
28
+ onProcessHandler({ success: true, types: ["MySQL", "MS SQL", "Firebird", "PostgreSQL", "MongoDB", "Oracle"] });
29
29
  } else {
30
- if (command.parameters){
30
+ if (command.parameters) {
31
31
  command.parameters.forEach(parameter => {
32
32
  if (parameter.name.length > 1 && parameter.name[0] == "@") parameter.name = parameter.name.substring(1);
33
33
  })
@@ -49,6 +49,14 @@ function process(command, onResult) {
49
49
  var PostgreSQLAdapter = require('./PostgreSQLAdapter');
50
50
  PostgreSQLAdapter.process(command, onProcessHandler);
51
51
  }
52
+ else if (command.database == "MongoDB") {
53
+ var MongoDBAdapter = require('./MongoDBAdapter');
54
+ MongoDBAdapter.process(command, onProcessHandler);
55
+ }
56
+ else if (command.database == "Oracle") {
57
+ var OracleAdapter = require('./OracleAdapter');
58
+ OracleAdapter.process(command, onProcessHandler);
59
+ }
52
60
  else onProcessHandler({ success: false, notice: "Database '" + command.database + "' not supported!" });
53
61
  }
54
62
  }
@@ -67,7 +75,7 @@ function getResponse(result) {
67
75
  return result
68
76
  }
69
77
  function onProcess(onResult, encryptData, result) {
70
- result.handlerVersion = "2023.3.3";
78
+ result.handlerVersion = "2023.4.1";
71
79
  result.checkVersion = true;
72
80
  result.encryptData = encryptData;
73
81
  onResult(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stimulsoft-data-adapter",
3
- "version": "2023.3.3",
3
+ "version": "2023.4.1",
4
4
  "description": "Nodejs data adapter for Stimulsoft Reports.JS",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,11 +11,13 @@
11
11
  "url": "https://github.com/stimulsoft/DataAdapters.JS/tree/main/NodejsDataAdapters"
12
12
  },
13
13
  "dependencies": {
14
+ "mongodb": "^6.1.0",
14
15
  "mssql": "^6.2.1",
15
- "mysql2": "^2.3.3",
16
- "node-firebird": "^0.9.8",
17
- "pg": "^8.3.3",
18
- "tzdata": "^1.0.25"
16
+ "mysql2": "^3.6.1",
17
+ "node-firebird": "^1.1.5",
18
+ "oracledb": "^6.1.0",
19
+ "pg": "^8.11.3",
20
+ "tzdata": "^1.0.38"
19
21
  },
20
22
  "files": [
21
23
  "package.json",
@@ -24,7 +26,8 @@
24
26
  "FirebirdAdapter.js",
25
27
  "MSSQLAdapter.js",
26
28
  "MySQLAdapter.js",
27
- "PostgreSQLAdapter.js"
29
+ "PostgreSQLAdapter.js",
30
+ "OracleAdapter.js"
28
31
  ],
29
32
  "author": {
30
33
  "name": "Stimulsoft",