I used the lock in this loop but the correct data is printed on its console log, and the SQL query did not work . The inserted data on MySQL is the last variable of the loop. I thought this is due to writing MySQL speed but it does not know how to fix it. Any remedy? Thank you
module.exports = function (callback) {Image from queryGetForSend = "SELECT * where send_request is zero and post_request is not faucet and year (moderate_time) = year (curdate) and months (Moderate_time) = months (curdate ()) and (time (moderate_time) & lt; (curtime () - 15)); "; Conn.query (queryGetForSend, function (err, rows, fields) {in rows} {if (rows [i] .post_request == 'approve') {resultSend = 1} else {resultSend = 2} var fileID = Rows [i] .img_md5; QueryString = fileID + "=" + resultSend; // Request URL: "http://im-api1.webpurify.com/image_queue/results/?key=" var d = new date (); Date.masks.default = 'YYYY-MM-DD hh: mm: ss'; SendTime = d.format (); (Function (queryString, sendTime) {querySent = "Image SET send_request = 1, result_sent = '" Update + QueryString + "', send_time = '" + sendTime + "' WHERE send_request is tap and no need for post and year (Medium_time) = year (curdate) and month (medium_time) = month (curdate) and (time (Moderate_time) & lt; (curtime () - 15)) ;; conn.query (querySent, function (fault, lines) , Field) {if (mistake) is confused, console.log ("http://google.com?key =" + key + "& amp;" + queryString ";});}) (Q urstring, sendtime) ; (Function (querystring) {request.get ("http://google.com" + key + "& amp; + Query Tring, function (err, race, body) {});}) (Kweristring); } // callback (rows); }); };
two suggestions:
-
Avoid joining SQL queries, instead using placeholder or ready statement (if you take care of security).
-
Use
array.forEach ()
instead of a regular one to avoid accidental use of variables set within the for-loop for-loop Close:conn.query (queryGetForSend, function (err, rows, field) {if (err); Rows.forEach (function) {var resultSend; if (row.post_request == 'Approval') {resultSend = 1} and {resultSend = 2} var fileID = row.img_md5; var queryString = fileID + '=' + ResultSend; var d = new date (); Date.Masks.default = ' YYYY-MM-DD hh: mm: ss '; var sendTime = d.format (); var query =' update image SET send_request = 1, result_cent =?, Send_time =? Where send_request is tap and post_ Ndest null and year (medium_time) = year (curdate) and month (moderate_time) = months (curdate) and (time (moderate_time) & lt; (curium) - 15)); 'conn.query QuerySent, [queryString, sendTime], function (mistake) {if (mistake) mess; console.log ('http://google.com?key=' + key + 'and' + queryString);}); Request.get ('http://google.com?key=' + key + '& amp; + Query string, function (error, race, body) {}); }); });
Comments
Post a Comment