@@ -2132,14 +2132,39 @@ def installDatabase(self, dbName):
2132
2132
try :
2133
2133
cmdLines = self ._createMySQLCMDLines (dbSql )
2134
2134
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 :
2143
2168
result = self .execMySQL (cmd , dbName )
2144
2169
if not result ["OK" ]:
2145
2170
error = "Failed to initialize Database"
0 commit comments