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

設定ブロックで、delimeterType を「row」に設定できます。

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

delimiterType

通常は、区切り文字が出現すると 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 に答える