@bkmj/node-red-contrib-odbcmj 1.6.5 → 1.7.0
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/README.md +18 -113
- package/odbc.html +226 -146
- package/odbc.js +623 -193
- package/package.json +1 -1
package/odbc.html
CHANGED
|
@@ -1,268 +1,348 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType(
|
|
3
|
-
category:
|
|
2
|
+
RED.nodes.registerType("odbc config", {
|
|
3
|
+
category: "config",
|
|
4
4
|
defaults: {
|
|
5
|
-
connectionString: {value:"", required:true},
|
|
6
|
-
name: {value:""},
|
|
7
|
-
initialSize: {value:5},
|
|
8
|
-
incrementSize: {value:5},
|
|
9
|
-
maxSize: {value:15},
|
|
10
|
-
shrink:{value:true},
|
|
11
|
-
syntaxtick:{value:false},
|
|
12
|
-
syntax: {value:"mysql"},
|
|
13
|
-
connectionTimeout:{value:3},
|
|
14
|
-
loginTimeout:{value:3}
|
|
5
|
+
connectionString: { value: "", required: true },
|
|
6
|
+
name: { value: "" },
|
|
7
|
+
initialSize: { value: 5 },
|
|
8
|
+
incrementSize: { value: 5 },
|
|
9
|
+
maxSize: { value: 15 },
|
|
10
|
+
shrink: { value: true },
|
|
11
|
+
syntaxtick: { value: false },
|
|
12
|
+
syntax: { value: "mysql" },
|
|
13
|
+
connectionTimeout: { value: 3 },
|
|
14
|
+
loginTimeout: { value: 3 },
|
|
15
|
+
// NOUVELLE PROPRIÉTÉ AJOUTÉE ICI
|
|
16
|
+
retryFreshConnection: { value: false }, // Default à false
|
|
15
17
|
},
|
|
16
|
-
label: function() {
|
|
17
|
-
return this.name ||
|
|
18
|
+
label: function () {
|
|
19
|
+
return this.name || "odbc config";
|
|
18
20
|
},
|
|
19
|
-
oneditprepare: function() {
|
|
21
|
+
oneditprepare: function () {
|
|
20
22
|
$(".input-syntax").hide();
|
|
21
|
-
$("#node-config-input-syntaxtick").change(function() {
|
|
22
|
-
if (this.checked){
|
|
23
|
+
$("#node-config-input-syntaxtick").change(function () {
|
|
24
|
+
if (this.checked) {
|
|
23
25
|
$(".input-syntax").show();
|
|
24
26
|
} else {
|
|
25
27
|
$(".input-syntax").hide();
|
|
26
28
|
}
|
|
27
29
|
});
|
|
28
|
-
}
|
|
30
|
+
},
|
|
29
31
|
});
|
|
30
32
|
</script>
|
|
31
33
|
|
|
32
34
|
<script type="text/html" data-template-name="odbc config">
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-config-input-name"
|
|
37
|
+
><i class="fa fa-tag"></i> Name</label
|
|
38
|
+
>
|
|
39
|
+
<input type="text" id="node-config-input-name" />
|
|
40
|
+
</div>
|
|
33
41
|
|
|
34
42
|
<div class="form-row">
|
|
35
|
-
<label for="node-config-input-
|
|
36
|
-
|
|
43
|
+
<label for="node-config-input-connectionString"
|
|
44
|
+
><i class="fa fa-database"></i> Connection String</label
|
|
45
|
+
>
|
|
46
|
+
<input
|
|
47
|
+
type="text"
|
|
48
|
+
id="node-config-input-connectionString"
|
|
49
|
+
placeholder="DSN=...;"
|
|
50
|
+
/>
|
|
37
51
|
</div>
|
|
38
52
|
|
|
39
53
|
<div class="form-row">
|
|
40
|
-
<label for="node-config-input-
|
|
41
|
-
|
|
54
|
+
<label for="node-config-input-initialSize"
|
|
55
|
+
><i class="fa fa-play"></i> Initial Size</label
|
|
56
|
+
>
|
|
57
|
+
<input
|
|
58
|
+
type="number"
|
|
59
|
+
id="node-config-input-initialSize"
|
|
60
|
+
placeholder="5"
|
|
61
|
+
/>
|
|
42
62
|
</div>
|
|
43
63
|
|
|
44
64
|
<div class="form-row">
|
|
45
|
-
<label for="node-config-input-
|
|
46
|
-
|
|
65
|
+
<label for="node-config-input-incrementSize"
|
|
66
|
+
><i class="fa fa-plus"></i> Increment Size</label
|
|
67
|
+
>
|
|
68
|
+
<input
|
|
69
|
+
type="number"
|
|
70
|
+
id="node-config-input-incrementSize"
|
|
71
|
+
placeholder="5"
|
|
72
|
+
/>
|
|
47
73
|
</div>
|
|
48
74
|
|
|
49
75
|
<div class="form-row">
|
|
50
|
-
<label for="node-config-input-
|
|
51
|
-
|
|
76
|
+
<label for="node-config-input-maxSize"
|
|
77
|
+
><i class="fa fa-stop"></i> Max Size</label
|
|
78
|
+
>
|
|
79
|
+
<input type="number" id="node-config-input-maxSize" placeholder="15" />
|
|
52
80
|
</div>
|
|
53
81
|
|
|
54
82
|
<div class="form-row">
|
|
55
|
-
<label for="node-config-input-
|
|
56
|
-
|
|
83
|
+
<label for="node-config-input-shrink"
|
|
84
|
+
><i class="fa fa-compress"></i> Shrink Pool</label
|
|
85
|
+
>
|
|
86
|
+
<input
|
|
87
|
+
type="checkbox"
|
|
88
|
+
id="node-config-input-shrink"
|
|
89
|
+
style="margin-left:0px; vertical-align:top; width:auto !important;"
|
|
90
|
+
/>
|
|
57
91
|
</div>
|
|
58
92
|
|
|
59
93
|
<div class="form-row">
|
|
60
|
-
<label for="node-config-input-
|
|
61
|
-
|
|
94
|
+
<label for="node-config-input-connectionTimeout"
|
|
95
|
+
><i class="fa fa-clock-o"></i></i> Connection Timeout (sec)</label
|
|
96
|
+
>
|
|
97
|
+
<input
|
|
98
|
+
type="number"
|
|
99
|
+
id="node-config-input-connectionTimeout"
|
|
100
|
+
placeholder="3"
|
|
101
|
+
/>
|
|
62
102
|
</div>
|
|
63
103
|
|
|
64
104
|
<div class="form-row">
|
|
65
|
-
<label for="node-config-input-
|
|
66
|
-
|
|
105
|
+
<label for="node-config-input-loginTimeout"
|
|
106
|
+
><i class="fa fa-clock-o"></i> Login Timeout (sec)</label
|
|
107
|
+
>
|
|
108
|
+
<input
|
|
109
|
+
type="number"
|
|
110
|
+
id="node-config-input-loginTimeout"
|
|
111
|
+
placeholder="3"
|
|
112
|
+
/>
|
|
67
113
|
</div>
|
|
68
114
|
|
|
69
115
|
<div class="form-row">
|
|
70
|
-
<label for="node-config-input-
|
|
71
|
-
|
|
116
|
+
<label for="node-config-input-retryFreshConnection" style="width: auto;"
|
|
117
|
+
><i class="fa fa-refresh"></i> Retry with fresh connection on
|
|
118
|
+
error</label
|
|
119
|
+
>
|
|
120
|
+
<input
|
|
121
|
+
type="checkbox"
|
|
122
|
+
id="node-config-input-retryFreshConnection"
|
|
123
|
+
style="display: inline-block; width: auto; vertical-align: top;"
|
|
124
|
+
/>
|
|
72
125
|
</div>
|
|
73
126
|
|
|
74
127
|
<div class="form-row">
|
|
75
|
-
<label for="node-config-input-syntaxtick" style="width: auto;"
|
|
76
|
-
|
|
128
|
+
<label for="node-config-input-syntaxtick" style="width: auto;"
|
|
129
|
+
><i class="fa fa-underline"></i> Syntax Checker</label
|
|
130
|
+
>
|
|
131
|
+
<input
|
|
132
|
+
type="checkbox"
|
|
133
|
+
id="node-config-input-syntaxtick"
|
|
134
|
+
style="display: inline-block; width: auto; vertical-align: top;"
|
|
135
|
+
/>
|
|
77
136
|
</div>
|
|
78
137
|
|
|
79
138
|
<div class="form-row input-syntax">
|
|
80
|
-
<label for="
|
|
139
|
+
<label for="node-config-input-syntax"
|
|
140
|
+
><i class="fa fa-language"></i> Syntax</label
|
|
141
|
+
>
|
|
81
142
|
<select id="node-config-input-syntax" style="width: 70%">
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
143
|
+
<option value="bigquery">BigQuery</option>
|
|
144
|
+
<option value="db2">DB2</option>
|
|
145
|
+
<option value="hive">Hive</option>
|
|
146
|
+
<option value="mariadb">MariaDB</option>
|
|
147
|
+
<option value="mysql">Mysql</option>
|
|
148
|
+
<option value="postgresql">PostgresQL</option>
|
|
149
|
+
<option value="sqlite">Sqlite</option>
|
|
150
|
+
<option value="transactsql">TransactSQL</option>
|
|
151
|
+
<option value="flinksql">FlinkSQL</option>
|
|
91
152
|
</select>
|
|
92
153
|
</div>
|
|
93
154
|
</script>
|
|
94
155
|
|
|
95
156
|
<script type="text/javascript">
|
|
96
|
-
RED.nodes.registerType(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
name: {value:""},
|
|
101
|
-
connection: {type:"odbc config", required:true},
|
|
102
|
-
query: {value: ""},
|
|
103
|
-
outputObj: {value:"payload"}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return this.name||"odbc";
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
157
|
+
RED.nodes.registerType("odbc", {
|
|
158
|
+
category: "storage",
|
|
159
|
+
color: "#89A5C0",
|
|
160
|
+
defaults: {
|
|
161
|
+
name: { value: "" },
|
|
162
|
+
connection: { type: "odbc config", required: true },
|
|
163
|
+
query: { value: "" },
|
|
164
|
+
outputObj: { value: "payload" },
|
|
165
|
+
},
|
|
166
|
+
inputs: 1,
|
|
167
|
+
outputs: 1,
|
|
168
|
+
icon: "db.svg",
|
|
169
|
+
label: function () {
|
|
170
|
+
return this.name || "odbc";
|
|
171
|
+
},
|
|
172
|
+
oneditprepare: function () {
|
|
173
|
+
this.editor = RED.editor.createEditor({
|
|
174
|
+
id: "node-input-query-editor",
|
|
175
|
+
mode: "ace/mode/sql",
|
|
176
|
+
value: this.query,
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
oneditsave: function () {
|
|
180
|
+
this.query = this.editor.getValue();
|
|
181
|
+
this.editor.destroy();
|
|
182
|
+
delete this.editor;
|
|
183
|
+
},
|
|
184
|
+
oneditcancel: function () {
|
|
185
|
+
this.editor.destroy();
|
|
186
|
+
delete this.editor;
|
|
187
|
+
},
|
|
188
|
+
});
|
|
128
189
|
</script>
|
|
129
190
|
|
|
130
191
|
<script type="text/html" data-template-name="odbc">
|
|
131
|
-
|
|
132
192
|
<div class="form-row">
|
|
133
193
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
134
|
-
<input type="text" id="node-input-name"
|
|
194
|
+
<input type="text" id="node-input-name" />
|
|
135
195
|
</div>
|
|
136
196
|
|
|
137
197
|
<div class="form-row">
|
|
138
|
-
|
|
139
|
-
|
|
198
|
+
<label for="node-input-connection"
|
|
199
|
+
><i class="fa fa-cog"></i> Connection</label
|
|
200
|
+
>
|
|
201
|
+
<input type="text" id="node-input-connection" />
|
|
140
202
|
</div>
|
|
141
203
|
|
|
142
204
|
<div class="form-row node-text-editor-row">
|
|
143
|
-
<label for="node-input-query" style="width: 100% !important;"
|
|
144
|
-
|
|
205
|
+
<label for="node-input-query" style="width: 100% !important;"
|
|
206
|
+
><i class="fa fa-search"></i> Query</label
|
|
207
|
+
>
|
|
208
|
+
<div
|
|
209
|
+
style="height: 250px;"
|
|
210
|
+
class="node-text-editor"
|
|
211
|
+
id="node-input-query-editor"
|
|
212
|
+
></div>
|
|
145
213
|
</div>
|
|
146
214
|
|
|
147
215
|
<div class="form-row">
|
|
148
|
-
|
|
149
|
-
|
|
216
|
+
<label for="node-input-outputObj"
|
|
217
|
+
><i class="fa fa-edit"></i> Result to</label
|
|
218
|
+
>
|
|
219
|
+
<span>msg.</span
|
|
220
|
+
><input
|
|
221
|
+
type="text"
|
|
222
|
+
id="node-input-outputObj"
|
|
223
|
+
placeholder="payload"
|
|
224
|
+
style="width: 64%;"
|
|
225
|
+
/>
|
|
150
226
|
</div>
|
|
151
227
|
</script>
|
|
152
228
|
<script type="text/markdown" data-help-name="odbc config">
|
|
153
|
-
A configuration node that manages connections in an `odbc.pool` object.
|
|
154
|
-
[Can take any configuration property recognized by `odbc.pool()`](https://www.npmjs.com/package/odbc/v/2.4.8#constructor-odbcconnectconnectionstring).
|
|
155
|
-
The connection pool will initialize the first time an `odbc` node receives an input message.
|
|
229
|
+
A configuration node that manages connections in an `odbc.pool` object.
|
|
230
|
+
[Can take any configuration property recognized by `odbc.pool()`](https://www.npmjs.com/package/odbc/v/2.4.8#constructor-odbcconnectconnectionstring).
|
|
231
|
+
The connection pool will initialize the first time an `odbc` node receives an input message.
|
|
156
232
|
|
|
157
|
-
## Properties
|
|
233
|
+
## Properties
|
|
158
234
|
|
|
159
|
-
|
|
235
|
+
- (**required**) **`connectionString`**: <`string`>
|
|
160
236
|
|
|
161
|
-
|
|
162
|
-
|
|
237
|
+
An ODBC connection string that defines your DSN and/or connection string options.
|
|
238
|
+
Check your ODBC driver documentation for more information about valid connection strings.
|
|
163
239
|
|
|
164
|
-
|
|
165
|
-
```
|
|
166
|
-
DSN=MyDSN;DFT=2;
|
|
167
|
-
```
|
|
240
|
+
Example:
|
|
168
241
|
|
|
169
|
-
|
|
242
|
+
```
|
|
243
|
+
DSN=MyDSN;DFT=2;
|
|
244
|
+
```
|
|
170
245
|
|
|
171
|
-
|
|
246
|
+
- (optional) **`initialSize`**: <`number`>
|
|
172
247
|
|
|
173
|
-
|
|
248
|
+
The number of connections created in the pool when it is initialized. Default: 5.
|
|
174
249
|
|
|
175
|
-
|
|
250
|
+
- (optional) **`incrementSize`**: <`number`>
|
|
176
251
|
|
|
177
|
-
|
|
252
|
+
The number of connections that are created when the pool is exhausted. Default: 5.
|
|
178
253
|
|
|
179
|
-
|
|
254
|
+
- (optional) **`maxSize`**: <`number`>
|
|
180
255
|
|
|
181
|
-
|
|
256
|
+
The maximum number of connections allowed in the pool before it won't create any more. Default: 15.
|
|
182
257
|
|
|
183
|
-
|
|
258
|
+
- (optional) **`shrinkPool`**: <`boolean`>
|
|
184
259
|
|
|
185
|
-
|
|
260
|
+
Whether the number of connections should be reduced to `initialSize` when they are returned to the pool. Default: true.
|
|
186
261
|
|
|
187
|
-
|
|
262
|
+
- (optional) **`connectionTimeout`**: <`number`>
|
|
188
263
|
|
|
189
|
-
|
|
264
|
+
The number of seconds for a connection to remain idle before closing. Default: 3.
|
|
190
265
|
|
|
191
|
-
|
|
266
|
+
- (optional) **`loginTimeout`**: <`number`>
|
|
192
267
|
|
|
193
|
-
|
|
268
|
+
The number of seconds for an attempt to create a connection before returning to the application. Default: 3.
|
|
194
269
|
|
|
195
|
-
|
|
196
|
-
[parsed](https://www.npmjs.com/package/node-sql-parser#create-ast-for-sql-statement)
|
|
197
|
-
and appended as an object to the output message with a key named `parsedQuery`. Default: false.
|
|
270
|
+
- (optional) **`retryFreshConnection`**: <`boolean`> If checked, in case of a query error, the node will attempt the query a second time using a brand new database connection instead of one from the pool. If this second attempt is successful, it indicates the pooled connection was faulty, and the entire connection pool will be reset. Default: false.
|
|
198
271
|
|
|
199
|
-
|
|
272
|
+
- (optional) **`syntaxChecker`**: <`boolean`>
|
|
200
273
|
|
|
201
|
-
|
|
202
|
-
|
|
274
|
+
Whether the syntax validator is activated or not. If activated, the query string will be
|
|
275
|
+
[parsed](https://www.npmjs.com/package/node-sql-parser#create-ast-for-sql-statement)
|
|
276
|
+
and appended as an object to the output message with a key named `parsedQuery`. Default: false.
|
|
277
|
+
|
|
278
|
+
- (optional) **`syntax`**: <`string`>
|
|
279
|
+
|
|
280
|
+
Dropdown list of the available [SQL flavors available](https://www.npmjs.com/package/node-sql-parser#supported-database-sql-syntax).
|
|
281
|
+
Default: mysql.
|
|
203
282
|
</script>
|
|
204
283
|
|
|
205
284
|
<script type="text/markdown" data-help-name="odbc">
|
|
206
|
-
A node that runs a query when input is received. Each instance of the node can define its own query string,
|
|
207
|
-
as well as take a query and/or parameters as input. A query sent as an input message will override any query
|
|
285
|
+
A node that runs a query when input is received. Each instance of the node can define its own query string,
|
|
286
|
+
as well as take a query and/or parameters as input. A query sent as an input message will override any query
|
|
208
287
|
defined in the node properties.
|
|
209
288
|
|
|
210
289
|
## Properties
|
|
211
290
|
|
|
212
|
-
|
|
291
|
+
- (**required**) **`connection`**: <`odbc config`>
|
|
213
292
|
|
|
214
293
|
The ODBC pool node that defines the connection settings and manages the connection pool used by this node.
|
|
215
294
|
|
|
216
|
-
|
|
295
|
+
- (optional) **`query`**: <`string`>
|
|
217
296
|
|
|
218
|
-
A valid SQL query string.
|
|
219
|
-
* Can contain parameters inserted using Mustache syntax (e.g., `{{{payload}}}`).
|
|
220
|
-
* Can use placeholders (`?`) for parameters.
|
|
221
|
-
* Can embed parameters directly in the query string.
|
|
297
|
+
A valid SQL query string.
|
|
222
298
|
|
|
223
|
-
|
|
299
|
+
- Can contain parameters inserted using Mustache syntax (e.g., `{{{payload}}}`).
|
|
300
|
+
- Can use placeholders (`?`) for parameters.
|
|
301
|
+
- Can embed parameters directly in the query string.
|
|
224
302
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
303
|
+
- (**required**) **`result to`**: <`dot-notation string`>
|
|
304
|
+
|
|
305
|
+
The JSON nested element structure that will contain the result output. The string must be a valid
|
|
306
|
+
JSON object structure using dot-notation, minus the `msg.` (e.g., `payload.results`) and must not
|
|
307
|
+
start or end with a period. Square bracket notation is not allowed. The node input object is carried
|
|
308
|
+
out to the output, as long as the output object name does not conflict with it. If the targeted output
|
|
309
|
+
JSON object was already present in the input, the result from the query will be appended to it if it
|
|
230
310
|
was itself an object (but not an array); otherwise, the original key/value pair will be overwritten.
|
|
231
311
|
|
|
232
312
|
Example:
|
|
233
313
|
|
|
234
|
-
|
|
235
|
-
|
|
314
|
+
- `input msg: {"payload": {"result": {"othervalue": 10} } };`
|
|
315
|
+
- `result to: payload.results.values`
|
|
236
316
|
|
|
237
|
-
In this case, `values` will be appended to `result` without overwriting `othervalue`.
|
|
317
|
+
In this case, `values` will be appended to `result` without overwriting `othervalue`.
|
|
238
318
|
If `result` had been a string, then it would have been replaced by `values`.
|
|
239
319
|
|
|
240
320
|
## Inputs
|
|
241
321
|
|
|
242
322
|
The `odbc` node accepts a message input that can contain:
|
|
243
323
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
324
|
+
- **`query`**: <`string`> A valid SQL query string. This overrides the query defined in the node properties.
|
|
325
|
+
- **`payload`**:
|
|
326
|
+
- A JSON string containing a `query` property with the SQL string.
|
|
327
|
+
- An object with a `query` property containing the SQL string.
|
|
328
|
+
- **`parameters`**: <`array` or `object`>
|
|
329
|
+
- Can be an array of values corresponding to the placeholders (`?`) in the query.
|
|
330
|
+
- Can be an object mapping parameter names to values. If the query contains placeholders (`?`) and `msg.parameters` is an object, the values will be automatically mapped to the placeholders based on the order of the parameters in the query.
|
|
251
331
|
|
|
252
332
|
## Outputs
|
|
253
333
|
|
|
254
334
|
Returns a message containing:
|
|
255
335
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
336
|
+
- **`output object`**: <`array`> The `odbc` result array returned from the query.
|
|
337
|
+
- **`odbc`**: <`object`> Contains additional information returned by the `odbc` module.
|
|
338
|
+
- **`parsedQuery`**: <`object`> (Optional) The parsed SQL query if the syntax checker is enabled.
|
|
259
339
|
|
|
260
340
|
## Automatic Prepared Statement Handling
|
|
261
341
|
|
|
262
342
|
The node automatically determines whether to use a prepared statement or a regular query based on the following:
|
|
263
343
|
|
|
264
|
-
|
|
265
|
-
|
|
344
|
+
- **Presence of Placeholders:** If the query string contains placeholders (`?`), the node will use a prepared statement.
|
|
345
|
+
- **`msg.parameters` Object/Array:** If the `msg.parameters` object/array is provided, the node will use a prepared statement.
|
|
266
346
|
|
|
267
347
|
This automatic handling ensures that your queries are executed in the most secure way possible, minimizing the risk of SQL injection vulnerabilities.
|
|
268
|
-
</script>
|
|
348
|
+
</script>
|