db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-5525) Precision for UPPER function is wrong if the returned value is longer than the literal argument
Date Thu, 08 Dec 2011 16:47:39 GMT

    [ https://issues.apache.org/jira/browse/DERBY-5525?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13165320#comment-13165320
] 

Knut Anders Hatlen commented on DERBY-5525:
-------------------------------------------

For the string literal case, I thought maybe constant folding might do the trick, so I added
this method to SimpleStringOperatorNode:

    ValueNode evaluateConstantExpressions() throws StandardException {
        if (operand instanceof CharConstantNode) {
            CharConstantNode node = (CharConstantNode) operand;
            StringDataValue val = (StringDataValue) node.getValue();
            if (methodName.equals("upper")) {
                val = val.upper(null);
            } else {
                val = val.lower(null);
            }
            return (ValueNode) getNodeFactory().getNode(
                    C_NodeTypes.CHAR_CONSTANT_NODE,
                    val.getString(),
                    getContextManager());
        }

        return this;
    }

However, the meta-data seems to have been calculated before we do constant folding, so the
precision is still wrong:

ij> values upper('Straße');
1     
------
STRAS&

1 row selected

However, the constant folding appears to be an improvement, since wrapping calling LENGTH
on the result from UPPER changed from

ij> values length(upper('Straße'));
1          
-----------
6          

1 row selected

to

ij> values length(upper('Straße'));
1          
-----------
7          

1 row selected
                
> Precision for UPPER function is wrong if the returned value is longer than the literal
argument
> -----------------------------------------------------------------------------------------------
>
>                 Key: DERBY-5525
>                 URL: https://issues.apache.org/jira/browse/DERBY-5525
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.8.2.2
>            Reporter: Knut Anders Hatlen
>
> Seen in ij in a database with territory based collation and German locale:
> ==vv= COPIED FROM IJ CONSOLE =vv==
> ij> VALUES UCASE('Straßenbahn');
> 1
> -----------
> STRASSENBA&
> 1 Zeile ausgewählt
> ==================================
> And with JDBC calls:
>     Connection c = DriverManager.getConnection(
>             "jdbc:derby:memory:db;create=true;territory=de_DE;" +
>             "collation=TERRITORY_BASED");
>     Statement s = c.createStatement();
>     ResultSet rs = s.executeQuery("values upper('Straße')");
>     System.out.println(rs.getMetaData().getPrecision(1));
>     rs.next();
>     System.out.println(rs.getString(1));
> This prints
> 6
> STRASSE
> The precision is wrong, since the returned value is 7 characters long.

--
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

       

Mime
View raw message