Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Merge [TRAFODION-1262] PR-853 ODBC:Varchar col operation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzuo committed Dec 19, 2016
2 parents 4d33839 + e0cf313 commit d6a5b79
Show file tree
Hide file tree
Showing 11 changed files with 742 additions and 269 deletions.
17 changes: 14 additions & 3 deletions core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ unsigned long CDescRec::setDescRec(short DescMode, SQLItemDesc_def *SQLItemDesc)
strcpy((char*)m_DescLiteralPrefix,"'");
strcpy((char*)m_DescLiteralSuffix,"'");
m_DescLength = SQLItemDesc->maxLen;
m_DescPrecision = m_DescLength;
switch (m_SQLCharset)
{
case SQLCHARSETCODE_ISO88591:
Expand Down Expand Up @@ -492,6 +493,7 @@ unsigned long CDescRec::setDescRec(short DescMode, SQLItemDesc_def *SQLItemDesc)
strcpy((char*)m_DescLiteralPrefix,"N'");
strcpy((char*)m_DescLiteralSuffix,"'");
m_DescLength = SQLItemDesc->maxLen/2;
m_DescPrecision = m_DescLength;
sprintf((char *)m_DescLocalTypeName,"%s CHARACTER SET %s", gSQLDatatypeMap[i].typeName, SQLCHARSETSTRING_UNICODE);
break;
case SQL_INTERVAL_SECOND:
Expand Down Expand Up @@ -595,9 +597,19 @@ unsigned long CDescRec::setDescRec(short DescMode, SQLItemDesc_def *SQLItemDesc)
break;
case SQLTYPECODE_VARCHAR_WITH_LENGTH:
if (m_SQLCharset == SQLCHARSETCODE_UCS2)
m_SQLOctetLength = SQLItemDesc->maxLen+4;
{
if(SQLItemDesc->maxLen > SHRT_MAX)
m_SQLOctetLength = SQLItemDesc->maxLen+6;
else
m_SQLOctetLength = SQLItemDesc->maxLen+4;
}
else
m_SQLOctetLength = SQLItemDesc->maxLen+3;
{
if(SQLItemDesc->maxLen > SHRT_MAX)
m_SQLOctetLength = SQLItemDesc->maxLen+5;
else
m_SQLOctetLength = SQLItemDesc->maxLen+3;
}
m_DescCaseSensitive = SQL_TRUE;
m_DescSearchable = SQL_PRED_SEARCHABLE;
break;
Expand Down Expand Up @@ -664,7 +676,6 @@ unsigned long CDescRec::setDescRec(short DescMode, SQLItemDesc_def *SQLItemDesc)
case SQL_LONGVARCHAR:
case SQL_WCHAR:
case SQL_WVARCHAR:
m_DescPrecision = m_DescLength;
m_DescDatetimeIntervalPrecision = m_DescLength;
break;
case SQL_INTERVAL_SECOND:
Expand Down
6 changes: 3 additions & 3 deletions core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class CDescRec {
SQLSMALLINT m_DescDatetimeIntervalCode;
SQLINTEGER m_DescOctetLength;
SQLUINTEGER m_DescLength;
SQLSMALLINT m_DescPrecision;
SQLINTEGER m_DescPrecision;
SQLSMALLINT m_DescScale;
SQLINTEGER m_DescDatetimeIntervalPrecision;
SQLSMALLINT m_DescFixedPrecScale;
Expand All @@ -131,8 +131,8 @@ class CDescRec {
SQLINTEGER m_ODBCCharset;
SQLSMALLINT m_SQLDataType;
SQLSMALLINT m_ODBCDataType;
SQLSMALLINT m_SQLPrecision;
SQLSMALLINT m_ODBCPrecision;
SQLINTEGER m_SQLPrecision;
SQLINTEGER m_ODBCPrecision;
SQLSMALLINT m_ODBCScale;
SQLSMALLINT m_SQLDatetimeCode;
SQLINTEGER m_SQLOctetLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ SQLRETURN ICUConverter::WCharToUTF8(UChar* wst, int wstlen, char *st, int stlen,

SQLRETURN ICUConverter::UTF8ToWChar(char *st, int stlen, UChar *wst, int wstlen, int *translen, char *error, DWORD dwFlags, int* reqLen)
{
short len;
int len;
SQLRETURN rc = SQL_SUCCESS;
DWORD lastError;
error[0] ='\0';
Expand Down Expand Up @@ -1158,7 +1158,7 @@ SQLRETURN ICUConverter::WCharToISO88591(UChar* wst, int wstlen, char *st, int st

SQLRETURN ICUConverter::ISO88591ToWChar(char *st, int stlen, UChar *wst, int wstlen, int *translen, char *error, DWORD dwFlags, int* reqLen)
{
short len;
int len;
SQLRETURN rc = SQL_SUCCESS;
DWORD lastError;
error[0] ='\0';
Expand Down
49 changes: 39 additions & 10 deletions core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER ODBCAppVersion,
SQLSMALLINT SQLDatetimeCode,
SQLPOINTER targetDataPtr,
SQLINTEGER targetLength,
SQLSMALLINT targetPrecision,
SQLINTEGER targetPrecision,
SQLSMALLINT targetScale,
SQLSMALLINT targetUnsigned,
SQLINTEGER targetCharSet,
Expand Down Expand Up @@ -361,7 +361,16 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER ODBCAppVersion,
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
case SQL_WVARCHAR:
Offset = sizeof(USHORT); //Note there is no break, I want it to fall thru
{
if(targetPrecision > SHRT_MAX)
{
Offset = sizeof(UINT);
}
else
{
Offset = sizeof(USHORT);
}
}
case SQL_CHAR:
case SQL_WCHAR:
switch (CDataType)
Expand Down Expand Up @@ -646,12 +655,10 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER ODBCAppVersion,
if (Offset != 0)
{
//#ifndef MXSUN
if(DataLen>32767){
*(int *)targetDataPtr = DataLen;
if(targetPrecision > SHRT_MAX){
outDataPtr = (unsigned char *)targetDataPtr + sizeof(int);
}
else{
*(unsigned short *)targetDataPtr = DataLen;
outDataPtr = (unsigned char *)targetDataPtr + sizeof(USHORT);
}
//#else
Expand Down Expand Up @@ -3210,7 +3217,12 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER ODBCAppVersion,
// }
}
if (Offset != 0)
*(unsigned short *)targetDataPtr = DataLen;
{
if(targetPrecision > SHRT_MAX)
*(unsigned int *)targetDataPtr = DataLen;
else
*(unsigned short *)targetDataPtr = DataLen;
}
}
else if (targetCharSet == SQLCHARSETCODE_UCS2)
{
Expand Down Expand Up @@ -3256,10 +3268,22 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER ODBCAppVersion,
DataLen = translateLength;
}
if (Offset != 0)
if(iconv->getUCS2Translation())
*(unsigned short *)targetDataPtr = DataLen*2;
{
if(targetPrecision > SHRT_MAX)
{
if(iconv->getUCS2Translation())
*(unsigned int *)targetDataPtr = DataLen*2;
else
*(unsigned int *)targetDataPtr = DataLen;
}
else
*(unsigned short *)targetDataPtr = DataLen;
{
if(iconv->getUCS2Translation())
*(unsigned short *)targetDataPtr = DataLen*2;
else
*(unsigned short *)targetDataPtr = DataLen;
}
}
}
// needs to work with UTF8 columns
else if (targetCharSet == SQLCHARSETCODE_UTF8)
Expand Down Expand Up @@ -3305,7 +3329,12 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER ODBCAppVersion,
DataLen = translateLength;
}
if (Offset != 0)
*(unsigned short *)targetDataPtr = DataLen;
{
if(targetPrecision > SHRT_MAX)
*(unsigned int *)targetDataPtr = DataLen;
else
*(unsigned short *)targetDataPtr = DataLen;
}
}

if (ODBCDataType == SQL_WCHAR || ODBCDataType == SQL_WVARCHAR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ unsigned long ConvertCToSQL(SQLINTEGER ODBCAppVersion,
SQLSMALLINT SQLDatetimeCode,
SQLPOINTER targetDataPtr,
SQLINTEGER targetLength,
SQLSMALLINT targetPrecision,
SQLINTEGER targetPrecision,
SQLSMALLINT targetScale,
SQLSMALLINT targetUnsigned,
SQLINTEGER targetCharSet,
Expand Down
Loading

0 comments on commit d6a5b79

Please sign in to comment.