Multiple Separator Sql-maven-plugin

I use sql-maven-plugin to execute some MySQL scripts in multiple databases. I would like to deploy the same SQL script, tables, data, triggers, events, and stored procedures.

I have a problem with line separator because for INSERT or CREATE I use ; but for my triggers I need, for example, change the delimiter to DELIMITER // .

I know that the plugin allows you to change the separator, but it is applicable for all scripts, I want to change the separator only for part of a unique script.

This is my maven configuration:

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sql-maven-plugin</artifactId> <version>1.5</version> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.21</version> </dependency> </dependencies> <configuration> <driver>com.mysql.jdbc.Driver</driver> <username>${db.user}</username> <password>${db.passwd}</password> <encoding>UTF-8</encoding> <orderFile>ascending</orderFile> <keepFormat>true</keepFormat> <driverProperties>characterEncoding=utf8, connectionCollation=utf8_general_ci, sql_mode=STRICT_TRANS_TABLES</driverProperties> </configuration> <executions> <execution> <id>execution-mysql</id> <phase>prepare-package</phase> <goals> <goal>execute</goal> </goals> <configuration> <url>jdbc:mysql://${db.url}:${db.port}</url <delimiterType>normal</delimiterType> <fileset> <basedir>${project.build.directory}/sql/</basedir> <includes> <include>${file.sql}</include> </includes> </fileset> </configuration> </execution> </executions> </plugin> 
+4
source share
1 answer

You can set delimeterType to "row" in the configuration block.

 <configuration> ... <delimiterType>row</delimiterType> ... </configuration> 

delimiterType

Normal means that any occurrence of a delimiter terminates SQL while with a string, only a string containing only the delimiter recognized as the end of the command.

Read more at http://mojo.codehaus.org/sql-maven-plugin/execute-mojo.html#delimiterType


For example: create-proc.sql

 CREATE PROCEDURE ADD_BOOK (IN title VARCHAR(100)) BEGIN -- your sql code INSERT INTO Book (title) VALUES (title); END ; -- this means the end of the sql command 
+4
source

Source: https://habr.com/ru/post/1442104/


All Articles