Updating a MySQL table with CURRENT_TIMESTAMP in node.js

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

Node.js Code

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

But it works if I 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 in mysql (using Navicat), the row is updated with the current timestamp!

Direct SQL query

 UPDATE listings SET job_checkout_timestamp = CURRENT_TIMESTAMP WHERE listing_id = 1515; 

Something went wrong?

+4
source share
1 answer

It seems that node.js can convert input variables to string,
and do current_timestamp as a string, not mysql variables,
replace current_timestamp with a synonym function call, for example: -

 now() current_timestamp() 

should fix the problem

+1
source

Source: https://habr.com/ru/post/1383334/


All Articles