@@ -99,6 +99,7 @@ public static String handleAddColumn(String mcSql) throws SQLException {
99
99
// split on whitespace to get column name
100
100
String [] columnDefinitions = columnsPart .split ("\\ s*,\\ s*" );
101
101
String tableName = noDatabasePrefix .replaceAll ("ALTER TABLE (\\ S+) ADD COLUMNS.*" , "$1" );
102
+ tableName = unwrapTable (tableName );
102
103
103
104
String [] alterTableStatements = new String [columnDefinitions .length ];
104
105
@@ -134,6 +135,7 @@ public static String handleDropColumn(String mcSql) throws SQLException {
134
135
String noDatabasePrefix = mcSql .replaceAll ("ALTER TABLE \\ S+\\ ." , "ALTER TABLE " );
135
136
136
137
String tableName = noDatabasePrefix .replaceAll ("ALTER TABLE (\\ S+) DROP COLUMNS.*" , "$1" );
138
+ tableName = unwrapTable (tableName );
137
139
String [] columnsToDrop =
138
140
noDatabasePrefix .replaceAll ("ALTER TABLE \\ S+ DROP COLUMNS " , "" ).split ("," );
139
141
@@ -180,6 +182,7 @@ public static String handleRenameColumn(String mcSql) throws SQLException {
180
182
String noDatabasePrefix = mcSql .replaceAll ("ALTER TABLE \\ S+\\ ." , "ALTER TABLE " );
181
183
182
184
String tableName = noDatabasePrefix .replaceAll ("ALTER TABLE (\\ S+) CHANGE COLUMN.*" , "$1" );
185
+ tableName = unwrapTable (tableName );
183
186
String [] columnToRename =
184
187
noDatabasePrefix .replaceAll ("ALTER TABLE \\ S+ CHANGE COLUMN " , "" ).replace ("\\ s+" , "" ).split (" " );
185
188
String oldName ;
@@ -211,6 +214,7 @@ public static String handleRenameColumn(String mcSql) throws SQLException {
211
214
}
212
215
213
216
public static SqlLiteSchema getSchema (String tableName ) throws SQLException {
217
+ tableName = unwrapTable (tableName );
214
218
try (Statement stmt = CommonUtils .getConnection ().createStatement ()) {
215
219
ResultSet rs = stmt .executeQuery (
216
220
"SELECT schema FROM schemas WHERE table_name = '" + tableName .toUpperCase () + "';" );
@@ -229,6 +233,7 @@ public static SqlLiteSchema getSchema(String tableName) throws SQLException {
229
233
}
230
234
231
235
static void updateSchema (String tableName , SqlLiteSchema schema ) throws SQLException {
236
+ tableName = unwrapTable (tableName );
232
237
try (Statement stmt = CommonUtils .getConnection ().createStatement ()) {
233
238
stmt .executeUpdate (
234
239
"UPDATE schemas SET schema = '" + schema .toJson () + "' WHERE table_name = '" + tableName +
@@ -275,4 +280,13 @@ private static String processResultSet(ResultSet resultSet) throws SQLException,
275
280
276
281
return writer .toString ();
277
282
}
283
+
284
+ private static String unwrapTable (String tableName ) {
285
+ tableName = tableName .trim ();
286
+ if (tableName .startsWith ("`" ) && tableName .endsWith ("`" )) {
287
+ return tableName .substring (1 , tableName .length () - 1 );
288
+ } else {
289
+ return tableName ;
290
+ }
291
+ }
278
292
}
0 commit comments