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

Added execution of multiple statement at once with two tests #296

Closed
wants to merge 1 commit into from
Closed

Added execution of multiple statement at once with two tests #296

wants to merge 1 commit into from

Conversation

daddykotex
Copy link

Hi,

I'm pretty new to Go and I've tried to do something here, please give me advice if I did something wrong. I'm also new to the GitHub workflow so if you have any advice I'll gladly take them.

I'm using a tool called migrate (https://github.com/mattes/migrate). The tools allows for database refactoring. The tool currently support MySQL in an experimental matter. One of the problem is that the migration are done reading files and as you probably know, SQL file can contains multiple statement to be executed one after the other.

There is currently no support for this feature in any MySQL (afaik) driver. I've tried something with this. It works, but I think it is far from optimal. I currently split the input on ";" and then run each query individually. I also add any affectedRows and return it with the result.

I can think of many problem with this, on the top of my head :

  • If the ";" character anywhere in a comment , or something it will break
  • If an error occur with one of the statement, what happens?

I didn't spent too much time here because I want to know your opinion before going any further. I have also seen #258 but maybe we can work something out here ?

Thanks a lot, David

An external file was created to avoid crap in the go test file
@arnehormann
Copy link
Member

Hi @daddykotex, thanks for contributing! Keep it up!

But... your approach doesn't work and we will not integrate it like this.

First - as you said - the semicolon may be part of a comment or a string. So we'd have to add an SQL parser to the driver and that still wouldn't catch a DELIMITER EOQ statement that redefines the query delimiter earlier in the session (I didn't find a good example in the documentation, see Stackoverflow for example).

The good news: MySQL can do this on its own. We only have to set two flags when a connection is established. The bad news: database/sql does not support it in any way. As it's unsupported by database/sql, we won't support it either - if we start doing it and build it in a different way and Go adds it later, we have it in the driver twice - which we want to keep clean.

There's more about this in #66, that's a much better reference than #258.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants