Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
OpenCMIS 0.6.0
-
Ubuntu 11.04 64bit OpenJDK Runtime Environment (IcedTea6 1.10.4) (6b22-1.10.4-0ubuntu1~11.04.2)
Description
Aphostrophes in hard coded string literals are removed.
A simple query without parameters will not work:
QueryStatement st = session.createQueryStatement("select * from cmis:document where cmis:createdBy = \'admin\'"); System.out.println(st.toQueryString());
prints out
select * from cmis:document where cmis:createdBy = admin
instead of
select * from cmis:document where cmis:createdBy = 'admin'
obvious is that this query will not work when sent to a cmis server.
For my opinion the code of the toQueryString method should be something like this:
public static String toQueryString() { boolean inStr = false; int parameterIndex = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < statement.length(); i++) { char c = statement.charAt(i); if (c == '\'') { if (inStr && statement.charAt(i - 1) == '\\') { inStr = true; } else { inStr = !inStr; } sb.append(c); // without this line all ' are removed! } else if (c == '?' && !inStr) { // added && !inStr to have ? in string literals parameterIndex++; String s = parametersMap.get(parameterIndex); if (s == null) { sb.append(c); } else { sb.append(s); } } else { sb.append(c); } } return sb.toString(); }