Skip to content

Commit 488289a

Browse files
committed
feat: handling DELIMETER in sql files
1 parent 449d2f4 commit 488289a

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/DIRAC/FrameworkSystem/Client/ComponentInstaller.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,14 +2132,39 @@ def installDatabase(self, dbName):
21322132
try:
21332133
cmdLines = self._createMySQLCMDLines(dbSql)
21342134

2135-
# We need to run one SQL cmd at once, mysql is much happier that way.
2136-
# Create a string of commands, ignoring comment lines
2137-
sqlString = "\n".join(x for x in cmdLines if not x.startswith("--"))
2138-
2139-
# Now run each command (They are seperated by ;)
2140-
# Ignore any empty ones
2141-
cmds = [x.strip() for x in sqlString.split(";") if x.strip()]
2142-
for cmd in cmds:
2135+
# Now run each command (They are seperated by ;, or by a DELIMITER)
2136+
# We need to split the string into commands, and ignore any empty ones
2137+
2138+
# Handle DELIMITER statements in SQL
2139+
delimiter = ";"
2140+
commands = []
2141+
current_command = []
2142+
for line in cmdLines:
2143+
if line.startswith("--"):
2144+
continue
2145+
if line.startswith("DELIMITER "):
2146+
delimiter = line.split("DELIMITER ", 1)[1].strip()
2147+
continue
2148+
if delimiter != ";":
2149+
if line == delimiter:
2150+
commands.append("\n".join(current_command).strip())
2151+
current_command = []
2152+
else:
2153+
current_command.append(line)
2154+
else:
2155+
if line.endswith(";"):
2156+
current_command.append(line[:-1])
2157+
commands.append("\n".join(current_command).strip())
2158+
current_command = []
2159+
else:
2160+
current_command.append(line)
2161+
if current_command:
2162+
commands.append("\n".join(current_command).strip())
2163+
2164+
# Remove empty commands
2165+
commands = [cmd for cmd in commands if cmd]
2166+
2167+
for cmd in commands:
21432168
result = self.execMySQL(cmd, dbName)
21442169
if not result["OK"]:
21452170
error = "Failed to initialize Database"

0 commit comments

Comments
 (0)