- private static void addFile(Statement stmt, File f, boolean truncate) 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);
- if (m.matches()) {
- String sql2 = "TRUNCATE `" + m.group(1) + "`";
- stmt.addBatch(sql2);
- }
- if ( !string.trim().equals("") && ( !truncate || string.contains("INSERT"))) {
- stmt.addBatch(string.replace("ENGINE=Memory", ""));
- }
- }