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

ASF GitHub Bot commented on TRAFODION-3099:
-------------------------------------------

Github user zellerh commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1623#discussion_r198553974
  
    --- Diff: core/sql/cli/CliExpExchange.cpp ---
    @@ -3383,6 +3383,94 @@ InputOutputExpr::inputRowwiseRowsetValues(atp_struct 
*atp,
       return ex_expr::EXPR_ERROR;
     }
     
    +void handleCharsetPerfix(Descriptor * inputDesc)
    +{
    +    char perfix[MAX_CHAR_SET_STRING_LENGTH];
    +
    +    if(inputDesc)
    +    {
    +        for (Lng32 entry = 1; entry <= inputDesc->getUsedEntryCount(); 
++entry)
    +        {
    +            Lng32 perfix_beg = -1;
    +            Lng32 perfix_end = 0;
    +            char* source = inputDesc->getVarData(entry);
    +            Lng32 valueLength = inputDesc->getVarDataLength(entry);
    +            if (source)
    +            {
    +                // get charset perfix beg loc
    +                for (Lng32 i = 0; i < valueLength && i < 
MAX_CHAR_SET_STRING_LENGTH; ++i)
    +                {
    +                    if(source[i] == '_' || TOUPPER(source[i]) =='N')
    +                    {
    +                        perfix_beg = i;
    +                        break;
    +                    }
    +
    +                    if (source[i] == '\'')
    +                        return;
    +                }
    +
    +                if (perfix_beg < 0)
    +                    return;
    +
    +                // get charset perfix end loc
    +                Lng32 perfix_ind = 0;
    +
    +                if (source[perfix_beg] == 'N')
    +                {
    +                    perfix[perfix_ind] = 'N';
    +                    perfix_ind = 1;
    +                }
    +
    +                for (Lng32 i = perfix_beg+1; i < valueLength && i < 
MAX_CHAR_SET_STRING_LENGTH; ++i)
    +                {
    +                    if(source[i] != '\'' && source[i] != 0)
    +                    {
    +                       perfix[perfix_ind] = TOUPPER(source[i]);
    +                       ++perfix_ind;
    +                    }
    +
    +                    if(source[i] == '\'')
    +                    {
    +                        perfix[perfix_ind] = 0;
    +                        perfix_end = i;
    +                        break;
    +                    }
    +                }
    +
    +                //perfix_cs
    +                CharInfo::CharSet cs = CharInfo::getCharSetEnum(perfix);
    +                if(str_len(perfix) == 1 AND perfix[0] == 'N')
    +                   cs = CharInfo::UNICODE;
    +
    +                //if perfix_cs is UnknownCharSet direct return
    +                if(cs == CharInfo::UnknownCharSet)
    +                    return;
    +
    +                // remove cs
    +                Lng32 valEnd = 0;
    +                for (Lng32 i = perfix_end+1; i < valueLength; ++i)
    +                {
    +                    if (source[i] == '\'')
    +                    {
    +                        valEnd = i-1;
    +                        break;
    +                    }
    +                }
    +                Lng32 valBeg = perfix_end+1;
    +                if (!source[valBeg])
    +                {
    +                    valBeg += 1;
    +                }
    +                memcpy(&source[perfix_beg], &source[valBeg], 
valEnd-valBeg+1);
    +                memcpy(&source[valEnd-valBeg+1+perfix_beg], 
&source[valEnd+3], valBeg+2);
    --- End diff --
    
    Wouldn't this copy uninitialized memory beyond the end of the value? This 
also shows a problem, that you would need to shorten the string. Another 
indicator that maybe the bug is in trafci and not here (see comment below).


> Prepare execute fails to handle N'<string>', _iso88591'<string>', 
> _utf8'<string>' for a nchar column
> ----------------------------------------------------------------------------------------------------
>
>                 Key: TRAFODION-3099
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-3099
>             Project: Apache Trafodion
>          Issue Type: Bug
>            Reporter: shaoyong.li
>            Assignee: shaoyong.li
>            Priority: Major
>
> As shown below, for a nchar column c1 with a value of N'ABCD' in the table t, 
> a direct select from t with predicates c1=N'ABCD', c1='ABCD', 
> c1=_iso88591'ABCD', and c1=_utf8'ABCD' all are able to find the match. 
> However, with a prepared query xx executed using a parameter ? in sqlci and 
> trafci operator have failed.
> From sqlci:
>  >>drop table if exists t;
>  
>  --- SQL operation complete.
>  >>create table t (c1 nchar(10));
>  
>  --- SQL operation complete.
>  >>insert into t values (N'ABCD');
>  
>  --- 1 row(s) inserted.
>  >>select * from t;
>  
>  C1
>  --------------------
>  
>  ABCD
>  
>  --- 1 row(s) selected.
>  >>select * from t where c1=N'ABCD';
>  
>  C1
>  --------------------
>  
>  ABCD
>  
>  --- 1 row(s) selected.
>  >>select * from t where c1='ABCD';
>  
>  C1
>  --------------------
>  
>  ABCD
>  
>  --- 1 row(s) selected.
>  >>select * from t where c1=_iso88591'ABCD';
>  
>  C1
>  --------------------
>  
>  ABCD
>  
>  --- 1 row(s) selected.
>  >>select * from t where c1=_utf8'ABCD';
>  
>  C1
>  --------------------
>  
>  ABCD
>  
>  --- 1 row(s) selected.
>  >>
>  >>prepare xx from select * from t where c1=?;
>  
>  --- SQL command prepared.
>  >>execute xx using N'ABCD';
>  
>  --- 0 row(s) selected.
>  >>execute xx using 'ABCD';
>  
>  C1
>  --------------------
>  
>  ABCD
>  
>  --- 1 row(s) selected.
>  >>execute xx using _iso88591'ABCD';
>  
>  C1
>  --------------------
>  
>  ABCD
>  
>  --- 1 row(s) selected.
>  >>execute xx using _utf8'ABCD';
>  
>  C1
>  --------------------
>  
>  ABCD
>  
>  --- 1 row(s) selected.
>  
>  From trafci:
>  
>  trafci sees even more failures:
>  
>  $ trafci
>  
>  Welcome to EsgynDB Command Interface
>  Copyright (c) 2015-2018 Esgyn Corporation
>  
>  User Name: db__root
>  Host Name/IP Address: localhost:23400
>  
>  Connected to EsgynDB Advanced
>  
>  SQL>obey mytest.sql;
>  
>  SQL>drop table if exists t;
>  
>  --- SQL operation complete.
>  
>  SQL>create table t (c1 nchar(10));
>  
>  --- SQL operation complete.
>  
>  SQL>insert into t values (N'ABCD');
>  
>  --- 1 row(s) inserted.
>  
>  SQL>select * from t;
>  
>  C1
>  --------------------
>  ABCD
>  
>  --- 1 row(s) selected.
>  
>  SQL>select * from t where c1=N'ABCD';
>  
>  C1
>  --------------------
>  ABCD
>  
>  --- 1 row(s) selected.
>  
>  SQL>select * from t where c1='ABCD';
>  
>  C1
>  --------------------
>  ABCD
>  
>  --- 1 row(s) selected.
>  
>  SQL>select * from t where c1=_iso88591'ABCD';
>  
>  C1
>  --------------------
>  ABCD
>  
>  --- 1 row(s) selected.
>  
>  SQL>select * from t where c1=_utf8'ABCD';
>  
>  C1
>  --------------------
>  ABCD
>  
>  --- 1 row(s) selected.
>  
>  SQL>prepare xx from select * from t where c1=?;
>  
>  --- SQL command prepared.
>  
>  SQL>execute xx using N'ABCD';
>  
>  --- 0 row(s) selected.
>  
>  SQL>execute xx using 'ABCD';
>  
>  C1
>  --------------------
>  ABCD
>  
>  --- 1 row(s) selected.
>  
>  SQL>execute xx using _iso88591'ABCD';
>  
>  *** ERROR[29183] Invalid Parameter Value: CHAR input data is longer than the 
> length for column: 0
>  
>  SQL>execute xx using _utf8'ABCD';
>  
>  *** ERROR[29183] Invalid Parameter Value: CHAR input data is longer than the 
> length for column: 0
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to