Comments (5)
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.
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.
Sure! Sounds like fun.
from node-postgres.
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.
Closing since this fix was merged in #56
from node-postgres.
Related Issues (20)
- bind message supplies 1 parameters, but prepared statement "" requires 8 HOT 2
- Inserting now() at time zone 'utc' gives invalid results HOT 4
- Errors with Vite+Vue / Nuxt+Vue HOT 4
- How to avoid serialization when using setTypeParser? HOT 4
- Procedure names being converted HOT 1
- [Question] How to print parameterize query? HOT 1
- error: relation "users" does not exist HOT 5
- [question] How to prevent database disconnects from crashing Node.js? HOT 1
- Timezone not set on pool event 'connect' HOT 2
- Fails creating pg client on FIPS environment HOT 1
- Unexpected NULL timestamp during some queries HOT 3
- Type of result.rows is any[][] instead of any[] ? HOT 1
- GSS authorization to connect to the database.
- [question] would a PR that adds JSDOC be welcome?
- Pg is ignoring the time zone ( 'Asia/Kolkata' ) that I provided and is returning time into UTC format. I tried converting the time back to my local time but it is not returnng as expected HOT 2
- pg-connection-string: Shouldn't idleTimeoutMillis be considered? For pool usage patterns?
- Clarification: Does pool.end() close clients created with pool.connect() HOT 1
- PG COPY via PG pool
- Readable never recieving 'end' event on COPY stream
- How to avoid statement preparation with `pg-cursor` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-postgres.