Uploaded image for project: 'Chemistry (Retired)'
  1. Chemistry (Retired)
  2. CMIS-498

Aphostrophes in hard coded string literals are removed in org.apache.chemistry.opencmis.client.runtime.QueryStatementImpl

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • OpenCMIS 0.6.0
    • OpenCMIS 0.7.0
    • opencmis-client
    • 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();
          }
      

      Attachments

        Activity

          People

            fmui Florian Müller
            bojannemec Bojan Nemec
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: