I'm trying to run a server node with restify. I have this error:
throw (new Error('too few args to sprintf'));
My server node code is:
function callPost(req, res, next) {
var user = {};
user.nombre = req.params.nombre;
user.apellido = req.params.apellido;
user.email = req.params.email;
user.telefono = req.params.telefono;
user.dirig = req.params.dirig;
user.mensaje = req.params.mensaje;
//user.idform = req.params.idform; user.fecha = req.params.fecha;
var formu = "2";
var sql = "call sp_contacto(?,?,?,?,?,?,?,?)";
res.setHeader('Access-Control-Allow-Origin', '*');
connection.query(sql, [user.nombre, user.apellido, user.email, user.telefono, user.dirig, user.mensaje, formu, user.fecha],
function (error, success) {
if (error) throw error;
console.log(success);
res.send(200, success.insertId);
}
);
}
and my stored procedure is:
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_contacto`(
IN nom VARCHAR(100),
IN ape VARCHAR(100),
IN mail VARCHAR(100),
IN tel VARCHAR(100),
IN dirigido VARCHAR(100),
IN maj TEXT,
IN id_form INT,
IN p_fecha DATE
) BEGIN
DECLARE p_idvisitante int DEFAULT 0;
DECLARE existe int DEFAULT 0;
select count_visit(nom, mail) into existe;
IF existe = 0 THEN
CALL insert_visitante(nom, ape, mail, tel);
select id_visit(nom, mail) into p_idvisitante;
CALL insert_visit_form_selec(p_idvisitante, id_form, 6, p_fecha, dirigido);
CALL insert_visit_form_selec(p_idvisitante, id_form, 7, p_fecha, msj);
CALL insert_form_visit(p_idvisitante, id_form);
ELSE
select id_visit(nom, mail) into p_idvisitante;
CALL insert_visit_form_selec(p_idvisitante, id_form, 6, p_fecha, dirigido);
CALL insert_visit_form_selec(p_idvisitante, id_form, 7, p_fecha, msj);
CALL insert_form_visit(p_idvisitante, id_form);
END IF;
END
What is the cause of the error?
The solutions:
console.log(error);
before of:
res.send(200, success.insertId);