If you extend the JDBC Appender and use the empty string '' constant in your query, the JdbcPatternParser will not parse the query correctly. This is due to the regular expression in the JdbcPatternParser I think.
This can be checked by adding the following test in JdbcPatternParserTest:
@Test
public void testEmptyStringConstant() {
String msgParam = "'%m'";
String sql = "INSERT INTO logtable (evt_date, err_code)" + " SELECT to_timestamp(a[1], 'DD.MM.YYYY HH:MI:SS'), NULLIF(a[2], '')::int"
+ " FROM (SELECT string_to_array(" + msgParam + ", ',') a) splitter";
ParserState expected = new ParserState(sql.replace(msgParam, "?"), "%m");
assertParserStateEquality(sql, expected);
}
Test above produce the error:
java.lang.AssertionError: expected:<ParserState [statement=INSERT INTO logtable (evt_date, err_code) SELECT to_timestamp(a[1], 'DD.MM.YYYY HH:MI:SS'), NULLIF(a[2], '')::int FROM (SELECT string_to_array(?, ',') a) splitter, args=[%m]]> but was:<ParserState [statement=INSERT INTO logtable (evt_date, err_code) SELECT to_timestamp(a[1], 'DD.MM.YYYY HH:MI:SS'), NULLIF(a[2], '')::int FROM (SELECT string_to_array('%m', ',') a) splitter, args=[]]>
If the STRING_LITERAL_PATTERN would be modified to "(?<!')'((?>[^']|'')+)'" it should work, and hopefully not breaking the other tests. It uses lookbehind to start matching an apostrophe only if not preceded by another apostrophe
it would also make line 36 of JdbcPatternParser :
private final static Pattern STRING_LITERAL_PATTERN = Pattern.compile("(?<!')'((?>[^']|'')+)'");
At the moment, I have set an empty_string() database function to work arround this issue.
If you extend the JDBC Appender and use the empty string
''constant in your query, theJdbcPatternParserwill not parse the query correctly. This is due to the regular expression in theJdbcPatternParserI think.This can be checked by adding the following test in
JdbcPatternParserTest:Test above produce the error:
java.lang.AssertionError: expected:<ParserState [statement=INSERT INTO logtable (evt_date, err_code) SELECT to_timestamp(a[1], 'DD.MM.YYYY HH:MI:SS'), NULLIF(a[2], '')::int FROM (SELECT string_to_array(?, ',') a) splitter, args=[%m]]> but was:<ParserState [statement=INSERT INTO logtable (evt_date, err_code) SELECT to_timestamp(a[1], 'DD.MM.YYYY HH:MI:SS'), NULLIF(a[2], '')::int FROM (SELECT string_to_array('%m', ',') a) splitter, args=[]]>If the STRING_LITERAL_PATTERN would be modified to "(?<!')'((?>[^']|'')+)'" it should work, and hopefully not breaking the other tests. It uses lookbehind to start matching an apostrophe only if not preceded by another apostrophe
it would also make line 36 of
JdbcPatternParser:At the moment, I have set an empty_string() database function to work arround this issue.