ignore empty statements (SPR-7363)

This commit is contained in:
Juergen Hoeller 2010-08-07 16:52:05 +00:00
parent bf4b9f5ffb
commit a8133a9917
1 changed files with 8 additions and 7 deletions

View File

@ -239,10 +239,10 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
} }
/** /**
* Split an SQL script into separate statements delimited with the provided delimiter character. Each individual * Split an SQL script into separate statements delimited with the provided delimiter character.
* statement will be added to the provided <code>List</code>. * Each individual statement will be added to the provided <code>List</code>.
* @param script the SQL script * @param script the SQL script
* @param delim character delimiting each statement - typically a ';' character * @param delim character delimiting each statement (typically a ';' character)
* @param statements the List that will contain the individual statements * @param statements the List that will contain the individual statements
*/ */
private void splitSqlScript(String script, char delim, List<String> statements) { private void splitSqlScript(String script, char delim, List<String> statements) {
@ -250,20 +250,21 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
boolean inLiteral = false; boolean inLiteral = false;
char[] content = script.toCharArray(); char[] content = script.toCharArray();
for (int i = 0; i < script.length(); i++) { for (int i = 0; i < script.length(); i++) {
if (content[i] == '\'') { char c = content[i];
if (c == '\'') {
inLiteral = !inLiteral; inLiteral = !inLiteral;
} }
if (content[i] == delim && !inLiteral) { if ((c == delim || c == '\n') && !inLiteral) {
if (sb.length() > 0) { if (sb.length() > 0) {
statements.add(sb.toString()); statements.add(sb.toString());
sb = new StringBuilder(); sb = new StringBuilder();
} }
} }
else { else {
sb.append(content[i]); sb.append(c);
} }
} }
if (sb.length() > 0) { if (StringUtils.hasText(sb)) {
statements.add(sb.toString()); statements.add(sb.toString());
} }
} }