Skip to content

Commit 971decb

Browse files
committed
Logic to read delimiter
1 parent 6a0fce3 commit 971decb

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

framework/db/src/com/cloud/utils/db/ScriptRunner.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
package com.cloud.utils.db;
2222

23+
import org.apache.log4j.Logger;
24+
2325
import java.io.IOException;
2426
import java.io.LineNumberReader;
2527
import java.io.Reader;
@@ -29,15 +31,14 @@
2931
import java.sql.SQLException;
3032
import java.sql.Statement;
3133

32-
import org.apache.log4j.Logger;
33-
3434
/**
3535
* Tool to run database scripts
3636
*/
3737
public class ScriptRunner {
3838
private static Logger s_logger = Logger.getLogger(ScriptRunner.class);
3939

4040
private static final String DEFAULT_DELIMITER = ";";
41+
private static final String CHANGE_DELIMITER_STMT = "DELIMITER ";
4142

4243
private Connection connection;
4344

@@ -128,6 +129,12 @@ private void runScript(Connection conn, Reader reader) throws IOException, SQLEx
128129
// Do nothing
129130
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("#")) {
130131
// Do nothing
132+
} else if (trimmedLine.startsWith(CHANGE_DELIMITER_STMT)) {
133+
String[] res = trimmedLine.split(CHANGE_DELIMITER_STMT, 2);
134+
if (res.length == 2) {
135+
String newDelimiter = res[1];
136+
setDelimiter(newDelimiter, fullLineDelimiter);
137+
}
131138
} else if (!fullLineDelimiter && trimmedLine.endsWith(getDelimiter()) || fullLineDelimiter && trimmedLine.equals(getDelimiter())) {
132139
command.append(line.substring(0, line.lastIndexOf(getDelimiter())));
133140
command.append(" ");

0 commit comments

Comments
 (0)