简体   繁体   中英

Conditional/Executable Comments in schema.sql in Spring Boot application

We are using the database initialization feature of Spring boot in our JUnit tests like it is documented here .

We have our schema.sql file on our classpath and it is beeing executed as expected on application startup. However the script fails because it contains some Conditional comments of the following form which are needed to make it run on MySQL or MariaDB.

The comments look like this:

/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

In the stack trace of the execution we found that the class org.springframework.jdbc.datasource.init.ScriptUtils is beeing used to split the sql file into separate statements. In this process all the block comments are removed and not sent to the database.

Is there a way to configure this behaviour so that the whole file ist just sent to the databse and executed at once ?

Don't use that script; it is clearly inappropriate.

Instead execute LOAD DATA INFILE ... to get the task done in a single step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM