mysql - 带有多个定界符的 sql-maven-plugin

标签 mysql maven sql-maven-plugin

我正在使用 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>

最佳答案

您可以在配置 block 中将 delimeterType 设置为“行”。

<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.

查看更多信息 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

关于mysql - 带有多个定界符的 sql-maven-plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13072354/

相关文章:

javascript - wro4j maven 插件 : how do I exclude files for jshint?

Maven 'versions' 插件,版本号顺序

mysql - 从给定条件中选择一个不是列名的列

PHP 包含 mysql 查询,使用 header 来防止查询重新执行,但是在哪里回显通知?

java - 使用 Maven 将 EAR 归档到另一个 EAR 中?

java - 使用 Maven 填充数据库

java - Maven 项目从依赖项运行 sql-maven-plugin 执行

php - 在 MYSQL 查询中使用变量作为列名

mysql - 如何使用同一张表中的多个 SELECT 优化 SQL 查询?