orange-orm 4.7.5-beta.0 → 4.7.5-beta.1
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 +84 -37
- package/package.json +1 -1
- package/src/mssql/wrapQuery.js +85 -38
package/dist/index.mjs
CHANGED
|
@@ -17444,59 +17444,98 @@ function requireWrapQuery$2 () {
|
|
|
17444
17444
|
function runQuery(query, onCompleted) {
|
|
17445
17445
|
var params = query.parameters;
|
|
17446
17446
|
var sql = query.sql();
|
|
17447
|
-
log.emitQuery({ sql, parameters: params });
|
|
17448
|
-
|
|
17449
|
-
// Helper function to check for non-ASCII UTF-8 characters
|
|
17450
|
-
function hasNonAsciiCharacters(str) {
|
|
17451
|
-
// Check if string contains any character with code point > 127 (non-ASCII)
|
|
17452
|
-
return /[\u0080-\uFFFF]/.test(str);
|
|
17453
|
-
}
|
|
17454
|
-
|
|
17455
|
-
function stringToHex(str) {
|
|
17456
|
-
return Buffer.from(str, 'utf8').toString('hex');
|
|
17457
|
-
}
|
|
17458
17447
|
|
|
17459
17448
|
const replacements = [];
|
|
17460
17449
|
const parametersToRemove = [];
|
|
17461
17450
|
const engine = getSessionSingleton(_context, 'engine');
|
|
17462
17451
|
|
|
17463
17452
|
if (engine === 'sap') {
|
|
17464
|
-
|
|
17465
|
-
|
|
17466
|
-
const parameter = params[i];
|
|
17453
|
+
const sap = connection.msnodesqlv8;
|
|
17454
|
+
// Helper function to check for non-ASCII UTF-8 characters
|
|
17467
17455
|
|
|
17468
|
-
|
|
17469
|
-
|
|
17470
|
-
|
|
17456
|
+
// Check if this is a stored procedure call
|
|
17457
|
+
const isStoredProcCall = /EXECUTE\s+/i.test(sql) || /EXEC\s+/i.test(sql);
|
|
17458
|
+
let hexVariables = [];
|
|
17471
17459
|
|
|
17472
|
-
|
|
17473
|
-
|
|
17474
|
-
|
|
17475
|
-
});
|
|
17460
|
+
// Non-ASCII UTF-8 characters workaround
|
|
17461
|
+
for (let i = 0; i < params.length; i++) {
|
|
17462
|
+
const parameter = params[i];
|
|
17476
17463
|
|
|
17477
|
-
|
|
17464
|
+
if (typeof parameter === 'string') {
|
|
17465
|
+
if (hasNonAsciiCharacters(parameter)) {
|
|
17466
|
+
|
|
17467
|
+
const hexValue = stringToHex(parameter);
|
|
17468
|
+
|
|
17469
|
+
if (isStoredProcCall) {
|
|
17470
|
+
// For stored procedures, create a variable
|
|
17471
|
+
const varName = `@hex_param_${i}`;
|
|
17472
|
+
const convertClause = `CONVERT(VARCHAR(255), CONVERT(VARBINARY(127), 0x${hexValue}))`;
|
|
17473
|
+
|
|
17474
|
+
hexVariables.push({
|
|
17475
|
+
declaration: `DECLARE ${varName} VARCHAR(255)`,
|
|
17476
|
+
assignment: `SET ${varName} = ${convertClause}`
|
|
17477
|
+
});
|
|
17478
|
+
|
|
17479
|
+
replacements.push({
|
|
17480
|
+
index: i,
|
|
17481
|
+
replacement: varName
|
|
17482
|
+
});
|
|
17483
|
+
} else {
|
|
17484
|
+
// For regular queries, use inline conversion
|
|
17485
|
+
const convertClause = `CONVERT(VARCHAR(255), CONVERT(VARBINARY(127), 0x${hexValue}))`;
|
|
17486
|
+
replacements.push({
|
|
17487
|
+
index: i,
|
|
17488
|
+
replacement: convertClause
|
|
17489
|
+
});
|
|
17490
|
+
}
|
|
17491
|
+
parametersToRemove.push(i);
|
|
17492
|
+
}
|
|
17493
|
+
else
|
|
17494
|
+
params[i] = sap.VarChar(parameter);
|
|
17478
17495
|
}
|
|
17479
17496
|
}
|
|
17480
|
-
}
|
|
17481
17497
|
|
|
17482
|
-
|
|
17483
|
-
|
|
17484
|
-
|
|
17485
|
-
|
|
17486
|
-
|
|
17487
|
-
|
|
17498
|
+
// Apply replacements
|
|
17499
|
+
if (replacements.length > 0) {
|
|
17500
|
+
let questionMarkIndex = 0;
|
|
17501
|
+
sql = sql.replace(/\?/g, (match) => {
|
|
17502
|
+
const replacement = replacements.find(r => r.index === questionMarkIndex);
|
|
17503
|
+
questionMarkIndex++;
|
|
17488
17504
|
|
|
17489
|
-
|
|
17490
|
-
|
|
17505
|
+
if (replacement) {
|
|
17506
|
+
return replacement.replacement;
|
|
17507
|
+
}
|
|
17508
|
+
return match;
|
|
17509
|
+
});
|
|
17510
|
+
|
|
17511
|
+
// For stored procedures, inject hex variable declarations
|
|
17512
|
+
if (isStoredProcCall && hexVariables.length > 0) {
|
|
17513
|
+
const lines = sql.split('\n');
|
|
17514
|
+
let insertIndex = 0;
|
|
17515
|
+
|
|
17516
|
+
// Find the last DECLARE statement
|
|
17517
|
+
for (let i = 0; i < lines.length; i++) {
|
|
17518
|
+
if (/^\s*DECLARE\s+/i.test(lines[i])) {
|
|
17519
|
+
insertIndex = i + 1;
|
|
17520
|
+
}
|
|
17521
|
+
}
|
|
17522
|
+
|
|
17523
|
+
// Insert hex variable declarations and assignments
|
|
17524
|
+
const hexDeclarations = hexVariables.map(v => v.declaration);
|
|
17525
|
+
const hexAssignments = hexVariables.map(v => v.assignment);
|
|
17526
|
+
|
|
17527
|
+
lines.splice(insertIndex, 0, ...hexDeclarations, ...hexAssignments);
|
|
17528
|
+
sql = lines.join('\n');
|
|
17491
17529
|
}
|
|
17492
|
-
|
|
17530
|
+
}
|
|
17531
|
+
|
|
17532
|
+
// Remove parameters in reverse order to maintain correct indices
|
|
17533
|
+
parametersToRemove.reverse().forEach(index => {
|
|
17534
|
+
params.splice(index, 1);
|
|
17493
17535
|
});
|
|
17494
17536
|
}
|
|
17495
17537
|
|
|
17496
|
-
|
|
17497
|
-
parametersToRemove.reverse().forEach(index => {
|
|
17498
|
-
params.splice(index, 1);
|
|
17499
|
-
});
|
|
17538
|
+
log.emitQuery({ sql, parameters: params });
|
|
17500
17539
|
|
|
17501
17540
|
runOriginalQuery.call(connection, sql, params, onInnerCompleted);
|
|
17502
17541
|
let result = [];
|
|
@@ -17511,7 +17550,6 @@ function requireWrapQuery$2 () {
|
|
|
17511
17550
|
}
|
|
17512
17551
|
result.push(rows);
|
|
17513
17552
|
if (!hasMore) {
|
|
17514
|
-
|
|
17515
17553
|
if (result.length === 1)
|
|
17516
17554
|
onCompleted(null, result[0]);
|
|
17517
17555
|
else
|
|
@@ -17519,9 +17557,18 @@ function requireWrapQuery$2 () {
|
|
|
17519
17557
|
}
|
|
17520
17558
|
}
|
|
17521
17559
|
}
|
|
17560
|
+
}
|
|
17522
17561
|
|
|
17562
|
+
function hasNonAsciiCharacters(str) {
|
|
17563
|
+
// Check if string contains any character with code point > 127 (non-ASCII)
|
|
17564
|
+
return /[\u0080-\uFFFF]/.test(str);
|
|
17523
17565
|
}
|
|
17524
17566
|
|
|
17567
|
+
function stringToHex(str) {
|
|
17568
|
+
return Buffer.from(str, 'utf8').toString('hex');
|
|
17569
|
+
}
|
|
17570
|
+
|
|
17571
|
+
|
|
17525
17572
|
wrapQuery_1$2 = wrapQuery;
|
|
17526
17573
|
return wrapQuery_1$2;
|
|
17527
17574
|
}
|
package/package.json
CHANGED
package/src/mssql/wrapQuery.js
CHANGED
|
@@ -8,59 +8,98 @@ function wrapQuery(_context, connection) {
|
|
|
8
8
|
function runQuery(query, onCompleted) {
|
|
9
9
|
var params = query.parameters;
|
|
10
10
|
var sql = query.sql();
|
|
11
|
-
log.emitQuery({ sql, parameters: params });
|
|
12
|
-
|
|
13
|
-
// Helper function to check for non-ASCII UTF-8 characters
|
|
14
|
-
function hasNonAsciiCharacters(str) {
|
|
15
|
-
// Check if string contains any character with code point > 127 (non-ASCII)
|
|
16
|
-
return /[\u0080-\uFFFF]/.test(str);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function stringToHex(str) {
|
|
20
|
-
return Buffer.from(str, 'utf8').toString('hex');
|
|
21
|
-
}
|
|
22
11
|
|
|
23
12
|
const replacements = [];
|
|
24
13
|
const parametersToRemove = [];
|
|
25
14
|
const engine = getSessionSingleton(_context, 'engine');
|
|
26
15
|
|
|
27
16
|
if (engine === 'sap') {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const parameter = params[i];
|
|
17
|
+
const sap = connection.msnodesqlv8;
|
|
18
|
+
// Helper function to check for non-ASCII UTF-8 characters
|
|
31
19
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
// Check if this is a stored procedure call
|
|
21
|
+
const isStoredProcCall = /EXECUTE\s+/i.test(sql) || /EXEC\s+/i.test(sql);
|
|
22
|
+
let hexVariables = [];
|
|
35
23
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
24
|
+
// Non-ASCII UTF-8 characters workaround
|
|
25
|
+
for (let i = 0; i < params.length; i++) {
|
|
26
|
+
const parameter = params[i];
|
|
40
27
|
|
|
41
|
-
|
|
28
|
+
if (typeof parameter === 'string') {
|
|
29
|
+
if (hasNonAsciiCharacters(parameter)) {
|
|
30
|
+
|
|
31
|
+
const hexValue = stringToHex(parameter);
|
|
32
|
+
|
|
33
|
+
if (isStoredProcCall) {
|
|
34
|
+
// For stored procedures, create a variable
|
|
35
|
+
const varName = `@hex_param_${i}`;
|
|
36
|
+
const convertClause = `CONVERT(VARCHAR(255), CONVERT(VARBINARY(127), 0x${hexValue}))`;
|
|
37
|
+
|
|
38
|
+
hexVariables.push({
|
|
39
|
+
declaration: `DECLARE ${varName} VARCHAR(255)`,
|
|
40
|
+
assignment: `SET ${varName} = ${convertClause}`
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
replacements.push({
|
|
44
|
+
index: i,
|
|
45
|
+
replacement: varName
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
// For regular queries, use inline conversion
|
|
49
|
+
const convertClause = `CONVERT(VARCHAR(255), CONVERT(VARBINARY(127), 0x${hexValue}))`;
|
|
50
|
+
replacements.push({
|
|
51
|
+
index: i,
|
|
52
|
+
replacement: convertClause
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
parametersToRemove.push(i);
|
|
56
|
+
}
|
|
57
|
+
else
|
|
58
|
+
params[i] = sap.VarChar(parameter);
|
|
42
59
|
}
|
|
43
60
|
}
|
|
44
|
-
}
|
|
45
61
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
// Apply replacements
|
|
63
|
+
if (replacements.length > 0) {
|
|
64
|
+
let questionMarkIndex = 0;
|
|
65
|
+
sql = sql.replace(/\?/g, (match) => {
|
|
66
|
+
const replacement = replacements.find(r => r.index === questionMarkIndex);
|
|
67
|
+
questionMarkIndex++;
|
|
68
|
+
|
|
69
|
+
if (replacement) {
|
|
70
|
+
return replacement.replacement;
|
|
71
|
+
}
|
|
72
|
+
return match;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// For stored procedures, inject hex variable declarations
|
|
76
|
+
if (isStoredProcCall && hexVariables.length > 0) {
|
|
77
|
+
const lines = sql.split('\n');
|
|
78
|
+
let insertIndex = 0;
|
|
79
|
+
|
|
80
|
+
// Find the last DECLARE statement
|
|
81
|
+
for (let i = 0; i < lines.length; i++) {
|
|
82
|
+
if (/^\s*DECLARE\s+/i.test(lines[i])) {
|
|
83
|
+
insertIndex = i + 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Insert hex variable declarations and assignments
|
|
88
|
+
const hexDeclarations = hexVariables.map(v => v.declaration);
|
|
89
|
+
const hexAssignments = hexVariables.map(v => v.assignment);
|
|
90
|
+
|
|
91
|
+
lines.splice(insertIndex, 0, ...hexDeclarations, ...hexAssignments);
|
|
92
|
+
sql = lines.join('\n');
|
|
55
93
|
}
|
|
56
|
-
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Remove parameters in reverse order to maintain correct indices
|
|
97
|
+
parametersToRemove.reverse().forEach(index => {
|
|
98
|
+
params.splice(index, 1);
|
|
57
99
|
});
|
|
58
100
|
}
|
|
59
101
|
|
|
60
|
-
|
|
61
|
-
parametersToRemove.reverse().forEach(index => {
|
|
62
|
-
params.splice(index, 1);
|
|
63
|
-
});
|
|
102
|
+
log.emitQuery({ sql, parameters: params });
|
|
64
103
|
|
|
65
104
|
runOriginalQuery.call(connection, sql, params, onInnerCompleted);
|
|
66
105
|
let result = [];
|
|
@@ -75,7 +114,6 @@ function wrapQuery(_context, connection) {
|
|
|
75
114
|
}
|
|
76
115
|
result.push(rows);
|
|
77
116
|
if (!hasMore) {
|
|
78
|
-
|
|
79
117
|
if (result.length === 1)
|
|
80
118
|
onCompleted(null, result[0]);
|
|
81
119
|
else
|
|
@@ -83,7 +121,16 @@ function wrapQuery(_context, connection) {
|
|
|
83
121
|
}
|
|
84
122
|
}
|
|
85
123
|
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function hasNonAsciiCharacters(str) {
|
|
127
|
+
// Check if string contains any character with code point > 127 (non-ASCII)
|
|
128
|
+
return /[\u0080-\uFFFF]/.test(str);
|
|
129
|
+
}
|
|
86
130
|
|
|
131
|
+
function stringToHex(str) {
|
|
132
|
+
return Buffer.from(str, 'utf8').toString('hex');
|
|
87
133
|
}
|
|
88
134
|
|
|
135
|
+
|
|
89
136
|
module.exports = wrapQuery;
|