This commit is contained in:
yakolee
2014-05-27 16:58:34 +08:00
parent 6e11d7bc23
commit 2d231cb6f9
3 changed files with 15 additions and 1 deletions
@@ -234,7 +234,7 @@ public class MySqlExprParser extends SQLExprParser {
String chars = lexer.stringVal();
concat.addParameter(new SQLCharExpr(chars));
lexer.nextToken();
} while (lexer.token() == Token.LITERAL_CHARS);
} while (lexer.token() == Token.LITERAL_CHARS || lexer.token() == Token.LITERAL_ALIAS);
expr = concat;
}
} else if (lexer.token() == Token.IDENTIFIER) {
@@ -2205,6 +2205,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
item.setParent(x);
item.accept(this);
}
print(";");
decrementIndent();
return false;
@@ -2226,6 +2227,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
item.setParent(x);
item.accept(this);
}
print(";");
decrementIndent();
return false;
@@ -2256,6 +2258,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
println();
}
}
print(";");
decrementIndent();
for (ElseIf elseIf : x.getElseIfList()) {
@@ -18,4 +18,15 @@ public class SQLUtilsTest extends TestCase {
"\nFROM t" + //
"\nWHERE id = 'abc'", formattedSql);
}
public void test_format_1() throws Exception {
String sql = "select * from t where tname LIKE \"%\"'温'\"%\"";
String formattedSql = SQLUtils.formatMySql(sql);
Assert.assertEquals("SELECT *\nFROM t\nWHERE tname LIKE CONCAT('%', '温', '%')", formattedSql);
}
public void test_format_2() throws Exception {
String sql = "begin\n" + " if (a=10) then\n" + " null;\n" + " else\n" + " null;\n" + " end if;\n" + "end;";
System.out.println(SQLUtils.formatOracle(sql));
}
}