Skip to content

Commit

Permalink
Fix return value of unsafe query with multiple statements
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Dec 28, 2019
1 parent df46f73 commit 748f198
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ function Backend({
}

function RowDescription(x) {
if (backend.query.result.command) {
backend.query.results = backend.query.results || [backend.query.result]
backend.query.results.push(backend.query.result = [])
backend.query.result.count = null
backend.query.statement.columns = null
}

rows = 0

if (backend.query.statement.columns)
Expand Down
2 changes: 1 addition & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function Connection(options = {}) {
? (backend.query ? backend.query.reject(err) : error(err))
: (backend.query && backend.query.resolve(backend.query.stream
? backend.query.result.count
: backend.query.result))
: (backend.query.results || backend.query.result)))

backend.query = backend.error = null
timeout && queries.length === 0 && idle()
Expand Down
4 changes: 2 additions & 2 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ t('Multiple queries', async() => {
t('Multiple statements', async() =>
[2, await sql.unsafe(`
select 1 as x;
select 2 as x;
`).then(([, x]) => x.x)]
select 2 as a;
`).then(([, [x]]) => x.a)]
)

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

0 comments on commit 748f198

Please sign in to comment.