- private static void addFile(Statement stmt, File f, ImportType type) throws IOException, SQLException {
- String sql = readFile(f);
- sql = sql.replaceAll("--[^\n]+\n", "\n");
- String[] stmts = sql.split(";");
- Pattern p = Pattern.compile("\\s*DROP TABLE IF EXISTS `([^`]+)`");
- for (String string : stmts) {
- Matcher m = p.matcher(string);
- string = string.trim();
- if (string.equals("")) {
- continue;
- }
- if (m.matches() && type == ImportType.TRUNCATE) {
- String sql2 = "TRUNCATE `" + m.group(1) + "`";
- stmt.addBatch(sql2);
- continue;
- }
- if (type == ImportType.PRODUCTION || string.startsWith("INSERT")) {
- stmt.addBatch(string);
- } else if (type == ImportType.TEST) {
- stmt.addBatch(string.replace("ENGINE=InnoDB", "ENGINE=Memory"));
- }
- }