-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathissue-396-print-throw.js
More file actions
53 lines (46 loc) · 1.53 KB
/
Copy pathissue-396-print-throw.js
File metadata and controls
53 lines (46 loc) · 1.53 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
49
50
51
52
53
// Reproduces issue #396:
// PRINT followed by THROW swallows the THROW message and surfaces
// 'Associated statement is not prepared' (HY007) instead.
//
// Run with the test env file so we pick up the same connection string
// the mocha tests use:
// npx env-cmd -e test node samples/javascript/issue-396-print-throw.js
const { TestEnv } = require('../../test/env/test-env')
const env = new TestEnv()
function runQuery (con, label, sqlText) {
return new Promise((resolve) => {
con.query(sqlText, (err) => {
console.log(`--- ${label} ---`)
console.log('SQL :', sqlText)
if (err) {
console.log('ERR :', err.message)
console.log(' sqlstate=', err.sqlstate, 'code=', err.code)
} else {
console.log('OK : no error')
}
resolve()
})
})
}
async function main () {
await env.open()
const con = env.theConnection
try {
// Baseline: bare THROW surfaces correctly
await runQuery(con, 'Q1: bare THROW', "THROW 50001, 'BOOM', 1")
// Bug: PRINT before THROW causes THROW message to be swallowed
await runQuery(con, 'Q2: PRINT + THROW', "PRINT 'BAR' ; THROW 50000, 'BOOM BOOM', 1")
// Variations to map the surface area
await runQuery(con, 'Q3: SELECT + THROW', "SELECT 1 AS x ; THROW 50002, 'BOOM3', 1")
await runQuery(con, 'Q4: RAISERROR after PRINT',
"PRINT 'BAR' ; RAISERROR('BOOM4', 16, 1)")
} finally {
await env.close()
}
}
main().then(() => {
console.log('done')
}).catch((e) => {
console.error('main failed', e)
process.exit(1)
})