diff --git a/cf/src/connection.js b/cf/src/connection.js index 8e79170a..328f938b 100644 --- a/cf/src/connection.js +++ b/cf/src/connection.js @@ -551,6 +551,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose query = results = errorResponse = null result = new Result() + rows = 0 connectTimer.cancel() if (initial) { diff --git a/cjs/src/connection.js b/cjs/src/connection.js index 07f67167..2f00d181 100644 --- a/cjs/src/connection.js +++ b/cjs/src/connection.js @@ -549,6 +549,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose query = results = errorResponse = null result = new Result() + rows = 0 connectTimer.cancel() if (initial) { diff --git a/deno/src/connection.js b/deno/src/connection.js index 796725de..0c0be9ec 100644 --- a/deno/src/connection.js +++ b/deno/src/connection.js @@ -552,6 +552,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose query = results = errorResponse = null result = new Result() + rows = 0 connectTimer.cancel() if (initial) { diff --git a/src/connection.js b/src/connection.js index 1b1cccde..03201df8 100644 --- a/src/connection.js +++ b/src/connection.js @@ -549,6 +549,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose query = results = errorResponse = null result = new Result() + rows = 0 connectTimer.cancel() if (initial) { diff --git a/tests/index.js b/tests/index.js index 23e6c4d4..297a66a7 100644 --- a/tests/index.js +++ b/tests/index.js @@ -67,6 +67,16 @@ t('Result has command', async() => ['SELECT', (await sql`select 1`).command] ) +t('Result is not sparse after a query errors mid row-stream', async() => { + const sql = postgres({ ...options, max: 1 }) + // Streams two rows, then errors on the third (division by zero), so the + // ErrorResponse arrives after DataRow messages and CommandComplete never fires. + await sql`select n, 1 / (3 - n) as boom from generate_series(1, 5) n`.catch(() => {}) + const result = await sql`select x from generate_series(1, 3) x` + await sql.end() + return ['3:1,2,3', result.length + ':' + result.map(r => r.x).join(',')] +}) + t('Create table', async() => ['CREATE TABLE', (await sql`create table test(int int)`).command, await sql`drop table test`] )