Support EOF as statement separator in SQL scripts
Prior to Spring Framework 4.0.3, it was possible to supply a bogus statement separator (i.e., a separator string that does not exist in the configured SQL scripts) to ResourceDatabasePopulator with the side effect that the entire contents of a script file would be interpreted as a single SQL statement. This undocumented feature was never intentional; however, some developers came to rely on it. Unfortunately, changes made in conjunction with SPR-9531 and SPR-11560 caused such scenarios to no longer work. This commit introduces first-class support for executing scripts which contain a single statement that spans multiple lines but is not followed by an explicit statement separator. Specifically, ScriptUtils.EOF_STATEMENT_SEPARATOR may now be specified as a 'virtual' statement separator to denote that a script contains a single statement and no actual separator. Issue: SPR-11687
This commit is contained in:
@@ -139,6 +139,17 @@ public abstract class AbstractDatabasePopulatorTests extends AbstractDatabaseIni
|
||||
assertUsersDatabaseCreated("Brannen", "Hoeller");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptWithoutStatementSeparator() throws Exception {
|
||||
databasePopulator.setSeparator(ScriptUtils.EOF_STATEMENT_SEPARATOR);
|
||||
databasePopulator.addScript(resource("drop-users-schema.sql"));
|
||||
databasePopulator.addScript(resource("users-schema-without-separator.sql"));
|
||||
databasePopulator.addScript(resource("users-data.sql"));
|
||||
DatabasePopulatorUtils.execute(databasePopulator, db);
|
||||
|
||||
assertUsersDatabaseCreated("Brannen");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWithMultipleScriptResources() throws Exception {
|
||||
final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(usersSchema(),
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE users IF EXISTS
|
||||
@@ -0,0 +1,3 @@
|
||||
INSERT INTO
|
||||
users(first_name, last_name)
|
||||
values('Sam', 'Brannen')
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE users (
|
||||
id INTEGER NOT NULL IDENTITY,
|
||||
first_name VARCHAR(50) NOT NULL,
|
||||
last_name VARCHAR(50) NOT NULL
|
||||
)
|
||||
Reference in New Issue
Block a user