Menu

JtdsDatabaseMetaData.processEscapes()

Steve
2015-06-03
2016-05-31
  • Steve

    Steve - 2015-06-03

    I'm a bit confused about the purpose of the processEscapes() method.
    It is used to process parameters for stored procedure calls, where the parameter is a pattern string. It seems to be replacing escape sequences such as '\x' with the unescaped character (or rather the alternate escape sequence '[x]'). Is this behaviour defined anywhere?

    I spent a while trying to figure out what was going wrong with my code, which was basically this:

    String schema = "domain\\user";
    String table = "tablename";
    ResultSet rs = connection.getMetaData().getColumns(null, schema, table, null);
    

    The ResultSet returned was empty, even though the table exists in the specified schema. I had to change my schema string to get it to work:

    String schema = "domain\\\\user";
    

    The only information I could find about how a pattern string should be formatted is from the Java API which says:

    Within a pattern String, "%" means match any substring of 0 or more characters, and "_" means match any one character.

    Thanks,
    Steve

     
  • Alois Mühleder

    Alois Mühleder - 2016-05-31

    Are there any news? I have the same problem with backslash in my schema name.
    But I cannot write four backslashes.

    Regards,
    Alois

     
  • Joey Smith

    Joey Smith - 2016-05-31

    This has nothing to do with processEscapes(), it is just part of the nature of Java's String implementation; "foo\\bar" is processed as a single backslash. If you want two backslashes, you need to say "\\\\".

    See this repl.it for example. You will need to do pre-processing on the string to make sure it has the desired number of backslashes - if you cannot know in advance how many are needed, try parameterizing the whole thing and constructing it with the correct number of backslashes dynamically (e.g., using the char code).

     

    Last edit: Joey Smith 2016-05-31

Log in to post a comment.