I want to write an interface to update user information,
UPDATE user_information SET the parameters here are not fixed where uid =?
could be name=?
or name=?, sex=?
or name=?, sex=?, qq=?
Please how should I achieve it?
< H2 > question 2 < / H2 >when using nodejs to operate a database, SET is followed by?? What does it mean?
UPDATE demo SET? Where id=?
app.all("/information/update", (req, res, next) => {
let sess = req.session;
let result = {
code: "0000",
data: {},
message: "fail",
detail: "",
function: "prize",
number: 0
};
let params = req.body;
let selectSql = "select name from user_information where uid = ?";
let updateSql = "UPDATE user_information SET name=? where uid = ?";
let name = helper.stringTrim(params.name) || "";
if(sess.loginUserInfo === undefined) {
result["detail"] = "";
res.send(JSON.stringify(result));
} else {
let loginInformation = sess.loginUserInfo;
// console.log("loginInformation == ", loginInformation);
pool.getConnection((err, connection) => {
connection.query(
selectSql,
[loginInformation.uid],
(err, rows) => {
// console.log("rows ==", rows);
if(rows.length === 1) {
result["detail"] = "";
connection.query(
updateSql,
[name, loginInformation.uid],
(err, rows) => {
if(err) {
result["detail"] = "";
res.send(JSON.stringify(result));
} else {
result["detail"] = "0001";
result["message"] = "success";
result["detail"] = "";
res.send(JSON.stringify(result));
}
}
);
} else {
result["detail"] = "";
res.send(JSON.stringify(result));
}
}
);
pool.releaseConnection(connection);
})
}
});