Error: ER_PARSE_ERROR: You have an error in your SQL syntax; error trying to make an requisition using node to a mysql database

type here

Im using node.js to connect an react native application to a mysql database.

I created a procedure that checks if the user is loggin for the first time. If is loggin for the first time will return 2, if user loggin for the firs time but the password is incorrect will return 3.

If is not loggin for the first time and the password is correct will return a json with a table data
If is not loggin for the first time and the password is incorrect will return 3.

CREATE DEFINER=`root`@`localhost` PROCEDURE `loginColaborador`(
    IN email varchar(100), 
    IN senhaColaborador varchar(255), 
    out resposta varchar(16383)
)
BEGIN
    declare padrao varchar(50);
    declare atual varchar(50);

    
    set padrao = (select senhaColaboradorPadrao from tbcolaborador where emailColaborador = email);
    set atual = (select senhaColaboradorAtual from tbcolaborador where emailColaborador = email);
    
    SET resposta = '';
    
    if padrao is null then
        if(atual = senhaColaborador)then
            SELECT CONCAT('[', GROUP_CONCAT(JSON_OBJECT('Id', idquestionario, 'Questionario', nomeQuestionario)), ']')
            INTO resposta
            FROM tbquestionario q
            WHERE q.idempresa = (SELECT idempresa FROM tbcolaborador WHERE emailColaborador = email);

        else
            set resposta =  '1';
        end if;
    else
        if (select senhaColaboradorPadrao from tbcolaborador where emailColaborador = email) = senhaColaborador then
            set resposta =  '2';
        else
            set resposta =  '3';
        end if;
    end if;
END

when im testing using mysql commands at workbench it works perfectly and i get my answers correct

CALL loginColaborador("[email protected]", "abcd", @resposta);
SELECT @resposta as resposta;

but when i try using my requisition at postman, using the application returns an mysql syntax errorr

requisition node:

app.post('/api/loginColaborador', (req, res) => {
    const { email, senhaColaborador } = req.body;

    const query = 'CALL loginColaborador(?, ?, @resposta); (SELECT @resposta as resposta);';
    pool.query(query, [email, senhaColaborador], (error, results) => {
        
        if (error) {
            console.error(error);
            return res.status(500).json({ message: 'Erro ao fazer login' });
        }
        
        // Pegar o valor da variável de saída `resposta`
        const resposta = results[1][0].resposta;
        
        if (resposta === '1') {
            return res.status(401).json({ message: 'Senha atual incorreta' });
        } else if (resposta === '2') {
            return res.status(200).json({ message: 'Senha padrão correta' });
        } else if (resposta === '3') {
            return res.status(401).json({ message: 'Senha padrão incorreta' });
        } else {
            return res.status(200).json({ questionarios: JSON.parse(resposta) });
        }
    });
});

error:
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 @resposta as resposta)’ at line 1
at Sequence._packetToError (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesmysqllibprotocolsequencesSequence.js:47:14)
at Query.ErrorPacket (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesmysqllibprotocolsequencesQuery.js:79:18)
at Protocol._parsePacket (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesmysqllibprotocolProtocol.js:291:23)
at Parser._parsePacket (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesmysqllibprotocolParser.js:433:10)
at Parser.write (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesmysqllibprotocolParser.js:43:10)
at Protocol.write (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesmysqllibprotocolProtocol.js:38:16)
at Socket. (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesmysqllibConnection.js:88:28)
at Socket. (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesmysqllibConnection.js:526:10)
at Socket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:559:12)
——————–
at Pool.query (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesmysqllibPool.js:199:23)
at C:UsersenzzoOneDriveDesktopnodemysqlindex.js:69:10
at Layer.handle [as handle_request] (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesexpresslibrouterlayer.js:95:5)
at next (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesexpresslibrouterroute.js:149:13)
at Route.dispatch (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesexpresslibrouterroute.js:119:3)
at Layer.handle [as handle_request] (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesexpresslibrouterlayer.js:95:5)
at C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesexpresslibrouterindex.js:284:15
at Function.process_params (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesexpresslibrouterindex.js:346:12)
at next (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulesexpresslibrouterindex.js:280:10)
at cors (C:UsersenzzoOneDriveDesktopnodemysqlnode_modulescorslibindex.js:188:7) {
code: ‘ER_PARSE_ERROR’,
errno: 1064,
sqlMessage: “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 @resposta as resposta)’ at line 1”,
sqlState: ‘42000’,
index: 0,
sql: “CALL loginColaborador(‘[email protected]’, ‘abcd’, @resposta); (SELECT @resposta as resposta);”
}

New contributor

enzz5 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật