@@ -99,6 +99,7 @@ public static String handleAddColumn(String mcSql) throws SQLException {
9999 // split on whitespace to get column name
100100 String [] columnDefinitions = columnsPart .split ("\\ s*,\\ s*" );
101101 String tableName = noDatabasePrefix .replaceAll ("ALTER TABLE (\\ S+) ADD COLUMNS.*" , "$1" );
102+ tableName = unwrapTable (tableName );
102103
103104 String [] alterTableStatements = new String [columnDefinitions .length ];
104105
@@ -134,6 +135,7 @@ public static String handleDropColumn(String mcSql) throws SQLException {
134135 String noDatabasePrefix = mcSql .replaceAll ("ALTER TABLE \\ S+\\ ." , "ALTER TABLE " );
135136
136137 String tableName = noDatabasePrefix .replaceAll ("ALTER TABLE (\\ S+) DROP COLUMNS.*" , "$1" );
138+ tableName = unwrapTable (tableName );
137139 String [] columnsToDrop =
138140 noDatabasePrefix .replaceAll ("ALTER TABLE \\ S+ DROP COLUMNS " , "" ).split ("," );
139141
@@ -180,6 +182,7 @@ public static String handleRenameColumn(String mcSql) throws SQLException {
180182 String noDatabasePrefix = mcSql .replaceAll ("ALTER TABLE \\ S+\\ ." , "ALTER TABLE " );
181183
182184 String tableName = noDatabasePrefix .replaceAll ("ALTER TABLE (\\ S+) CHANGE COLUMN.*" , "$1" );
185+ tableName = unwrapTable (tableName );
183186 String [] columnToRename =
184187 noDatabasePrefix .replaceAll ("ALTER TABLE \\ S+ CHANGE COLUMN " , "" ).replace ("\\ s+" , "" ).split (" " );
185188 String oldName ;
@@ -211,6 +214,7 @@ public static String handleRenameColumn(String mcSql) throws SQLException {
211214 }
212215
213216 public static SqlLiteSchema getSchema (String tableName ) throws SQLException {
217+ tableName = unwrapTable (tableName );
214218 try (Statement stmt = CommonUtils .getConnection ().createStatement ()) {
215219 ResultSet rs = stmt .executeQuery (
216220 "SELECT schema FROM schemas WHERE table_name = '" + tableName .toUpperCase () + "';" );
@@ -229,6 +233,7 @@ public static SqlLiteSchema getSchema(String tableName) throws SQLException {
229233 }
230234
231235 static void updateSchema (String tableName , SqlLiteSchema schema ) throws SQLException {
236+ tableName = unwrapTable (tableName );
232237 try (Statement stmt = CommonUtils .getConnection ().createStatement ()) {
233238 stmt .executeUpdate (
234239 "UPDATE schemas SET schema = '" + schema .toJson () + "' WHERE table_name = '" + tableName +
@@ -275,4 +280,13 @@ private static String processResultSet(ResultSet resultSet) throws SQLException,
275280
276281 return writer .toString ();
277282 }
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+ }
278292}
0 commit comments