@Test public void alterMeta() { AlterMeta test = SQLHelper.alterMeta(TEST, "alter table xx add yy int null after zz"); assertNotNull(test); assertEquals("", TEST, test.getSchema()); assertEquals("", XX, test.getTable()); test = SQLHelper.alterMeta("", "alter table test.xx add yy int null after zz"); assertNotNull(test); assertEquals("", TEST, test.getSchema()); assertEquals("", XX, test.getTable()); test = SQLHelper.alterMeta(TEST, "alter table xx drop column yy"); assertNotNull(test); assertEquals("", TEST, test.getSchema()); assertEquals("", XX, test.getTable()); test = SQLHelper.alterMeta("", "alter table test.xx drop column yy"); assertNotNull(test); assertEquals("", TEST, test.getSchema()); assertEquals("", XX, test.getTable()); test = SQLHelper.alterMeta(TEST, "alter table xx modify column yy int after zz"); assertNotNull(test); assertEquals("", TEST, test.getSchema()); assertEquals("", XX, test.getTable()); test = SQLHelper.alterMeta("", "alter table test.xx modify column yy int after zz"); assertNotNull(test); assertEquals("", TEST, test.getSchema()); assertEquals("", XX, test.getTable()); test = SQLHelper.alterMeta("", "alter table `test`.`xx` modify column `yy` int after `zz`"); assertNotNull(test); assertEquals("", TEST, test.getSchema()); assertEquals("", XX, test.getTable()); test = SQLHelper.alterMeta("", "alter table `test`\n.`xx`\n modify column `yy` int after `zz`"); assertNotNull(test); assertEquals("", TEST, test.getSchema()); assertEquals("", XX, test.getTable()); test = SQLHelper.alterMeta(TEST, "alter table xx add yy int null"); assertNull(test); test = SQLHelper.alterMeta("", "alter table test.xx add yy int null"); assertNull(test); }
public static AlterMeta alterMeta(String database, String sql) { String alterTarget = isAlter(sql); if (alterTarget != null) { alterTarget = alterTarget.replaceAll("`|\\s", ""); if (!StringUtils.isEmpty(database)) { return new AlterMeta(database, alterTarget); } String[] split = alterTarget.split("\\."); assert split.length == 2; return new AlterMeta(split[0], split[1]); } return null; }
SQLHelper { public static AlterMeta alterMeta(String database, String sql) { String alterTarget = isAlter(sql); if (alterTarget != null) { alterTarget = alterTarget.replaceAll("`|\\s", ""); if (!StringUtils.isEmpty(database)) { return new AlterMeta(database, alterTarget); } String[] split = alterTarget.split("\\."); assert split.length == 2; return new AlterMeta(split[0], split[1]); } return null; } }
SQLHelper { public static AlterMeta alterMeta(String database, String sql) { String alterTarget = isAlter(sql); if (alterTarget != null) { alterTarget = alterTarget.replaceAll("`|\\s", ""); if (!StringUtils.isEmpty(database)) { return new AlterMeta(database, alterTarget); } String[] split = alterTarget.split("\\."); assert split.length == 2; return new AlterMeta(split[0], split[1]); } return null; }  }
SQLHelper { public static AlterMeta alterMeta(String database, String sql) { String alterTarget = isAlter(sql); if (alterTarget != null) { alterTarget = alterTarget.replaceAll("`|\\s", ""); if (!StringUtils.isEmpty(database)) { return new AlterMeta(database, alterTarget); } String[] split = alterTarget.split("\\."); assert split.length == 2; return new AlterMeta(split[0], split[1]); } return null; }  static String inSQL(Object value); static String wrapCol(String col); static AlterMeta alterMeta(String database, String sql); }
SQLHelper { public static AlterMeta alterMeta(String database, String sql) { String alterTarget = isAlter(sql); if (alterTarget != null) { alterTarget = alterTarget.replaceAll("`|\\s", ""); if (!StringUtils.isEmpty(database)) { return new AlterMeta(database, alterTarget); } String[] split = alterTarget.split("\\."); assert split.length == 2; return new AlterMeta(split[0], split[1]); } return null; }  static String inSQL(Object value); static String wrapCol(String col); static AlterMeta alterMeta(String database, String sql);  }