我正在用 expressjs 研究 NodeJS,到目前为止,一切都很好,但我有一个小问题:从 Workbench 调用存储过程一切运行正常,但是 express 中的同一句话(复制/粘贴)显示来自 MySQL 引擎的错误。
{
"desc_status": {
"code": "ER_BAD_NULL_ERROR",
"errno": 1048,
"sqlMessage": "Column 'id_color' cannot be null",
"sqlState": "23000",
"index": 0,
"sql": "CALL pinturas.add_inventory('101', '3');"
},
"code_status": 409
}
这是我的 NodeJS 调用:
let sql = "CALL pinturas.add_inventory(101, 3);";
conn.query(sql, true, (err, filas) => {
if(err){
//next(err);
res.status(409).json({
desc_status: err,
code_status: 409,
});
return;
}
(...)
});
从工作台调用
CALL `pinturas`.`add_inventory`('101', '3');
最后,存储过程:
CREATE DEFINER=`root`@`localhost` PROCEDURE `add_inventory`(
IN _id_color INT(11),
IN _cant INT(11)
)
BEGIN
set @numRows = (select count(*) from stock_colores where id_pintura = 1 and id_color = @_id_color);
if @numRows > 0 then
set @oldCant = (select cant from stock_colores where id_pintura = 1 and id_color = @_id_color);
set @_stock_id = (select stock_id from stock_colores where id_pintura = 1 and id_color = @_id_color);
update stock_colores set cant = (_cant + @oldCant) where stock_id = @_stock_id;
else
insert into stock_colores (id_pintura, id_color, cant) values (1, @_id_color, _cant);
end if;
END
我很感激任何指导。干杯。