-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathtest_output_params.js
More file actions
48 lines (39 loc) · 1.3 KB
/
test_output_params.js
File metadata and controls
48 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const sql = require('.');
async function test() {
try {
const connStr = 'Driver={ODBC Driver 17 for SQL Server};Server=127.0.0.1,1433;Database=node;UID=node_user;PWD=StrongPassword123!;TrustServerCertificate=yes;';
// First create the stored procedure
const conn = await sql.promises.open(connStr);
try {
await conn.promises.query(`DROP PROCEDURE test_sp_get_str_str`);
} catch (e) {
// Ignore if doesn't exist
}
await conn.promises.query(`
CREATE PROCEDURE test_sp_get_str_str(
@id INT,
@name varchar(20) OUTPUT,
@company varchar(20) OUTPUT
) AS
BEGIN
SET @name = 'name'
SET @company = 'company'
RETURN 99;
END
`);
// Call the procedure
const result = await conn.promises.callProc('test_sp_get_str_str', [1]);
console.log('Result:', result);
console.log('Output:', result.output);
console.log('Output JSON:', JSON.stringify(result.output));
// Check result
const expected = [99, 'name', 'company'];
console.log('Expected:', expected);
console.log('Match:', JSON.stringify(result.output) === JSON.stringify(expected));
await conn.promises.close();
} catch (err) {
console.error('Error:', err);
process.exit(1);
}
}
test();