The heart of this problem is being able to see the OUT parameter in Node JS. I am getting a parsing error in Node JS every time I try to run it. It is this specific line of code that the error is referencing every time:
let sql = "CALL GetUsername(?,@usernameOut); select @usernameOut";
I am using MySQL 5.7 to create this stored procedure:
CREATE DEFINER=`MySQLDB`@`%` PROCEDURE `GetUsername`(
IN userIdVal INT,
OUT usernameOut NVARCHAR(45)
)
BEGIN
SELECT username INTO usernameOut
FROM players
WHERE userId = userIdVal AND avatarId = 0 AND Gender IS NULL AND active = 1 ;
END
I am calling it in Node JS like this:
let connection = mysql.createConnection(config,{multipleStatements: true});
let sql = "CALL GetUsername(?,@usernameOut); select @usernameOut";
let myRows;
await connection.query(sql, [param1],
function(err,rows){
console.log("INSIDE MySQL1"); (shortened to show the relevant code)
I am consistently getting this error:
ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select @usernameOut' at line 1
I have looked at around 40 articles and everything I am using seems to match what I have seen. I have several other stored procedures working fine in these APIs but this is the first one I have set up an Out param for. I am triggering this through Postman as I always test everything there until I know it works. I need some fresh eyes on this and help would be greatly appreciated!