我正在使用MySQl和Inquirer的后端节点应用程序上工作,当我运行这部分代码时,我一直收到以下错误消息:“您的SQL语法有错误;请查看与您的MySQL服务器相对应的手册正确的语法版本以在“第1行”附近使用,但我一生都无法确定它的来源?
我尝试浏览应用程序中的MySQL代码以查看是否存在任何错误或错别字,但我似乎找不到任何错误或错别字。
inquirer.prompt([
{
type: 'list',
name: 'monthSelection',
message: 'What month would you like to see?',
choices: ["january", "febuary", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]
},
{
type: 'input',
name: 'yearInput',
message: 'Please enter the year you would like to use:'
}
]).then(function(select) {
console.log(select.monthSelection);
console.log(select.yearInput);
connection.query("SELECT * FROM " + select.monthSelection + "_" + select.yearInput + "_leadsandsales", function(err, res) {
console.log(monthSelection);
if (err) {
console.log("Error, the month and/or year you input does not exist");
inquirer.prompt([
{
type: 'checkbox',
name: 'errChoice',
message: 'Would you like to add this as a new month?',
choices: ["Yes", "No"],
default: "Yes"
}
]).then(function(select) {
if (select.errChoice === "Yes") {
addMonth();
}
else if (select.errChoice === "No") {
mainMenu();
}
});
}
else {
monthSelection = select.monthSelection + "_" + select.yearInput + "_leadsandsales";
}
});
}).then(function() {
connection.query("SELECT * FROM " + monthSelection + "", function(res, err) {
if (err) throw err;
console.table(res);
mainMenu();
})
})
预期结果是在控制台中显示如下表(在MySQL代码中):
CREATE TABLE gnomedepot_products(
item_id BIGINT(12) NOT NUll,
product_name VARCHAR(30) NOT NULL,
department_name VARCHAR(30),
price DECIMAL(7, 2),
stock_quantity INTEGER(4)
);