6

I am using node-mysql to update a MySQL database table from node.js. I want to update the timestamp column of a row with CURRENT_TIMESTAMP. However, no changes seem to be made by node.js using the following code:

Node.js Code

client.query('UPDATE listings SET job_checkout_timestamp = CURRENT_TIMESTAMP WHERE listing_id = 1515');

But works if I were to replace CURRENT_TIMESTAMP with a javascript time function, like new Date()

client.query('UPDATE listings SET job_checkout_timestamp = ? WHERE listing_id = 1515', [ new Date() ]);

However, if I were to execute the same SQL query directly into mysql (using Navicat), the row gets updated with the current timestamp!

Direct SQL Query

UPDATE listings SET job_checkout_timestamp = CURRENT_TIMESTAMP WHERE listing_id = 1515;

Did something go wrong somewhere?

4
  • Can you try select CURRENT_TIMESTAMP;? Commented Nov 27, 2011 at 19:04
  • Yes, select CURRENT_TIMESTAMP works both directly and through node.js Commented Nov 27, 2011 at 19:08
  • I wondering is it node.js convert all the value to string instead of mysql variable. So, you should replace it now(), which is the same as current_timestamp. Hopefully node.js won't do any changes to function call. Commented Nov 27, 2011 at 19:15
  • you will have the same problem if you try with "null" value. Check this out : github.com/felixge/node-mysql/blob/master/lib/client.js#L145 Commented Nov 28, 2011 at 2:35

1 Answer 1

2

It seems that node.js might convert the input variables into string,
and make the current_timestamp as string rather than mysql variables,
by replace the current_timestamp to synonym function call like :-

now()
current_timestamp()

should fix the problem

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.