Skip to content

client.query(sqlString, params[], function) alters the given params[] #750

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

Closed
ngervasi opened this issue Mar 18, 2015 · 7 comments
Closed

Comments

@ngervasi
Copy link

When supplying a parameters array to client.query the given array is modified (in my case it originally was an array of numbers and got transformed to an array of strings). This is not correct behaviour, I see the problem in the source code (query.js, line 143):

self.values[i] = utils.prepareValue(self.values[i]);

If transformation is needed it should be done on a clone of the passed array so that it doesn't break any logic in case the original array is reused somewhere else after the query.

I think a quick fix would be to change (query.js, line 14) from:

this.values = config.values;

to

this.values = config.values.slice();
@brianc
Copy link
Owner

brianc commented Mar 28, 2015

yeah that totally sucks! Sorry about that. Do you wanna submit a PR for that change w/ a little test? If not, I can bang one together.

@ngervasi
Copy link
Author

Hi Brian, maybe it's faster if you do the change directly, I've never done a Pull request... but I promise I will start learning and contribute :)

@vitaly-t
Copy link
Contributor

@ngervasi
Many people are on the fence like yourself, so was I, for a while, till I tried and then was laughing how easy it really was ;) And if you don't like GIT, use Source Tree - it is a huge help: http://www.sourcetreeapp.com/

ngervasi added a commit to ngervasi/node-postgres that referenced this issue Mar 30, 2015
@ngervasi
Copy link
Author

You're right Vitaly, it's time to actively contribute to the project, I sent my pull requests but I didn't create the tests, I'm unsure about how to do that properly. Can someone give me a hint about it? I'm not familiar with node tests... btw: thanks Brian for this impressive project!

@vitaly-t
Copy link
Contributor

All tests are in \test sub-folder. Typically, you either amend an existing test or add a new one. Given the nature of the issue, I'd say you have to create a new test. The syntax is very easy, and for details just look at the test library ;)

@vitaly-t
Copy link
Contributor

@brianc , @ngervasi
Any progress here? I'm stuck with some tests here on parameters, they are altered, unexpectedly.

This is kind of a big issue.

@ngervasi
Copy link
Author

Unfortunately not, I'm very busy and I wasn't able to learn how to setup the test, if you have time have a look at my patch and feel free to submit it on your own. Sorry bout that but it's a tough time.

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

3 participants