Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: brianc/node-postgres
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: pg@8.4.0
Choose a base ref
...
head repository: brianc/node-postgres
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: pg@8.4.1
Choose a head ref
  • 8 commits
  • 7 files changed
  • 1 contributor

Commits on Oct 8, 2020

  1. Copy the full SHA
    9c678e1 View commit details
  2. Remove fix to fail tests

    brianc committed Oct 8, 2020
    Copy the full SHA
    17e7e9e View commit details
  3. Apply fix

    brianc committed Oct 8, 2020
    Copy the full SHA
    f55d879 View commit details
  4. Update comments

    brianc committed Oct 8, 2020
    Copy the full SHA
    b45051d View commit details
  5. Copy the full SHA
    d31486f View commit details
  6. Copy the full SHA
    dd3ce61 View commit details
  7. Comments & cleanup

    brianc committed Oct 8, 2020
    Copy the full SHA
    d8681fc View commit details
  8. Publish

     - pg-cursor@2.4.1
     - pg-query-stream@3.3.1
     - pg@8.4.1
    brianc committed Oct 8, 2020
    Copy the full SHA
    36342c9 View commit details
4 changes: 2 additions & 2 deletions packages/pg-cursor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-cursor",
"version": "2.4.0",
"version": "2.4.1",
"description": "Query cursor extension for node-postgres",
"main": "index.js",
"directories": {
@@ -17,6 +17,6 @@
"license": "MIT",
"devDependencies": {
"mocha": "^7.1.2",
"pg": "^8.4.0"
"pg": "^8.4.1"
}
}
6 changes: 3 additions & 3 deletions packages/pg-query-stream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-query-stream",
"version": "3.3.0",
"version": "3.3.1",
"description": "Postgres query result returned as readable stream",
"main": "index.js",
"scripts": {
@@ -26,12 +26,12 @@
"concat-stream": "~1.0.1",
"eslint-plugin-promise": "^3.5.0",
"mocha": "^7.1.2",
"pg": "^8.4.0",
"pg": "^8.4.1",
"stream-spec": "~0.3.5",
"stream-tester": "0.0.5",
"through": "~2.3.4"
},
"dependencies": {
"pg-cursor": "^2.4.0"
"pg-cursor": "^2.4.1"
}
}
48 changes: 27 additions & 21 deletions packages/pg/lib/query.js
Original file line number Diff line number Diff line change
@@ -96,39 +96,28 @@ class Query extends EventEmitter {
}
}

handleCommandComplete(msg, con) {
handleCommandComplete(msg, connection) {
this._checkForMultirow()
this._result.addCommandComplete(msg)
// need to sync after each command complete of a prepared statement
if (this.isPreparedStatement) {
con.sync()
// if we were using a row count which results in multiple calls to _getRows
if (this.rows) {
connection.sync()
}
}

// if a named prepared statement is created with empty query text
// the backend will send an emptyQuery message but *not* a command complete message
// execution on the connection will hang until the backend receives a sync message
handleEmptyQuery(con) {
if (this.isPreparedStatement) {
con.sync()
}
}

handleReadyForQuery(con) {
if (this._canceledDueToError) {
return this.handleError(this._canceledDueToError, con)
}
if (this.callback) {
this.callback(null, this._results)
// since we pipeline sync immediately after execute we don't need to do anything here
// unless we have rows specified, in which case we did not pipeline the intial sync call
handleEmptyQuery(connection) {
if (this.rows) {
connection.sync()
}
this.emit('end', this._results)
}

handleError(err, connection) {
// need to sync after error during a prepared statement
if (this.isPreparedStatement) {
connection.sync()
}
if (this._canceledDueToError) {
err = this._canceledDueToError
this._canceledDueToError = false
@@ -141,6 +130,16 @@ class Query extends EventEmitter {
this.emit('error', err)
}

handleReadyForQuery(con) {
if (this._canceledDueToError) {
return this.handleError(this._canceledDueToError, con)
}
if (this.callback) {
this.callback(null, this._results)
}
this.emit('end', this._results)
}

submit(connection) {
if (typeof this.text !== 'string' && typeof this.name !== 'string') {
return new Error('A query must have either text or a name. Supplying neither is unsupported.')
@@ -173,7 +172,14 @@ class Query extends EventEmitter {
portal: this.portal,
rows: rows,
})
connection.flush()
// if we're not reading pages of rows send the sync command
// to indicate the pipeline is finished
if (!rows) {
connection.sync()
} else {
// otherwise flush the call out to read more rows
connection.flush()
}
}

// http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
2 changes: 1 addition & 1 deletion packages/pg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg",
"version": "8.4.0",
"version": "8.4.1",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [
"database",
10 changes: 10 additions & 0 deletions packages/pg/test/integration/client/prepared-statement-tests.js
Original file line number Diff line number Diff line change
@@ -174,5 +174,15 @@ var suite = new helper.Suite()
checkForResults(query)
})

suite.testAsync('with no data response and rows', async function () {
const result = await client.query({
name: 'some insert',
text: '',
values: [],
rows: 1,
})
assert.equal(result.rows.length, 0)
})

suite.test('cleanup', () => client.end())
})()
20 changes: 20 additions & 0 deletions packages/pg/test/integration/gh-issues/1105-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const pg = require('../../../lib')
const helper = require('../test-helper')
const suite = new helper.Suite()

suite.testAsync('timeout causing query crashes', async () => {
const client = new helper.Client()
await client.connect()
await client.query('CREATE TEMP TABLE foobar( name TEXT NOT NULL, id SERIAL)')
await client.query('BEGIN')
await client.query("SET LOCAL statement_timeout TO '1ms'")
let count = 0
while (count++ < 5000) {
try {
await client.query('INSERT INTO foobar(name) VALUES ($1)', [Math.random() * 1000 + ''])
} catch (e) {
await client.query('ROLLBACK')
}
}
await client.end()
})
6 changes: 6 additions & 0 deletions packages/pg/test/integration/gh-issues/2085-tests.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,12 @@ var assert = require('assert')

const suite = new helper.Suite()

// allow skipping of this test via env var for
// local testing when you don't have SSL set up
if (process.env.PGTESTNOSSL) {
return
}

suite.testAsync('it should connect over ssl', async () => {
const ssl = helper.args.native
? 'require'