Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a StoreProc Syntax Error #3

Open
mmTomArcher opened this issue Sep 2, 2021 · 1 comment
Open

Creating a StoreProc Syntax Error #3

mmTomArcher opened this issue Sep 2, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@mmTomArcher
Copy link

Afternoon,

I'm trying to use DbUp to create a new Store Proc and I'm getting a syntax error when execute PerformUpgrade... My script works directly on a query window on the MySQL database.

here is the query

DROP PROCEDURE IF EXISTS My_StoreProc;

CREATE PROCEDURE My_StoreProc;(strEmail VARCHAR(255))

BEGIN
SELECT id FROM table WHERE email = strEmail
ORDER BY id DESC limit 1;
END;

Here is the error:
Script block number: 1; Message: 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 'END' at line 1
MySql.Data.MySqlClient.MySqlException (0x80004005): 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 'END' at line 1
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at DbUp.Support.ScriptExecutor.ExecuteAndLogOutput(IDbCommand command)
at DbUp.Support.ScriptExecutor.<>c__DisplayClass18_2.b__1()
at DbUp.MySql.MySqlScriptExecutor.ExecuteCommandsWithinExceptionHandler(Int32 index, SqlScript script, Action executeCommand)

Any suggestions, is there a work arround, is this a know bug?

@mmTomArcher mmTomArcher added the bug Something isn't working label Sep 2, 2021
@jafin
Copy link

jafin commented Sep 16, 2021

@mmTomArcher I think the issue is with the MySQL parser splitting on the limit1; inside the BEGIN..END

--cmd1
DROP PROCEDURE IF EXISTS My_StoreProc

--cmd2
CREATE PROCEDURE My_StoreProc(strEmail VARCHAR(255))
BEGIN
SELECT id FROM table_name WHERE email = strEmail
ORDER BY id DESC limit 1

--cmd3
END

As a workaround you could try changing the delimier

DELIMITER $$

DROP PROCEDURE IF EXISTS My_StoreProc$$

CREATE PROCEDURE My_StoreProc(strEmail VARCHAR(255))
BEGIN
SELECT id FROM table_name WHERE email = strEmail
ORDER BY id DESC limit 1;
END$$

This test fails but passes if setting a DELIMITER:

  public class MySqlParserTests
    {
        private int commandCount = 0;

        [Fact]
        public void Parse()
        {
            MySqlCommandReader reader = new MySqlCommandReader(@"
DROP PROCEDURE IF EXISTS My_StoreProc;

CREATE PROCEDURE My_StoreProc(strEmail VARCHAR(255))
BEGIN
SELECT id FROM table_name WHERE email = strEmail
ORDER BY id DESC limit 1;
END;
");
            reader.ReadAllCommands(CommandHandler);
            commandCount.ShouldBe(2);
        }

        private void CommandHandler(string val)
        {
            Console.WriteLine(val);
            commandCount++;
        }
    }

@droyad droyad transferred this issue from DbUp/DbUp Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Bugs
Development

No branches or pull requests

2 participants