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

Use native DELIMITER #95

Open
chb0github opened this issue Oct 18, 2017 · 5 comments
Open

Use native DELIMITER #95

chb0github opened this issue Oct 18, 2017 · 5 comments

Comments

@chb0github
Copy link
Contributor

following on #88 mybatis should honor native DB delimiters in order to support stored procedures and such.

Benefits to this approach

  1. In the unlikely event that a migration goes wrong the original SQL script can be run with the native client
  2. Reduces the friction to adoption by those familiar with the native tooling due to 1)
  3. use of migrate script may generate a script that is intended to be run with a native client. However, without the native delimiter this would not be possible.

Since all DBs potentially (likely) use different delimiters, basically either a simple Map<String,Consumer<String>> need be implemented where the key is the command word to check to see if it's a delimiter word and the consumer is what should be done with the word to correctly process it. This follows the Command Pattern

a sketched implementation:

Map<String,Consumer<String>> COMMANDS = new HashMap<>();
COMMANDS.put("DELIMITER", c -> this.delimiter = c); // mysql version
COMMANDS.put("CHANGE", c -> this.delimiter = c.split(" ")[1]); // ORACLE version CHANGE / %

Consumer<String> whatToDo = COMMANDS.getOrDefault(command,c -> sendToDb(c));
whatToDo.accept(command);

An alternative implementation might require deeper logical inspection with the application of a series of predicates. Hopefully that's not necessary

@harawata
Copy link
Member

harawata commented Oct 18, 2017

Both of your ideas require to implement database dependent patterns (dialects) in Migrations code and we do not do that.

Instead, I plan to add a new option delimiter_prefix or delimiter_pattern.
This will work with any database without modifying Migrations code.

In your case, the configuration will look like...

delimiter_prefix=DELIMITER 

This meets your requirement, doesn't it?

@chb0github
Copy link
Contributor Author

My case? Sure. The general case? No. For oracle, the syntax is

SET CMDS[EP] {; | c | ON | OFF}

example:

SET CMDSEP ON
SET CMDSEP "!"
SHOW CMDSEP! SHOW BUFFER!

So, while it won't be easy (hence the suggestion of using predicates and an AbstractFactory) what you have won't work.

@harawata
Copy link
Member

Hi @chb0github ,

Sorry for a late reply.
At this point, I am not sure if there is a universal solution that does not involve dialect or similar.
Please use hooks for now.

@chb0github
Copy link
Contributor Author

chb0github commented Oct 24, 2017

How about we leave the issue open as a feature request? Closing an issue means it's not an issue any more and becomes less visible.

And, as I suggested: A dialectic approach is the right approach but is definitely involved

@harawata
Copy link
Member

Okay.

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

No branches or pull requests

2 participants