Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cf/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
function ReadyForQuery(x) {
query && query.options.simple && query.resolve(results || result)
query = results = null
rows = 0
result = new Result()
connectTimer.cancel()

Expand Down
1 change: 1 addition & 0 deletions cjs/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
function ReadyForQuery(x) {
query && query.options.simple && query.resolve(results || result)
query = results = null
rows = 0
result = new Result()
connectTimer.cancel()

Expand Down
19 changes: 19 additions & 0 deletions cjs/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2614,3 +2614,22 @@ t('Ensure reserve on query throws proper error', async() => {
'wat', x, reserved.release()
]
})

t('Ensure rows count is cleared before performing new query on a connection', async() => {
const sql = postgres({ idle_timeout, max: 1 }) // eslint-disable-line
await sql`create table table_causing_error(name text,age int)`
await sql`insert into table_causing_error values('John', 20)`
await sql`insert into table_causing_error values('Jane', 21)`
await sql`insert into table_causing_error values('Jim', 0)`

await sql`create table some_other_table(title text,amount int)`
await sql`insert into some_other_table values ('a', 100), ('b', 200), ('c', 300), ('d', 400), ('e', 500), ('f', 600)`

const rows_count_before_error = await sql`select * from some_other_table`
await sql`select * from table_causing_error where 1000/age > 0`.catch(e => e)
const rows_count_after_error = await sql`select * from some_other_table`

return [
rows_count_before_error, rows_count_after_error
]
})
1 change: 1 addition & 0 deletions deno/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
function ReadyForQuery(x) {
query && query.options.simple && query.resolve(results || result)
query = results = null
rows = 0
result = new Result()
connectTimer.cancel()

Expand Down
18 changes: 18 additions & 0 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2617,4 +2617,22 @@ t('Ensure reserve on query throws proper error', async() => {
]
})

t('Ensure rows count is cleared before performing new query on a connection', async() => {
const sql = postgres({ idle_timeout, max: 1 }) // eslint-disable-line
await sql`create table table_causing_error(name text,age int)`
await sql`insert into table_causing_error values('John', 20)`
await sql`insert into table_causing_error values('Jane', 21)`
await sql`insert into table_causing_error values('Jim', 0)`

await sql`create table some_other_table(title text,amount int)`
await sql`insert into some_other_table values ('a', 100), ('b', 200), ('c', 300), ('d', 400), ('e', 500), ('f', 600)`

const rows_count_before_error = await sql`select * from some_other_table`
await sql`select * from table_causing_error where 1000/age > 0`.catch(e => e)
const rows_count_after_error = await sql`select * from some_other_table`

return [
rows_count_before_error, rows_count_after_error
]
})
;globalThis.addEventListener("unload", () => Deno.exit(process.exitCode))
1 change: 1 addition & 0 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
function ReadyForQuery(x) {
query && query.options.simple && query.resolve(results || result)
query = results = null
rows = 0
result = new Result()
connectTimer.cancel()

Expand Down
22 changes: 22 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2614,3 +2614,25 @@ t('Ensure reserve on query throws proper error', async() => {
'wat', x, reserved.release()
]
})

t('Ensure rows count is cleared before performing new query on a connection', async() => {
const sql = postgres({ idle_timeout, max: 1 }) // eslint-disable-line
await sql`create table table_causing_error(name text,age int)`
await sql`insert into table_causing_error values('John', 20)`
await sql`insert into table_causing_error values('Jane', 21)`
await sql`insert into table_causing_error values('Jim', 0)`

await sql`create table some_other_table(title text,amount int)`
await sql`insert into some_other_table values ('a', 100), ('b', 200), ('c', 300), ('d', 400), ('e', 500), ('f', 600)`

const rows_count_before_error = await sql`select * from some_other_table`
await sql`select * from table_causing_error where 1000/age > 0`.catch(e => e)
const rows_count_after_error = await sql`select * from some_other_table`

await sql`drop table table_causing_error`
await sql`drop table some_other_table`

return [
rows_count_before_error.length, rows_count_after_error.length
]
})