4

我正在使用 sql-maven-plugin 在多个数据库上执行一些 MySQL 脚本。我想在同一个 SQL 脚本中部署表、数据、触发器、事件和存储过程。

我对行分隔符有疑问,因为对于 INSERT 或 CREATE 我使用;,但对于我的触发器,我必须使用 更改分隔符DELIMITER //,例如。

我知道该插件允许更改分隔符,但它适用于所有脚本,我只想为唯一脚本的一部分更改分隔符。

这是我的 Maven 配置:

<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

1 回答 1

5

您可以在配置块中将 demeterType 设置为“行”。

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

分隔符类型

正常意味着任何分隔符的出现都会终止 SQL 命令,而对于行,只有仅包含分隔符的行被识别为命令的结尾。

在http://mojo.codehaus.org/sql-maven-plugin/execute-mojo.html#delimiterType中查看更多信息


例如: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
于 2012-10-26T07:44:18.783 回答