Skip to content

Commit 748f198

Browse files
committed
Fix return value of unsafe query with multiple statements
1 parent df46f73 commit 748f198

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

lib/backend.js

+7
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ function Backend({
174174
}
175175

176176
function RowDescription(x) {
177+
if (backend.query.result.command) {
178+
backend.query.results = backend.query.results || [backend.query.result]
179+
backend.query.results.push(backend.query.result = [])
180+
backend.query.result.count = null
181+
backend.query.statement.columns = null
182+
}
183+
177184
rows = 0
178185

179186
if (backend.query.statement.columns)

lib/connection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function Connection(options = {}) {
131131
? (backend.query ? backend.query.reject(err) : error(err))
132132
: (backend.query && backend.query.resolve(backend.query.stream
133133
? backend.query.result.count
134-
: backend.query.result))
134+
: (backend.query.results || backend.query.result)))
135135

136136
backend.query = backend.error = null
137137
timeout && queries.length === 0 && idle()

tests/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ t('Multiple queries', async() => {
681681
t('Multiple statements', async() =>
682682
[2, await sql.unsafe(`
683683
select 1 as x;
684-
select 2 as x;
685-
`).then(([, x]) => x.x)]
684+
select 2 as a;
685+
`).then(([, [x]]) => x.a)]
686686
)
687687

688688
t('throws correct error when authentication fails', async() => {

0 commit comments

Comments
 (0)