Skip to content

Commit 2de3b1b

Browse files
committed
Logic to read delimiter
1 parent 6a0fce3 commit 2de3b1b

2 files changed

Lines changed: 9 additions & 4 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(" ");

setup/db/db/schema-41000to41100.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,11 @@ CREATE PROCEDURE `cloud`.`ADD_COLUMN_TO_TABLE_IDEMPOTENT`(
134134
IN comment VARCHAR(255))
135135
BEGIN
136136
SET @t1=CONCAT('SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA="cloud" AND TABLE_NAME="', tableName, '" AND COLUMN_NAME="', colName, '" into @outvar');
137-
SELECT @t1;
138137
PREPARE stmt1 FROM @t1;
139138
EXECUTE stmt1;
140139
DEALLOCATE PREPARE stmt1;
141140
IF (@outvar < 1) THEN
142141
SET @t2=CONCAT('ALTER TABLE `cloud`.`', tableName, '` ADD COLUMN `', colName, '` ', colType, ' DEFAULT NULL COMMENT "', comment , '"');
143-
SELECT @t2;
144142
PREPARE stmt2 FROM @t2;
145143
EXECUTE stmt2;
146144
DEALLOCATE PREPARE stmt2;

0 commit comments

Comments
 (0)