orange-orm 4.7.7 → 4.7.8

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/dist/index.mjs CHANGED
@@ -18269,7 +18269,9 @@ function requireWrapQuery$1 () {
18269
18269
  }
18270
18270
 
18271
18271
  function doQuery(query, onCompleted) {
18272
- const result = [];
18272
+ const results = []; // Array to hold multiple result sets
18273
+ let currentResult = []; // Current result set being built
18274
+ let hasResultSet = false; // Track if we're in an actual result set
18273
18275
 
18274
18276
  log.emitQuery({ sql: query.sql(), parameters: query.parameters });
18275
18277
  const sql = replaceParamChar(query.sql(), query.parameters);
@@ -18297,7 +18299,6 @@ function requireWrapQuery$1 () {
18297
18299
  }
18298
18300
 
18299
18301
  let keys;
18300
- // Now we can safely create Request using CachedRequest
18301
18302
  var request = new CachedRequest(sql, onInnerCompleted);
18302
18303
  addParameters(request, query.parameters, CachedTypes);
18303
18304
 
@@ -18309,7 +18310,35 @@ function requireWrapQuery$1 () {
18309
18310
  keys.forEach(cols => {
18310
18311
  tmp[cols] = rows[cols].value;
18311
18312
  });
18312
- result.push(tmp);
18313
+ currentResult.push(tmp);
18314
+ hasResultSet = true; // We're definitely in a result set
18315
+ });
18316
+
18317
+ // Handle column metadata - indicates a result set is starting
18318
+ request.on('columnMetadata', (_columns) => {
18319
+ hasResultSet = true; // A result set is starting (even if it ends up empty)
18320
+ });
18321
+
18322
+ // Handle end of each result set
18323
+ request.on('doneInProc', (_rowCount, _more) => {
18324
+ // End of a result set within a stored procedure
18325
+ // Add to results if we had a result set (even if empty)
18326
+ if (hasResultSet) {
18327
+ results.push(currentResult);
18328
+ currentResult = [];
18329
+ keys = null; // Reset keys for next result set
18330
+ hasResultSet = false; // Reset for next potential result set
18331
+ }
18332
+ });
18333
+
18334
+ request.on('doneProc', (_rowCount, _more) => {
18335
+ // End of stored procedure execution
18336
+ // Add to results if we had a result set (even if empty)
18337
+ if (hasResultSet) {
18338
+ results.push(currentResult);
18339
+ currentResult = [];
18340
+ hasResultSet = false; // Reset for next potential result set
18341
+ }
18313
18342
  });
18314
18343
 
18315
18344
  connection.execSql(request);
@@ -18318,14 +18347,28 @@ function requireWrapQuery$1 () {
18318
18347
  if (err) {
18319
18348
  onCompleted(extractError(err));
18320
18349
  } else {
18321
- onCompleted(null, result);
18350
+ // If we have any remaining result set, add it
18351
+ if (hasResultSet) {
18352
+ results.push(currentResult);
18353
+ }
18354
+
18355
+ // Return based on number of actual result sets
18356
+ if (results.length === 0) {
18357
+ // No result sets - return empty array
18358
+ onCompleted(null, []);
18359
+ } else if (results.length === 1) {
18360
+ // Single result set - return as single-depth array (even if empty)
18361
+ onCompleted(null, results[0]);
18362
+ } else {
18363
+ // Multiple result sets - return as array of arrays
18364
+ onCompleted(null, results);
18365
+ }
18322
18366
  }
18323
18367
  }
18324
18368
  }
18325
18369
  }
18326
18370
 
18327
- // same helpers as before
18328
-
18371
+ // Helper functions remain the same
18329
18372
  function extractError(e) {
18330
18373
  if (e && e.errors) {
18331
18374
  return e.errors[0];
package/docs/changelog.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## Changelog
2
+ __4.7.8__
3
+ Bugfix: Support for multiple result sets from stored procedures in MsSql. See [#130](https://github.com/alfateam/issues/130)
2
4
  __4.7.7__
3
5
  Always do logging with question mark as placeholder instead of dialect specific placeholder.
4
6
  __4.7.6__
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.7.7",
3
+ "version": "4.7.8",
4
4
  "main": "./src/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "browser": "./dist/index.browser.mjs",
@@ -22,7 +22,9 @@ function wrapQuery(_context, connection) {
22
22
  }
23
23
 
24
24
  function doQuery(query, onCompleted) {
25
- const result = [];
25
+ const results = []; // Array to hold multiple result sets
26
+ let currentResult = []; // Current result set being built
27
+ let hasResultSet = false; // Track if we're in an actual result set
26
28
 
27
29
  log.emitQuery({ sql: query.sql(), parameters: query.parameters });
28
30
  const sql = replaceParamChar(query.sql(), query.parameters);
@@ -50,7 +52,6 @@ function wrapQuery(_context, connection) {
50
52
  }
51
53
 
52
54
  let keys;
53
- // Now we can safely create Request using CachedRequest
54
55
  var request = new CachedRequest(sql, onInnerCompleted);
55
56
  addParameters(request, query.parameters, CachedTypes);
56
57
 
@@ -62,7 +63,35 @@ function wrapQuery(_context, connection) {
62
63
  keys.forEach(cols => {
63
64
  tmp[cols] = rows[cols].value;
64
65
  });
65
- result.push(tmp);
66
+ currentResult.push(tmp);
67
+ hasResultSet = true; // We're definitely in a result set
68
+ });
69
+
70
+ // Handle column metadata - indicates a result set is starting
71
+ request.on('columnMetadata', (_columns) => {
72
+ hasResultSet = true; // A result set is starting (even if it ends up empty)
73
+ });
74
+
75
+ // Handle end of each result set
76
+ request.on('doneInProc', (_rowCount, _more) => {
77
+ // End of a result set within a stored procedure
78
+ // Add to results if we had a result set (even if empty)
79
+ if (hasResultSet) {
80
+ results.push(currentResult);
81
+ currentResult = [];
82
+ keys = null; // Reset keys for next result set
83
+ hasResultSet = false; // Reset for next potential result set
84
+ }
85
+ });
86
+
87
+ request.on('doneProc', (_rowCount, _more) => {
88
+ // End of stored procedure execution
89
+ // Add to results if we had a result set (even if empty)
90
+ if (hasResultSet) {
91
+ results.push(currentResult);
92
+ currentResult = [];
93
+ hasResultSet = false; // Reset for next potential result set
94
+ }
66
95
  });
67
96
 
68
97
  connection.execSql(request);
@@ -71,14 +100,28 @@ function wrapQuery(_context, connection) {
71
100
  if (err) {
72
101
  onCompleted(extractError(err));
73
102
  } else {
74
- onCompleted(null, result);
103
+ // If we have any remaining result set, add it
104
+ if (hasResultSet) {
105
+ results.push(currentResult);
106
+ }
107
+
108
+ // Return based on number of actual result sets
109
+ if (results.length === 0) {
110
+ // No result sets - return empty array
111
+ onCompleted(null, []);
112
+ } else if (results.length === 1) {
113
+ // Single result set - return as single-depth array (even if empty)
114
+ onCompleted(null, results[0]);
115
+ } else {
116
+ // Multiple result sets - return as array of arrays
117
+ onCompleted(null, results);
118
+ }
75
119
  }
76
120
  }
77
121
  }
78
122
  }
79
123
 
80
- // same helpers as before
81
-
124
+ // Helper functions remain the same
82
125
  function extractError(e) {
83
126
  if (e && e.errors) {
84
127
  return e.errors[0];
@@ -130,4 +173,4 @@ function addParameters(request, params, TYPES) {
130
173
  }
131
174
  }
132
175
 
133
- module.exports = wrapQuery;
176
+ module.exports = wrapQuery;