5

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?

Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
  • Can you try `select CURRENT_TIMESTAMP;`? – ajreal Nov 27 '11 at 19:04
  • Yes, `select CURRENT_TIMESTAMP` works both directly and through node.js – Nyxynyx Nov 27 '11 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. – ajreal Nov 27 '11 at 19:15
  • you will have the same problem if you try with "null" value. Check this out : https://github.com/felixge/node-mysql/blob/master/lib/client.js#L145 – malletjo Nov 28 '11 at 02:35

1 Answers1

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

ajreal
  • 46,720
  • 11
  • 89
  • 119