I am using the sql-maven-plugin to execute some MySQL scripts on several databases. I would like to deploy, in the same SQL script, tables, datas, triggers, events and stored procedures.
I have a problem with the line delimiter, because for INSERT or CREATE I use the ;
, but for my triggers I have to change the delimiter with DELIMITER //
, for example.
I know that the plugin allows changing the delimiter, but it will be applicable for all the script, I want to change the delimiter only for a 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>
You can set your delimeterType to "row" in configuration block.
<configuration>
...
<delimiterType>row</delimiterType>
...
</configuration>
Normal means that any occurrence of the delimiter terminate the SQL command whereas with row, only a line containing just the delimiter is recognized as the end of the command.
See more at http://mojo.codehaus.org/sql-maven-plugin/execute-mojo.html#delimiterType
For examlpe: 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