stimulsoft-data-adapter 2021.3.7 → 2021.4.4

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/MySQLAdapter.js CHANGED
@@ -1,202 +1,208 @@
1
- exports.process = function (command, onResult) {
2
-
3
- var end = function (result) {
4
- try {
5
- if (connection) {
6
- connection.end();
7
- }
8
- onResult(result);
9
- }
10
- catch (e) {
11
- }
12
- }
13
-
14
- var onError = function (message) {
15
- end({ success: false, notice: message });
16
- }
17
-
18
- try {
19
- var connect = function () {
20
- connection.connect(function (error) {
21
- if (error) onError(error.message);
22
- else onConnect();
23
- });
24
- }
25
-
26
- var query = function (queryString, timeout) {
27
- connection.query("USE " + command.connectionStringInfo.database);
28
- //queryString = queryString.replace(/\'/gi, "\"");
29
- connection.query({ sql: queryString, timeout: timeout }, function (error, rows, fields) {
30
- if (error) onError(error.message);
31
- else {
32
- onQuery(rows, fields);
33
- }
34
- });
35
- }
36
-
37
- var onConnect = function () {
38
- if (command.queryString) query(command.queryString, command.timeout);
39
- else end({ success: true });
40
- }
41
-
42
- var onQuery = function (recordset, fields) {
43
- var columns = [];
44
- var rows = [];
45
- var types = [];
46
- if (fields.length > 0 && Array.isArray(fields[0])) fields = fields[0];
47
-
48
- for (var columnIndex in fields) {
49
- var column = fields[columnIndex]
50
- columns.push(column.name);
51
-
52
- switch (column.type) {
53
- case 16: // Bit
54
- types[columnIndex] = "boolean"; break;
55
-
56
- case 1: // Byte
57
- case 2: // Int16
58
- case 3: // Int32
59
- case 5: // Double
60
- case 8: // Int64
61
- case 9: // Int24
62
- case 13: // Year
63
- case 501: // UByte
64
- case 502: // UInt16
65
- case 503: // UInt32
66
- case 508: // UInt64
67
- case 509: // UInt24
68
- types[columnIndex] = "int"; break;
69
-
70
- case 0: // Decimal
71
- case 4: // Float
72
- case 246: // NewDecimal
73
- types[columnIndex] = "number"; break;
74
-
75
- case 7: // Timestamp
76
- case 10: // Date
77
- case 12: // DateTime
78
- case 14: // Newdate
79
- types[columnIndex] = "datetime"; break;
80
-
81
- case 11: // Time
82
- types[columnIndex] = "time"; break;
83
-
84
- case 15: // VarString
85
- case 247: // Enum
86
- case 248: // Set
87
- case 249: // TinyBlob
88
- case 250: // MediumBlob
89
- case 251: // LongBlob
90
- case 252: // Blob
91
- case 253: // VarChar
92
- case 254: // String
93
- case 255: // Geometry
94
- case 600: // Binary
95
- case 601: // VarBinary
96
- case 749: // TinyText
97
- case 750: // MediumText
98
- case 751: // LongText
99
- case 752: // Text
100
- case 800: // Guid
101
-
102
- default:
103
- types[columnIndex] = "string"; break;
104
- }
105
- }
106
-
107
- if (recordset.length > 0 && Array.isArray(recordset[0])) recordset = recordset[0];
108
- for (var recordIndex in recordset) {
109
- var row = [];
110
- for (var columnName in recordset[recordIndex]) {
111
- var columnIndex = columns.indexOf(columnName);
112
- if (recordset[recordIndex][columnName] instanceof Uint8Array ||
113
- recordset[recordIndex][columnName] instanceof Buffer) {
114
- types[columnIndex] = "array";
115
- recordset[recordIndex][columnName] = Buffer.from(recordset[recordIndex][columnName]).toString('base64');
116
- }
117
-
118
- if (recordset[recordIndex][columnName] != null && typeof recordset[recordIndex][columnName].toISOString === "function") {
119
- var dateTime = new Date(recordset[recordIndex][columnName].getTime() - (recordset[recordIndex][columnName].getTimezoneOffset() * 60000)).toISOString();
120
- recordset[recordIndex][columnName] = dateTime.replace("Z", "");
121
- types[columnIndex] = "datetime";
122
- }
123
-
124
- row[columnIndex] = recordset[recordIndex][columnName];
125
- }
126
- rows.push(row);
127
- }
128
-
129
- end({ success: true, columns: columns, rows: rows, types: types });
130
- }
131
-
132
- var getConnectionStringInfo = function (connectionString) {
133
- var info = { host: "localhost", port: "3306", charset: "utf8" };
134
-
135
- for (var propertyIndex in connectionString.split(";")) {
136
- var property = connectionString.split(";")[propertyIndex];
137
- if (property) {
138
- var match = property.split("=");
139
- if (match && match.length >= 2) {
140
- match[0] = match[0].trim().toLowerCase();
141
- match[1] = match[1].trim();
142
-
143
- switch (match[0]) {
144
- case "server":
145
- case "host":
146
- case "location":
147
- info["host"] = match[1];
148
- break;
149
-
150
- case "port":
151
- info["port"] = match[1];
152
- break;
153
-
154
- case "database":
155
- case "data source":
156
- info["database"] = match[1];
157
- break;
158
-
159
- case "uid":
160
- case "user":
161
- case "username":
162
- case "userid":
163
- case "user id":
164
- info["userId"] = match[1];
165
- break;
166
-
167
- case "pwd":
168
- case "password":
169
- info["password"] = match[1];
170
- break;
171
-
172
- case "charset":
173
- info["charset"] = match[1];
174
- break;
175
- }
176
- }
177
- }
178
- }
179
-
180
- return info;
181
- };
182
-
183
- var mysql = require('mysql');
184
- command.connectionStringInfo = getConnectionStringInfo(command.connectionString);
185
-
186
- var connection = mysql.createConnection({
187
- host: command.connectionStringInfo.host,
188
- user: command.connectionStringInfo.userId,
189
- password: command.connectionStringInfo.password,
190
- port: command.connectionStringInfo.port,
191
- charset: command.connectionStringInfo.charset,
192
- database: command.connectionStringInfo.database
193
- });
194
-
195
- connect();
196
-
197
-
198
- }
199
- catch (e) {
200
- onError(e.stack);
201
- }
1
+ /*
2
+ Stimulsoft.Reports.JS
3
+ Version: 2021.4.4
4
+ Build date: 2021.11.18
5
+ License: https://www.stimulsoft.com/en/licensing/reports
6
+ */
7
+ exports.process = function (command, onResult) {
8
+ var end = function (result) {
9
+ try {
10
+ if (connection) {
11
+ connection.end();
12
+ }
13
+ result.adapterVersion = "2021.4.4";
14
+ onResult(result);
15
+ }
16
+ catch (e) {
17
+ }
18
+ }
19
+
20
+ var onError = function (message) {
21
+ end({ success: false, notice: message });
22
+ }
23
+
24
+ try {
25
+ var connect = function () {
26
+ connection.connect(function (error) {
27
+ if (error) onError(error.message);
28
+ else onConnect();
29
+ });
30
+ }
31
+
32
+ var query = function (queryString, timeout) {
33
+ connection.query("USE " + command.connectionStringInfo.database);
34
+ //queryString = queryString.replace(/\'/gi, "\"");
35
+ connection.query({ sql: queryString, timeout: timeout }, function (error, rows, fields) {
36
+ if (error) onError(error.message);
37
+ else {
38
+ onQuery(rows, fields);
39
+ }
40
+ });
41
+ }
42
+
43
+ var onConnect = function () {
44
+ if (command.queryString) query(command.queryString, command.timeout);
45
+ else end({ success: true });
46
+ }
47
+
48
+ var onQuery = function (recordset, fields) {
49
+ var columns = [];
50
+ var rows = [];
51
+ var types = [];
52
+ if (fields.length > 0 && Array.isArray(fields[0])) fields = fields[0];
53
+
54
+ for (var columnIndex in fields) {
55
+ var column = fields[columnIndex]
56
+ columns.push(column.name);
57
+
58
+ switch (column.type) {
59
+ case 16: // Bit
60
+ types[columnIndex] = "boolean"; break;
61
+
62
+ case 1: // Byte
63
+ case 2: // Int16
64
+ case 3: // Int32
65
+ case 5: // Double
66
+ case 8: // Int64
67
+ case 9: // Int24
68
+ case 13: // Year
69
+ case 501: // UByte
70
+ case 502: // UInt16
71
+ case 503: // UInt32
72
+ case 508: // UInt64
73
+ case 509: // UInt24
74
+ types[columnIndex] = "int"; break;
75
+
76
+ case 0: // Decimal
77
+ case 4: // Float
78
+ case 246: // NewDecimal
79
+ types[columnIndex] = "number"; break;
80
+
81
+ case 7: // Timestamp
82
+ case 10: // Date
83
+ case 12: // DateTime
84
+ case 14: // Newdate
85
+ types[columnIndex] = "datetime"; break;
86
+
87
+ case 11: // Time
88
+ types[columnIndex] = "time"; break;
89
+
90
+ case 15: // VarString
91
+ case 247: // Enum
92
+ case 248: // Set
93
+ case 249: // TinyBlob
94
+ case 250: // MediumBlob
95
+ case 251: // LongBlob
96
+ case 252: // Blob
97
+ case 253: // VarChar
98
+ case 254: // String
99
+ case 255: // Geometry
100
+ case 600: // Binary
101
+ case 601: // VarBinary
102
+ case 749: // TinyText
103
+ case 750: // MediumText
104
+ case 751: // LongText
105
+ case 752: // Text
106
+ case 800: // Guid
107
+
108
+ default:
109
+ types[columnIndex] = "string"; break;
110
+ }
111
+ }
112
+
113
+ if (recordset.length > 0 && Array.isArray(recordset[0])) recordset = recordset[0];
114
+ for (var recordIndex in recordset) {
115
+ var row = [];
116
+ for (var columnName in recordset[recordIndex]) {
117
+ var columnIndex = columns.indexOf(columnName);
118
+ if (recordset[recordIndex][columnName] instanceof Uint8Array ||
119
+ recordset[recordIndex][columnName] instanceof Buffer) {
120
+ types[columnIndex] = "array";
121
+ recordset[recordIndex][columnName] = Buffer.from(recordset[recordIndex][columnName]).toString('base64');
122
+ }
123
+
124
+ if (recordset[recordIndex][columnName] != null && typeof recordset[recordIndex][columnName].toISOString === "function") {
125
+ var dateTime = new Date(recordset[recordIndex][columnName].getTime() - (recordset[recordIndex][columnName].getTimezoneOffset() * 60000)).toISOString();
126
+ recordset[recordIndex][columnName] = dateTime.replace("Z", "");
127
+ types[columnIndex] = "datetime";
128
+ }
129
+
130
+ row[columnIndex] = recordset[recordIndex][columnName];
131
+ }
132
+ rows.push(row);
133
+ }
134
+
135
+ end({ success: true, columns: columns, rows: rows, types: types });
136
+ }
137
+
138
+ var getConnectionStringInfo = function (connectionString) {
139
+ var info = { host: "localhost", port: "3306", charset: "utf8" };
140
+
141
+ for (var propertyIndex in connectionString.split(";")) {
142
+ var property = connectionString.split(";")[propertyIndex];
143
+ if (property) {
144
+ var match = property.split("=");
145
+ if (match && match.length >= 2) {
146
+ match[0] = match[0].trim().toLowerCase();
147
+ match[1] = match[1].trim();
148
+
149
+ switch (match[0]) {
150
+ case "server":
151
+ case "host":
152
+ case "location":
153
+ info["host"] = match[1];
154
+ break;
155
+
156
+ case "port":
157
+ info["port"] = match[1];
158
+ break;
159
+
160
+ case "database":
161
+ case "data source":
162
+ info["database"] = match[1];
163
+ break;
164
+
165
+ case "uid":
166
+ case "user":
167
+ case "username":
168
+ case "userid":
169
+ case "user id":
170
+ info["userId"] = match[1];
171
+ break;
172
+
173
+ case "pwd":
174
+ case "password":
175
+ info["password"] = match[1];
176
+ break;
177
+
178
+ case "charset":
179
+ info["charset"] = match[1];
180
+ break;
181
+ }
182
+ }
183
+ }
184
+ }
185
+
186
+ return info;
187
+ };
188
+
189
+ var mysql = require('mysql');
190
+ command.connectionStringInfo = getConnectionStringInfo(command.connectionString);
191
+
192
+ var connection = mysql.createConnection({
193
+ host: command.connectionStringInfo.host,
194
+ user: command.connectionStringInfo.userId,
195
+ password: command.connectionStringInfo.password,
196
+ port: command.connectionStringInfo.port,
197
+ charset: command.connectionStringInfo.charset,
198
+ database: command.connectionStringInfo.database
199
+ });
200
+
201
+ connect();
202
+
203
+
204
+ }
205
+ catch (e) {
206
+ onError(e.stack);
207
+ }
202
208
  }