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.
@@ -1,240 +1,246 @@
1
- exports.process = function (command, onResult) {
2
-
3
- var end = function (result) {
4
- try {
5
- if (client) client.end();
6
- onResult(result);
7
- }
8
- catch (e) {
9
- }
10
- }
11
-
12
- var onError = function (message) {
13
- end({ success: false, notice: message });
14
- }
15
-
16
- try {
17
- var connect = function () {
18
- client.connect(function (error) {
19
- if (error) onError(error.message);
20
- else onConnect();
21
- });
22
- }
23
-
24
- var query = function (queryString) {
25
- client.query(queryString, function (error, recordset) {
26
- if (error) onError(error.message);
27
- else {
28
- onQuery(recordset);
29
- }
30
- });
31
- }
32
-
33
- var onConnect = function () {
34
- if (command.queryString) query(command.queryString);
35
- else end({ success: true });
36
- }
37
-
38
- var onQuery = function (recordset) {
39
- var columns = [];
40
- var rows = [];
41
- var types = [];
42
-
43
- for (var columnIndex in recordset.fields) {
44
- var column = recordset.fields[columnIndex]
45
- columns.push(column.name);
46
-
47
- switch (column.dataTypeID) {
48
- case 16: // BOOL
49
- types[columnIndex] = "boolean"; break;
50
-
51
- case 20: // INT8
52
- case 21: // INT2
53
- case 23: // INT4
54
- types[columnIndex] = "int"; break;
55
-
56
- case 700: // FLOAT4
57
- case 701: // FLOAT8
58
- case 790: // MONEY
59
- types[columnIndex] = "number"; break;
60
-
61
- case 702: // ABSTIME
62
- case 1082: // DATE
63
- case 1114: // TIMESTAMP
64
- types[columnIndex] = "datetime"; break;
65
-
66
- case 1184: // TIMESTAMPTZ
67
- types[columnIndex] = "datetimeZ"; break;
68
-
69
- case 1083: // TIME
70
- types[columnIndex] = "time"; break;
71
-
72
- case 1266: // TIMETZ
73
- types[columnIndex] = "timeZ"; break;
74
-
75
- case 17: // BYTEA
76
- case 18: // CHAR
77
- case 19:
78
- case 24: // REGPROC
79
- case 25: // TEXT
80
- case 26: // OID
81
- case 27: // TID
82
- case 28: // XID
83
- case 29: // CID
84
- case 114: // JSON
85
- case 142: // XML
86
- case 194: // PG_NODE_TREE
87
- case 210: // SMGR
88
- case 602: // PATH
89
- case 604: // POLYGON
90
- case 650: // CIDR
91
- case 703: // RELTIME
92
- case 704: // TINTERVAL
93
- case 718: // CIRCLE
94
- case 774: // MACADDR8
95
- case 829: // MACADDR
96
- case 869: // INET
97
- case 1033: // ACLITEM
98
- case 1042: // BPCHAR
99
- case 1043: // VARCHAR
100
- case 1186: // INTERVAL
101
- case 1560: // BIT
102
- case 1562: // VARBIT
103
- case 1700: // NUMERIC
104
- case 1790: // REFCURSOR
105
- case 2202: // REGPROCEDURE
106
- case 2203: // REGOPER
107
- case 2204: // REGOPERATOR
108
- case 2205: // REGCLASS
109
- case 2206: // REGTYPE
110
- case 2950: // UUID
111
- case 2970: // TXID_SNAPSHOT
112
- case 3220: // PG_LSN
113
- case 3361: // PG_NDISTINCT
114
- case 3402: // PG_DEPENDENCIES
115
- case 3614: // TSVECTOR
116
- case 3615: // TSQUERY
117
- case 3642: // GTSVECTOR
118
- case 3734: // REGCONFIG
119
- case 3769: // REGDICTIONARY
120
- case 3802: // JSONB
121
- case 4089: // REGNAMESPACE
122
- case 4096: // REGROLE
123
- default:
124
- types[columnIndex] = "string"; break;
125
- }
126
- }
127
-
128
- if (recordset.rows.length > 0 && Array.isArray(recordset.rows[0])) recordset.rows = recordset.rows[0];
129
- for (var recordIndex in recordset.rows) {
130
- var row = [];
131
- for (var columnName in recordset.rows[recordIndex]) {
132
- var columnIndex = columns.indexOf(columnName);
133
- if (recordset.rows[recordIndex][columnName] instanceof Uint8Array) {
134
- types[columnIndex] = "array";
135
- recordset.rows[recordIndex][columnName] = Buffer.from(recordset.rows[recordIndex][columnName]).toString('base64');
136
- }
137
-
138
- if (recordset.rows[recordIndex][columnName] != null && typeof recordset.rows[recordIndex][columnName].toISOString === "function") {
139
- if (types[columnIndex] == "datetimeZ") {
140
- recordset.rows[recordIndex][columnName] = recordset.rows[recordIndex][columnName].toISOString();
141
- }
142
- else {
143
- var dateTime = new Date(recordset.rows[recordIndex][columnName].getTime() - (recordset.rows[recordIndex][columnName].getTimezoneOffset() * 60000)).toISOString();
144
- recordset.rows[recordIndex][columnName] = dateTime.replace("Z", "");
145
- types[columnIndex] = "datetime";
146
- }
147
- }
148
-
149
- if (types[columnIndex] == "timeZ") {
150
- var time = recordset.rows[recordIndex][columnName];
151
- var offset = time.substr(time.indexOf("+"));
152
- if (offset.indexOf(":") == -1) offset += ":00";
153
- time = time.substr(0, time.indexOf("+"));
154
- if (time.indexOf(".") == -1) time += ".000"
155
- recordset.rows[recordIndex][columnName] = "0001-01-01T" + time + offset;
156
- }
157
-
158
- row[columnIndex] = recordset.rows[recordIndex][columnName];
159
- }
160
- rows.push(row);
161
- }
162
-
163
- for (var typeIndex in types) {
164
- if (types[typeIndex] == "timeZ") types[typeIndex] = "datetimeoffset";
165
- if (types[typeIndex] == "datetimeZ") types[typeIndex] = "datetime";
166
- }
167
-
168
- end({ success: true, columns: columns, rows: rows, types: types });
169
- }
170
-
171
- var getConnectionStringInfo = function (connectionString) {
172
- var info = { port: 5432 };
173
-
174
- for (var propertyIndex in connectionString.split(";")) {
175
- var property = connectionString.split(";")[propertyIndex];
176
- if (property) {
177
- var match = property.split(new RegExp('=|:'));
178
- if (match && match.length >= 2) {
179
- match[0] = match[0].trim().toLowerCase();
180
- match[1] = match[1].trim();
181
-
182
- switch (match[0]) {
183
- case "data source":
184
- case "server":
185
- case "host":
186
- info["host"] = match[1];
187
- break;
188
-
189
- case "port":
190
- info["port"] = match[1];
191
- break;
192
-
193
- case "database":
194
- case "location":
195
- info["database"] = match[1];
196
- break;
197
-
198
- case "uid":
199
- case "user":
200
- case "user id":
201
- info["userId"] = match[1];
202
- break;
203
-
204
- case "pwd":
205
- case "password":
206
- info["password"] = match[1];
207
- break;
208
-
209
- case "ssl":
210
- info["ssl"] = match[1];
211
- break;
212
- case "sslmode":
213
- if (match[1] == "require") info["ssl"] = 1;
214
- else if (match[1] == "disable") info["ssl"] = 0;
215
- break;
216
- }
217
- }
218
- }
219
- }
220
-
221
- return info;
222
- };
223
-
224
- var pg = require('pg');
225
- if (command.connectionString.startsWith("postgres://")) command.postgreConnectionString = command.connectionString
226
- else {
227
- command.connectionStringInfo = getConnectionStringInfo(command.connectionString);
228
-
229
- command.postgreConnectionString = "postgres://" + command.connectionStringInfo.userId + ":" + command.connectionStringInfo.password + "@" + command.connectionStringInfo.host;
230
- if (command.connectionStringInfo.port != null) command.postgreConnectionString += ":" + command.connectionStringInfo.port;
231
- command.postgreConnectionString += "/" + command.connectionStringInfo.database;
232
- }
233
- var client = new pg.Client(command.postgreConnectionString);
234
-
235
- connect();
236
- }
237
- catch (e) {
238
- onError(e.stack);
239
- }
240
- }
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 (client) client.end();
11
+ result.adapterVersion = "2021.4.4";
12
+ onResult(result);
13
+ }
14
+ catch (e) {
15
+ }
16
+ }
17
+
18
+ var onError = function (message) {
19
+ end({ success: false, notice: message });
20
+ }
21
+
22
+ try {
23
+ var connect = function () {
24
+ client.connect(function (error) {
25
+ if (error) onError(error.message);
26
+ else onConnect();
27
+ });
28
+ }
29
+
30
+ var query = function (queryString) {
31
+ client.query(queryString, function (error, recordset) {
32
+ if (error) onError(error.message);
33
+ else {
34
+ onQuery(recordset);
35
+ }
36
+ });
37
+ }
38
+
39
+ var onConnect = function () {
40
+ if (command.queryString) query(command.queryString);
41
+ else end({ success: true });
42
+ }
43
+
44
+ var onQuery = function (recordset) {
45
+ var columns = [];
46
+ var rows = [];
47
+ var types = [];
48
+
49
+ for (var columnIndex in recordset.fields) {
50
+ var column = recordset.fields[columnIndex]
51
+ columns.push(column.name);
52
+
53
+ switch (column.dataTypeID) {
54
+ case 16: // BOOL
55
+ types[columnIndex] = "boolean"; break;
56
+
57
+ case 20: // INT8
58
+ case 21: // INT2
59
+ case 23: // INT4
60
+ types[columnIndex] = "int"; break;
61
+
62
+ case 700: // FLOAT4
63
+ case 701: // FLOAT8
64
+ case 790: // MONEY
65
+ types[columnIndex] = "number"; break;
66
+
67
+ case 702: // ABSTIME
68
+ case 1082: // DATE
69
+ case 1114: // TIMESTAMP
70
+ types[columnIndex] = "datetime"; break;
71
+
72
+ case 1184: // TIMESTAMPTZ
73
+ types[columnIndex] = "datetimeZ"; break;
74
+
75
+ case 1083: // TIME
76
+ types[columnIndex] = "time"; break;
77
+
78
+ case 1266: // TIMETZ
79
+ types[columnIndex] = "timeZ"; break;
80
+
81
+ case 17: // BYTEA
82
+ case 18: // CHAR
83
+ case 19:
84
+ case 24: // REGPROC
85
+ case 25: // TEXT
86
+ case 26: // OID
87
+ case 27: // TID
88
+ case 28: // XID
89
+ case 29: // CID
90
+ case 114: // JSON
91
+ case 142: // XML
92
+ case 194: // PG_NODE_TREE
93
+ case 210: // SMGR
94
+ case 602: // PATH
95
+ case 604: // POLYGON
96
+ case 650: // CIDR
97
+ case 703: // RELTIME
98
+ case 704: // TINTERVAL
99
+ case 718: // CIRCLE
100
+ case 774: // MACADDR8
101
+ case 829: // MACADDR
102
+ case 869: // INET
103
+ case 1033: // ACLITEM
104
+ case 1042: // BPCHAR
105
+ case 1043: // VARCHAR
106
+ case 1186: // INTERVAL
107
+ case 1560: // BIT
108
+ case 1562: // VARBIT
109
+ case 1700: // NUMERIC
110
+ case 1790: // REFCURSOR
111
+ case 2202: // REGPROCEDURE
112
+ case 2203: // REGOPER
113
+ case 2204: // REGOPERATOR
114
+ case 2205: // REGCLASS
115
+ case 2206: // REGTYPE
116
+ case 2950: // UUID
117
+ case 2970: // TXID_SNAPSHOT
118
+ case 3220: // PG_LSN
119
+ case 3361: // PG_NDISTINCT
120
+ case 3402: // PG_DEPENDENCIES
121
+ case 3614: // TSVECTOR
122
+ case 3615: // TSQUERY
123
+ case 3642: // GTSVECTOR
124
+ case 3734: // REGCONFIG
125
+ case 3769: // REGDICTIONARY
126
+ case 3802: // JSONB
127
+ case 4089: // REGNAMESPACE
128
+ case 4096: // REGROLE
129
+ default:
130
+ types[columnIndex] = "string"; break;
131
+ }
132
+ }
133
+
134
+ if (recordset.rows.length > 0 && Array.isArray(recordset.rows[0])) recordset.rows = recordset.rows[0];
135
+ for (var recordIndex in recordset.rows) {
136
+ var row = [];
137
+ for (var columnName in recordset.rows[recordIndex]) {
138
+ var columnIndex = columns.indexOf(columnName);
139
+ if (recordset.rows[recordIndex][columnName] instanceof Uint8Array) {
140
+ types[columnIndex] = "array";
141
+ recordset.rows[recordIndex][columnName] = Buffer.from(recordset.rows[recordIndex][columnName]).toString('base64');
142
+ }
143
+
144
+ if (recordset.rows[recordIndex][columnName] != null && typeof recordset.rows[recordIndex][columnName].toISOString === "function") {
145
+ if (types[columnIndex] == "datetimeZ") {
146
+ recordset.rows[recordIndex][columnName] = recordset.rows[recordIndex][columnName].toISOString();
147
+ }
148
+ else {
149
+ var dateTime = new Date(recordset.rows[recordIndex][columnName].getTime() - (recordset.rows[recordIndex][columnName].getTimezoneOffset() * 60000)).toISOString();
150
+ recordset.rows[recordIndex][columnName] = dateTime.replace("Z", "");
151
+ types[columnIndex] = "datetime";
152
+ }
153
+ }
154
+
155
+ if (recordset.rows[recordIndex][columnName] != null && types[columnIndex] == "timeZ") {
156
+ var time = recordset.rows[recordIndex][columnName];
157
+ var offset = time.substr(time.indexOf("+"));
158
+ if (offset.indexOf(":") == -1) offset += ":00";
159
+ time = time.substr(0, time.indexOf("+"));
160
+ if (time.indexOf(".") == -1) time += ".000"
161
+ recordset.rows[recordIndex][columnName] = "0001-01-01T" + time + offset;
162
+ }
163
+
164
+ row[columnIndex] = recordset.rows[recordIndex][columnName];
165
+ }
166
+ rows.push(row);
167
+ }
168
+
169
+ for (var typeIndex in types) {
170
+ if (types[typeIndex] == "timeZ") types[typeIndex] = "datetimeoffset";
171
+ if (types[typeIndex] == "datetimeZ") types[typeIndex] = "datetime";
172
+ }
173
+
174
+ end({ success: true, columns: columns, rows: rows, types: types });
175
+ }
176
+
177
+ var getConnectionStringInfo = function (connectionString) {
178
+ var info = { port: 5432 };
179
+
180
+ for (var propertyIndex in connectionString.split(";")) {
181
+ var property = connectionString.split(";")[propertyIndex];
182
+ if (property) {
183
+ var match = property.split(new RegExp('=|:'));
184
+ if (match && match.length >= 2) {
185
+ match[0] = match[0].trim().toLowerCase();
186
+ match[1] = match[1].trim();
187
+
188
+ switch (match[0]) {
189
+ case "data source":
190
+ case "server":
191
+ case "host":
192
+ info["host"] = match[1];
193
+ break;
194
+
195
+ case "port":
196
+ info["port"] = match[1];
197
+ break;
198
+
199
+ case "database":
200
+ case "location":
201
+ info["database"] = match[1];
202
+ break;
203
+
204
+ case "uid":
205
+ case "user":
206
+ case "user id":
207
+ info["userId"] = match[1];
208
+ break;
209
+
210
+ case "pwd":
211
+ case "password":
212
+ info["password"] = match[1];
213
+ break;
214
+
215
+ case "ssl":
216
+ info["ssl"] = match[1];
217
+ break;
218
+ case "sslmode":
219
+ if (match[1] == "require") info["ssl"] = 1;
220
+ else if (match[1] == "disable") info["ssl"] = 0;
221
+ break;
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ return info;
228
+ };
229
+
230
+ var pg = require('pg');
231
+ if (command.connectionString.startsWith("postgres://")) command.postgreConnectionString = command.connectionString
232
+ else {
233
+ command.connectionStringInfo = getConnectionStringInfo(command.connectionString);
234
+
235
+ command.postgreConnectionString = "postgres://" + command.connectionStringInfo.userId + ":" + command.connectionStringInfo.password + "@" + command.connectionStringInfo.host;
236
+ if (command.connectionStringInfo.port != null) command.postgreConnectionString += ":" + command.connectionStringInfo.port;
237
+ command.postgreConnectionString += "/" + command.connectionStringInfo.database;
238
+ }
239
+ var client = new pg.Client(command.postgreConnectionString);
240
+
241
+ connect();
242
+ }
243
+ catch (e) {
244
+ onError(e.stack);
245
+ }
246
+ }