Giter VIP home page Giter VIP logo

Comments (5)

bdunavant avatar bdunavant commented on July 30, 2024

For what it's worth, for inputs I'd treat undefined as a null value. It also makes it a one line change to fix at that point I believe :)

from node-postgres.

brianc avatar brianc commented on July 30, 2024

I think undefined should probably be treated as null. I've bit bitten by
this same issue in some apps I've developed with node-postgres. Interested
in forking & pull-requesting? I've not I'll pound this out myself, but
might be fun for you, yeah? ;)

On Wed, Oct 12, 2011 at 9:46 PM, Brian Dunavant <
[email protected]>wrote:

If you pass an undefined value as a parameter to a query it crashes when
trying to bind. Unfortunately with a stack trace that makes it very
difficult to find your error (at least without putting console.logs inside
of _pulseQuery to figure out which query is running).

Not sure what the correct solution would be here. Treat it as NULL?
Throw an error?

Test case:

var pg = require('pg');
var conString = "tcp://user:pass@localhost/postgres";
pg.connect( conString, function(err, client) {
client.query("select $1 as foo", [ undefined ], function(err, result) {
console.log(result.rows[0].foo);
});
});

Crash output:

TypeError: Cannot call method 'toString' of undefined
at [object Object].bind
(/Users/brian/node_modules/pg/lib/connection.js:138:17)
at [object Object].prepare
(/Users/brian/node_modules/pg/lib/query.js:136:14)
at [object Object].submit
(/Users/brian/node_modules/pg/lib/query.js:95:10)
at [object Object]._pulseQueryQueue
(/Users/brian/node_modules/pg/lib/client.js:140:24)
at [object Object].query
(/Users/brian/node_modules/pg/lib/client.js:164:8)
at assign_pending_items (/Users/brian/lucre/app.js:291:8)
at /Users/brian/lucre/app.js:213:3
at callbacks
(/Users/brian/node_modules/express/lib/router/index.js:272:11)
at requireLogin (/Users/brian/lucre/app.js:46:3)
at callbacks
(/Users/brian/node_modules/express/lib/router/index.js:272:11)

Reply to this email directly or view it on GitHub:
#55

from node-postgres.

bdunavant avatar bdunavant commented on July 30, 2024

Sure! Sounds like fun.

from node-postgres.

bdunavant avatar bdunavant commented on July 30, 2024

The response for this is in issue #56 which got created when I submitted the code. Sorry, didn't know how to make it reference this issue.

from node-postgres.

bdunavant avatar bdunavant commented on July 30, 2024

Closing since this fix was merged in #56

from node-postgres.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.