Parser { public static String replaceProcessing(String sql, boolean replaceProcessingEnabled, boolean standardConformingStrings) throws SQLException { if (replaceProcessingEnabled) { int len = sql.length(); char[] chars = sql.toCharArray(); StringBuilder newsql = new StringBuilder(len); int i = 0; while (i < len) { i = parseSql(chars, i, newsql, false, standardConformingStrings); if (i < len) { newsql.append(chars[i]); i++; } } return newsql.toString(); } else { return sql; } }  static List<NativeQuery> parseJdbcSql(String query, boolean standardConformingStrings,
      boolean withParameters, boolean splitStatements,
      boolean isBatchedReWriteConfigured,
      String... returningColumnNames); static int parseSingleQuotes(final char[] query, int offset,
      boolean standardConformingStrings); static int parseDoubleQuotes(final char[] query, int offset); static int parseDollarQuotes(final char[] query, int offset); static int parseLineComment(final char[] query, int offset); static int parseBlockComment(final char[] query, int offset); static boolean parseDeleteKeyword(final char[] query, int offset); static boolean parseInsertKeyword(final char[] query, int offset); static boolean parseMoveKeyword(final char[] query, int offset); static boolean parseReturningKeyword(final char[] query, int offset); static boolean parseSelectKeyword(final char[] query, int offset); static boolean parseUpdateKeyword(final char[] query, int offset); static boolean parseValuesKeyword(final char[] query, int offset); static long parseLong(String s, int beginIndex, int endIndex); static boolean parseWithKeyword(final char[] query, int offset); static boolean parseAsKeyword(final char[] query, int offset); static boolean isDigitAt(String s, int pos); static int digitAt(String s, int pos); static boolean isSpace(char c); static boolean isArrayWhiteSpace(char c); static boolean isOperatorChar(char c); static boolean isIdentifierStartChar(char c); static boolean isIdentifierContChar(char c); static boolean charTerminatesIdentifier(char c); static boolean isDollarQuoteStartChar(char c); static boolean isDollarQuoteContChar(char c); static JdbcCallParseInfo modifyJdbcCall(String jdbcSql, boolean stdStrings,
      int serverVersion, int protocolVersion, EscapeSyntaxCallMode escapeSyntaxCallMode); static String replaceProcessing(String sql, boolean replaceProcessingEnabled,
      boolean standardConformingStrings);  }
@Test public void testEscapeProcessing() throws Exception { assertEquals("DATE '1999-01-09'", Parser.replaceProcessing("{d '1999-01-09'}", true, false)); assertEquals("DATE '1999-01-09'", Parser.replaceProcessing("{D '1999-01-09'}", true, false)); assertEquals("TIME '20:00:03'", Parser.replaceProcessing("{t '20:00:03'}", true, false)); assertEquals("TIME '20:00:03'", Parser.replaceProcessing("{T '20:00:03'}", true, false)); assertEquals("TIMESTAMP '1999-01-09 20:11:11.123455'", Parser.replaceProcessing("{ts '1999-01-09 20:11:11.123455'}", true, false)); assertEquals("TIMESTAMP '1999-01-09 20:11:11.123455'", Parser.replaceProcessing("{Ts '1999-01-09 20:11:11.123455'}", true, false)); assertEquals("user", Parser.replaceProcessing("{fn user()}", true, false)); assertEquals("cos(1)", Parser.replaceProcessing("{fn cos(1)}", true, false)); assertEquals("extract(week from DATE '2005-01-24')", Parser.replaceProcessing("{fn week({d '2005-01-24'})}", true, false)); assertEquals("\"T1\" LEFT OUTER JOIN t2 ON \"T1\".id = t2.id", Parser.replaceProcessing("{oj \"T1\" LEFT OUTER JOIN t2 ON \"T1\".id = t2.id}", true, false)); assertEquals("ESCAPE '_'", Parser.replaceProcessing("{escape '_'}", true, false)); assertEquals("{obj : 1}", Parser.replaceProcessing("{obj : 1}", true, false)); }
@Test public void testUnterminatedEscape() throws Exception { assertEquals("{oj ", Parser.replaceProcessing("{oj ", true, false)); }