Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"invalid message format" error when string to write contains a NUL character #10

Closed
rchampeimont opened this issue Oct 26, 2016 · 2 comments

Comments

@rchampeimont
Copy link

rchampeimont commented Oct 26, 2016

When I send a string with a \0 in it, I get an "invalid message format" error.

var sql = require('sql-bricks-postgres');

// pool is the "pool" object provided by module pg 6.1.0
pool.connect(function(error, client, done) {
  if (error) return console.error(error.stack);

  client.query(sql.insertInto('test', 's').values('test\0').toString(), function(error, result) {
    if (error) return console.error(error.stack);
  });
});

I get:

error: invalid message format
at Connection.parseE (/Users/raphaelchampeimont/nodejs-doctrine/node_modules/pg/lib/connection.js:554:11)
at Connection.parseMessage (/Users/raphaelchampeimont/nodejs-doctrine/node_modules/pg/lib/connection.js:381:17)
at TLSSocket. (/Users/raphaelchampeimont/nodejs-doctrine/node_modules/pg/lib/connection.js:117:22)
at emitOne (events.js:77:13)
at TLSSocket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:153:18)
at TLSSocket.Readable.push (_stream_readable.js:111:10)
at TLSWrap.onread (net.js:536:20)

I am using sql-bricks-postgres@0.4.2

@Suor
Copy link
Owner

Suor commented Oct 26, 2016

You should never use .toString() when making actual query, use .toParams(). You might also want to look at pg-bricks:

var db = require('pg-bricks').configure(process.env.DATABASE_URL);

db.insertInto('test', 's').values('test\0').run(callback);

The syntax for making queries is the same, but you get .run() and other executors.

@rchampeimont
Copy link
Author

OK thank you. I now get "invalid byte sequence for encoding "UTF8": 0x00" but I guess this is an "expected" error now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants