I am running the following SQL query:
Executing (default): DROP PROCEDURE IF EXISTS x;
DELIMITER $$
CREATE PROCEDURE x()
BEGIN
# do something
END $$
DELIMITER; $$
Like so:
sequelize.query(query, {
type: sequelize.QueryTypes.SELECT
});
But I get this error (even though it works just fine, if I use any other SQL client):
SequelizeDatabaseError: 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 'DELIMITER $$
CREATE PROCEDURE x()
BEGIN
I already added multipleStatements = true
to my connection config, but it does not do anything.
Update
I ended up using RAW
instead, like so:
sequelize.query(query, {
type: sequelize.QueryTypes.RAW
});
I am running the following SQL query:
Executing (default): DROP PROCEDURE IF EXISTS x;
DELIMITER $$
CREATE PROCEDURE x()
BEGIN
# do something
END $$
DELIMITER; $$
Like so:
sequelize.query(query, {
type: sequelize.QueryTypes.SELECT
});
But I get this error (even though it works just fine, if I use any other SQL client):
SequelizeDatabaseError: 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 'DELIMITER $$
CREATE PROCEDURE x()
BEGIN
I already added multipleStatements = true
to my connection config, but it does not do anything.
Update
I ended up using RAW
instead, like so:
sequelize.query(query, {
type: sequelize.QueryTypes.RAW
});
Share
Improve this question
edited Oct 6, 2018 at 6:19
Domi
asked May 13, 2015 at 13:30
DomiDomi
24.7k19 gold badges104 silver badges132 bronze badges
4
-
Did you add
multipleStatements
tosequelize.options.dialectOptions
? – Jan Aagaard Meier Commented May 14, 2015 at 11:53 -
@JanAagaardMeier I have, and I even added a check to my
mysql/lib/ConnectionConfig.js
, and verified thatoptions.multipleStatements
is actually true. However, I realized later that it worked on a friend's machine just fine, so I assume that it is a bug in my MySQL connector. Will let you know, when I have any updates... – Domi Commented May 14, 2015 at 19:33 - @Domi,Any further update? – dialox Commented Aug 18, 2015 at 3:42
-
@huangchang Can't quite remember. I think I ended up using
sequelize.query(query, { type: sequelize.QueryTypes.RAW });
– Domi Commented Aug 18, 2015 at 6:06
3 Answers
Reset to default 5DELIMITER
is not part of MySQL server, it's part of the MySQL mand line client. This feature is not available in the driver.
Source: https://github./mysqljs/mysql/issues/280#issuement-8081626
Your error is actually in the last line. Take out the $$
after DELIMITER;
The statement: DELIMITER;
resets the delimiter to ;
the $$
after that confuses the syntax analyzer.
I hit this issue as well in Sequelize with MySQL. The solution that worked for me was removing both the DELIMITER
statements. This would make the original posters procedure look like this:
const query = `DROP PROCEDURE IF EXISTS x;
CREATE PROCEDURE x()
BEGIN
SELECT 1;
SELECT 2;
END;`
await sequelize.query(query, {
type: sequelize.QueryTypes.RAW
});
As this Github ment suggested, not only is DELIMITER
not available to the Node.js MySQL client, it's not necessary, since Node.js client uses quotes or backticks to determine where your query ends, and uses the BEGIN
and END
tokens to determine where the trigger code begins and ends.