@bkmj/node-red-contrib-odbcmj 1.4.0 → 1.5.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.
Files changed (2) hide show
  1. package/odbc.js +5 -7
  2. package/package.json +1 -1
package/odbc.js CHANGED
@@ -73,7 +73,7 @@ module.exports = function(RED) {
73
73
 
74
74
  // Automatically determine if it's a prepared statement based on the presence of
75
75
  // placeholders (?) in the query or if msg.parameters is an object/array.
76
- const isPreparedStatement = msg?.parameters || this.queryString.includes('?');
76
+ const isPreparedStatement = msg?.parameters || (this?.queryString ? this.queryString.includes('?') : false);
77
77
  this.queryString = this.config.query;
78
78
  if (!this.queryString.length) {
79
79
  this.queryString = null;
@@ -122,7 +122,7 @@ module.exports = function(RED) {
122
122
  } else {
123
123
  // If parameters are provided as an object, extract parameter names from the query
124
124
  // and create an ordered array of values for the prepared statement.
125
- if (typeof msg.parameters === 'object' && !Array.isArray(msg.parameters)) {                            
125
+ if (typeof msg.parameters === 'object' && !Array.isArray(msg.parameters)) {
126
126
  const paramNames = this.queryString.match(/\(([^)]*)\)/)[1].split(',').map(el => el.trim());
127
127
 
128
128
  // Create an ordered array of values
@@ -135,7 +135,7 @@ module.exports = function(RED) {
135
135
  throw new Error("msg.parameters must be an object or an array");
136
136
  } else if ((this.queryString.match(/\?/g) || []).length !== msg.parameters.length) {
137
137
  throw new Error("Incorrect number of parameters");
138
- }                    
138
+ }
139
139
  }
140
140
 
141
141
  // --- Syntax check ---
@@ -177,11 +177,10 @@ module.exports = function(RED) {
177
177
  if (isPreparedStatement) {
178
178
  // --- Execute prepared statement ---
179
179
  const stmt = await this.connection.createStatement();
180
- await this.connection.prepare(this.queryString);
181
- let values = msg.parameters;
180
+ await stmt.prepare(this.queryString);
182
181
 
183
182
  // Bind the values to the prepared statement
184
- await stmt.bind(values);
183
+ await stmt.bind(msg.parameters);
185
184
 
186
185
  // Execute the prepared statement
187
186
  result = await stmt.execute();
@@ -214,7 +213,6 @@ module.exports = function(RED) {
214
213
  }
215
214
  } catch (error) {
216
215
  // Handle query errors (e.g., log the error, set node status)
217
- this.error(`Error executing query: ${error}`);
218
216
  this.status({ fill: "red", shape: "ring", text: "Query error" });
219
217
  throw error; // Re-throw to trigger the outer catch block
220
218
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bkmj/node-red-contrib-odbcmj",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Node Red implementation of odbc.js",
5
5
  "keywords": [
6
6
  "node-red",