You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@chemistry.apache.org by "Bojan Nemec (Created) (JIRA)" <ji...@apache.org> on 2012/02/02 14:03:53 UTC

[jira] [Created] (CMIS-498) Aphostrophes in hard coded string literals are removed in org.apache.chemistry.opencmis.client.runtime.QueryStatementImpl

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

                 Key: CMIS-498
                 URL: https://issues.apache.org/jira/browse/CMIS-498
             Project: Chemistry
          Issue Type: Bug
          Components: opencmis-client
    Affects Versions: OpenCMIS 0.6.0
         Environment: Ubuntu 11.04 64bit OpenJDK Runtime Environment (IcedTea6 1.10.4) (6b22-1.10.4-0ubuntu1~11.04.2)
            Reporter: Bojan Nemec


Aphostrophes in hard coded string literals are removed.

A simple query without parameters will not work:

{code}
QueryStatement st = session.createQueryStatement("select * from cmis:document where cmis:createdBy = \'admin\'");
System.out.println(st.toQueryString());
{code}

prints out

{code}select * from cmis:document where cmis:createdBy = admin{code}

instead of

{code}select * from cmis:document where cmis:createdBy = 'admin'{code}

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:
{code}
    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();
    }
{code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (CMIS-498) Aphostrophes in hard coded string literals are removed in org.apache.chemistry.opencmis.client.runtime.QueryStatementImpl

Posted by "Florian Müller (Resolved JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CMIS-498?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Florian Müller resolved CMIS-498.
---------------------------------

       Resolution: Fixed
    Fix Version/s: OpenCMIS 0.7.0

Thanks for the report!
                
> Aphostrophes in hard coded string literals are removed in org.apache.chemistry.opencmis.client.runtime.QueryStatementImpl
> -------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CMIS-498
>                 URL: https://issues.apache.org/jira/browse/CMIS-498
>             Project: Chemistry
>          Issue Type: Bug
>          Components: opencmis-client
>    Affects Versions: OpenCMIS 0.6.0
>         Environment: Ubuntu 11.04 64bit OpenJDK Runtime Environment (IcedTea6 1.10.4) (6b22-1.10.4-0ubuntu1~11.04.2)
>            Reporter: Bojan Nemec
>            Assignee: Florian Müller
>              Labels: newbie
>             Fix For: OpenCMIS 0.7.0
>
>
> Aphostrophes in hard coded string literals are removed.
> A simple query without parameters will not work:
> {code}
> QueryStatement st = session.createQueryStatement("select * from cmis:document where cmis:createdBy = \'admin\'");
> System.out.println(st.toQueryString());
> {code}
> prints out
> {code}select * from cmis:document where cmis:createdBy = admin{code}
> instead of
> {code}select * from cmis:document where cmis:createdBy = 'admin'{code}
> 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:
> {code}
>     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();
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Assigned] (CMIS-498) Aphostrophes in hard coded string literals are removed in org.apache.chemistry.opencmis.client.runtime.QueryStatementImpl

Posted by "Florian Müller (Assigned JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CMIS-498?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Florian Müller reassigned CMIS-498:
-----------------------------------

    Assignee: Florian Müller
    
> Aphostrophes in hard coded string literals are removed in org.apache.chemistry.opencmis.client.runtime.QueryStatementImpl
> -------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CMIS-498
>                 URL: https://issues.apache.org/jira/browse/CMIS-498
>             Project: Chemistry
>          Issue Type: Bug
>          Components: opencmis-client
>    Affects Versions: OpenCMIS 0.6.0
>         Environment: Ubuntu 11.04 64bit OpenJDK Runtime Environment (IcedTea6 1.10.4) (6b22-1.10.4-0ubuntu1~11.04.2)
>            Reporter: Bojan Nemec
>            Assignee: Florian Müller
>              Labels: newbie
>
> Aphostrophes in hard coded string literals are removed.
> A simple query without parameters will not work:
> {code}
> QueryStatement st = session.createQueryStatement("select * from cmis:document where cmis:createdBy = \'admin\'");
> System.out.println(st.toQueryString());
> {code}
> prints out
> {code}select * from cmis:document where cmis:createdBy = admin{code}
> instead of
> {code}select * from cmis:document where cmis:createdBy = 'admin'{code}
> 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:
> {code}
>     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();
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira