0

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!

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
flurp
  • 109
  • 3
  • 12
  • I am not sure who said this was associated to the link at the top of the page, but it is not for several obvious reasons. They were using MSSQL while I am using MySQL. I am using Node JS and they were using PHP. They had no output in the query(at least partially because they were using MSSQL and not MySQL.). The specific issue I am having is directly related to the OUT parameter. – flurp May 02 '22 at 03:22
  • What are you talking about? The duplicate is about MySQL and Node.JS. – Mark Rotteveel May 23 '22 at 10:43

0 Answers0