You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by ry...@apache.org on 2016/12/19 01:52:58 UTC

[1/3] incubator-trafodion git commit: [TRAFODION-1262]ODBC:Varchar col operation fails fix bugs on varchar col(>32k) insert/select failure

Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 4d3383962 -> d6a5b79b0


[TRAFODION-1262]ODBC:Varchar col operation fails
fix bugs on varchar col(>32k) insert/select failure


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/c4a39d4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/c4a39d4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/c4a39d4d

Branch: refs/heads/master
Commit: c4a39d4d2c5c8d952e9c4b4b87d962332183d34f
Parents: ea16d38
Author: rwbzx <xi...@esgyn.cn>
Authored: Mon Nov 28 14:21:51 2016 +0800
Committer: rwbzx <xi...@esgyn.cn>
Committed: Mon Nov 28 14:21:51 2016 +0800

----------------------------------------------------------------------
 .../odbc/odbcclient/unixcli/cli/cdesc.cpp       |  17 +-
 .../odbc/odbcclient/unixcli/cli/cdesc.h         |   6 +-
 .../odbc/odbcclient/unixcli/cli/ctosqlconv.cpp  |  49 +-
 .../odbc/odbcclient/unixcli/cli/ctosqlconv.h    |   2 +-
 .../odbc/odbcclient/unixcli/cli/sqltocconv.cpp  | 403 +++++++++++-----
 win-odbc64/odbcclient/drvr35/cdesc.cpp          |  25 +-
 win-odbc64/odbcclient/drvr35/cdesc.h            |   6 +-
 win-odbc64/odbcclient/drvr35/ctosqlconv.cpp     |  43 +-
 win-odbc64/odbcclient/drvr35/ctosqlconv.h       |   2 +-
 win-odbc64/odbcclient/drvr35/sqltocconv.cpp     | 457 +++++++++++++------
 10 files changed, 740 insertions(+), 270 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp
----------------------------------------------------------------------
diff --git a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp
index b397899..b844519 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp
@@ -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:
@@ -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:
@@ -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 > 0x7fff)
+				m_SQLOctetLength = SQLItemDesc->maxLen+6;
+			else
+				m_SQLOctetLength = SQLItemDesc->maxLen+4;
+		}
 		else
-			m_SQLOctetLength = SQLItemDesc->maxLen+3;
+		{
+			if(SQLItemDesc->maxLen > 0x7fff)
+				m_SQLOctetLength = SQLItemDesc->maxLen+5;
+			else
+				m_SQLOctetLength = SQLItemDesc->maxLen+3;
+		}
 		m_DescCaseSensitive = SQL_TRUE;
 		m_DescSearchable = SQL_PRED_SEARCHABLE;
 		break;
@@ -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:

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.h
----------------------------------------------------------------------
diff --git a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.h b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.h
index abc89d9..54ae76f 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.h
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.h
@@ -111,7 +111,7 @@ public:
 	SQLSMALLINT	m_DescDatetimeIntervalCode;
 	SQLINTEGER	m_DescOctetLength;
 	SQLUINTEGER	m_DescLength;
-	SQLSMALLINT	m_DescPrecision;
+	SQLINTEGER	m_DescPrecision;
 	SQLSMALLINT	m_DescScale;
 	SQLINTEGER	m_DescDatetimeIntervalPrecision;
 	SQLSMALLINT	m_DescFixedPrecScale;
@@ -131,8 +131,8 @@ public:
 	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;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
----------------------------------------------------------------------
diff --git a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
index 73b6976..5663f09 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
@@ -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,
@@ -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 > 0x7fff)
+			{
+				Offset = sizeof(UINT);
+			}
+			else
+			{
+				Offset = sizeof(USHORT);
+			}
+		}
 	case SQL_CHAR:
 	case SQL_WCHAR:
 		switch (CDataType)
@@ -646,12 +655,10 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 		if (Offset != 0)
 		{
 //#ifndef MXSUN
-			if(DataLen>32767){
-				*(int *)targetDataPtr = DataLen;
+			if(targetPrecision > 0x7fff){
 				outDataPtr = (unsigned char *)targetDataPtr + sizeof(int);
 			}
 			else{
-				*(unsigned short *)targetDataPtr = DataLen;
 				outDataPtr = (unsigned char *)targetDataPtr + sizeof(USHORT);
 			}
 //#else
@@ -3210,7 +3217,12 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 //					}
 				}
 				if (Offset != 0)
-					*(unsigned short *)targetDataPtr = DataLen;
+				{
+					if(targetPrecision > 0x7fff)
+						*(unsigned int *)targetDataPtr = DataLen;
+					else
+						*(unsigned short *)targetDataPtr = DataLen;
+				}
 			}
 			else if (targetCharSet == SQLCHARSETCODE_UCS2)
 			{
@@ -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 > 0x7fff)
+					{
+						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)
@@ -3305,7 +3329,12 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
                                                 DataLen = translateLength;
 				}
 				if (Offset != 0)
-					*(unsigned short *)targetDataPtr = DataLen;
+				{
+					if(targetPrecision > 0x7fff)
+						*(unsigned int *)targetDataPtr = DataLen;
+					else
+						*(unsigned short *)targetDataPtr = DataLen;
+				}
 			}
 
 			if (ODBCDataType == SQL_WCHAR || ODBCDataType == SQL_WVARCHAR)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.h
----------------------------------------------------------------------
diff --git a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.h b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.h
index 16456ba..87d67f1 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.h
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.h
@@ -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,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/sqltocconv.cpp
----------------------------------------------------------------------
diff --git a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/sqltocconv.cpp b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/sqltocconv.cpp
index f248c4d..d7d8ec1 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/sqltocconv.cpp
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/sqltocconv.cpp
@@ -1125,27 +1125,64 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					DataLen = *(USHORT *)srcDataPtr;
-					if (DataLen == 0)
-					return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+					if(isshort)
 					{
-						if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-							return IDS_22_003;
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the length
-						srcLength = TransStringLength + 1;
+						if (!ctoi64(cTmpBuf, tempVal64 ))
+							return IDS_22_003;
 					}
 					else
 					{
-						memcpy(cTmpBuf, (char*)srcDataPtr, DataLen + 2);
-						cTmpBuf[DataLen + 2] = 0;
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+2, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
+						}
+						if (!ctoi64(cTmpBuf, tempVal64 ))
+							return IDS_22_003;
 					}
-					if (!ctoi64(cTmpBuf+2, tempVal64 ))
-						return IDS_22_003;
 				}
 			}
 			if ((retCode = ConvertSQLCharToNumeric(cTmpBuf, srcLength, ODBCDataType, dTmp)) != SQL_SUCCESS)
@@ -1504,25 +1541,59 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					DataLen = *(USHORT *)srcDataPtr;
-					if (DataLen == 0)
-						return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+					if(isshort)
 					{
-						if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-							return IDS_22_003;
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the lengths
-						DataLen = sizeof(DATE_STRUCT); 
-						srcLength = TransStringLength + 1;
 					}
 					else
 					{
-						memcpy(cTmpBuf, (char*)srcDataPtr, DataLen + 2);
-						cTmpBuf[DataLen + 2] = 0;
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+2, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
+						}
 					}
 				}
 			}
@@ -1716,24 +1787,59 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					SQLINTEGER tmpDataLen = *(USHORT *)srcDataPtr;
-					if (tmpDataLen == 0)
-					return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+					if(isshort)
 					{
-						if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, tmpDataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-							return IDS_22_003;
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the length
-						srcLength = TransStringLength + 1;
 					}
 					else
 					{
-						memcpy(cTmpBuf, (char*)srcDataPtr , tmpDataLen + 2);
-						cTmpBuf[tmpDataLen + 2] = 0;
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+2, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
+						}
 					}
 				}
 			}
@@ -1898,28 +2004,60 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					DataLen = *(USHORT *)srcDataPtr;
-					if (DataLen == 0)
-					return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+					if(isshort)
 					{
-						if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						// We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-						// But this should never happen!
-							return IDS_22_003;
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the length
-						srcLength = TransStringLength + 1;
 					}
 					else
 					{
-						memcpy(cTmpBuf, (char*)srcDataPtr, DataLen + 2);
-						cTmpBuf[DataLen + 2] = 0;
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+2, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
+						}
 					}
-					//reset DataLen
-					DataLen = sizeof(TIMESTAMP_STRUCT);
 				}
 			}
 			if ((retCode = ConvertSQLCharToDate(ODBCDataType, cTmpBuf, srcLength, SQL_C_TIMESTAMP, 
@@ -2274,6 +2412,7 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		default:
 			return IDS_07_006;
 		}
+		NullTerminate = TRUE;
 		break; // End of switch for SQL_C_BINARY 
 	case SQL_C_DEFAULT:
 		switch (ODBCDataType)
@@ -2699,28 +2838,62 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		case SQL_VARCHAR:
 		case SQL_LONGVARCHAR:
 		case SQL_WVARCHAR:
-			DataLen = *(USHORT *)srcDataPtr;
-			if (DataLen == 0)
-				return SQL_NO_DATA;
-			DataPtr = (char *)srcDataPtr + sizeof(USHORT);
-			if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+			if(isshort)
 			{
-				int TransStringLength = 0;
-				if(iconv->WCharToUTF8((UChar*)DataPtr, DataLen/2, (char*)cTmpBuf,
-					sizeof(cTmpBuf) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+				DataLen = *(USHORT *)srcDataPtr;
+				if (DataLen == 0)
+				return SQL_NO_DATA;
+				if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 				{
-				//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-				//Add more trace
-					return IDS_07_003;
+					int TransStringLength = 0;
+					if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf,
+						(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+					{
+					//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+						return IDS_07_003;
+					}
+					srcLength = TransStringLength + 1;
+				}
+				else
+				{
+					if((DataLen + 1) <= sizeof(cTmpBuf))
+					{
+						memcpy(cTmpBuf, (char*)srcDataPtr+2, DataLen);
+						srcLength = DataLen + 1;
+						cTmpBuf[DataLen] = 0;
+					}
+					else
+						return IDS_07_003;
 				}
-				srcLength = TransStringLength + 1;
 			}
 			else
 			{
-				if (sizeof(cTmpBuf) < DataLen )
-					return IDS_07_003;
-				memcpy(cTmpBuf, (char*)srcDataPtr + 2 , DataLen);
-				cTmpBuf[DataLen] = 0;
+				DataLen = *(UINT *)srcDataPtr;
+				if (DataLen == 0)
+				return SQL_NO_DATA;
+				if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+				{
+
+					int TransStringLength = 0;
+					if(iconv->WCharToUTF8((UChar*)srcDataPtr+2, DataLen/2, (char*)cTmpBuf,
+						(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+					{
+					//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+						return IDS_07_003;
+					}
+					srcLength = TransStringLength + 1;
+				}
+				else
+				{
+					if((DataLen + 1) <= sizeof(cTmpBuf))
+					{
+						memcpy(cTmpBuf, (char*)srcDataPtr+4, DataLen);
+						srcLength = DataLen + 1;
+						cTmpBuf[DataLen] = 0;
+					}
+					else
+						return IDS_07_003;
+				}
 			}
 			useDouble = FALSE;
 			break;
@@ -3007,28 +3180,59 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					DataLen = *(USHORT *)srcDataPtr;
-					if (DataLen == 0)
-					return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+					if(isshort)
 					{
-						if (sizeof (cTmpBuf) <= DataLen/2) //Avoid a seg-violation
-							return IDS_07_003;
-						if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-							return IDS_07_003;
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_07_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_07_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the length
-						srcLength = TransStringLength + 1;
 					}
 					else
 					{
-						if (sizeof (cTmpBuf) <= DataLen + 2)
-							return IDS_07_003;
-						memcpy(cTmpBuf, (char*)srcDataPtr, DataLen + 2);
-						cTmpBuf[DataLen + 2] = 0;
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+						return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if(iconv->WCharToUTF8((UChar*)srcDataPtr+2, DataLen/2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)) , &TransStringLength, (char*)errorMsg) != SQL_SUCCESS)
+							{
+							//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_07_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_07_003;
+						}
 					}
 				}
 				if ((retCode = ConvertSQLCharToInterval(ODBCDataType, cTmpBuf, srcLength, CDataType, 
@@ -3923,6 +4127,9 @@ unsigned long ODBC::ConvertSQLCharToNumeric(SQLPOINTER srcDataPtr, SQLINTEGER sr
 	switch (ODBCDataType) {
 	case SQL_CHAR:
 	case SQL_WCHAR:
+	case SQL_VARCHAR:
+	case SQL_LONGVARCHAR:
+	case SQL_WVARCHAR:
 		str = (char *)srcDataPtr;
 		tempLen = srcLength-1;
 		if (str[ tempLen - 1 ] == ' ')
@@ -3932,12 +4139,6 @@ unsigned long ODBC::ConvertSQLCharToNumeric(SQLPOINTER srcDataPtr, SQLINTEGER sr
 			tempLen = strlen(str);
 		}
 		break;
-	case SQL_VARCHAR:
-	case SQL_LONGVARCHAR:
-	case SQL_WVARCHAR:
-		tempLen = *(USHORT *)srcDataPtr;
-		str = (char *)srcDataPtr+sizeof(USHORT);
-		break;
 	case SQL_INTERVAL_MONTH:
 	case SQL_INTERVAL_YEAR:
 	case SQL_INTERVAL_YEAR_TO_MONTH:
@@ -3987,6 +4188,9 @@ unsigned long ODBC::ConvertSQLCharToDate(SQLSMALLINT ODBCDataType,
 	{
 	case SQL_CHAR:
 	case SQL_WCHAR:
+	case SQL_VARCHAR:
+	case SQL_LONGVARCHAR:
+	case SQL_WVARCHAR:
 		len = srcLength-1;
 		strPtr = (char *)srcDataPtr;
 		if (strPtr[ len - 1 ] == ' ')
@@ -3996,12 +4200,6 @@ unsigned long ODBC::ConvertSQLCharToDate(SQLSMALLINT ODBCDataType,
 			len = strlen(strPtr);
 		}
 		break;
-	case SQL_VARCHAR:
-	case SQL_LONGVARCHAR:
-	case SQL_WVARCHAR:
-		len = *(USHORT *)srcDataPtr;
-		strPtr = (char *)srcDataPtr + sizeof(USHORT);
-		break;
 	default:
 		return IDS_07_006;
 	}
@@ -4228,6 +4426,9 @@ unsigned long ODBC::ConvertSQLCharToInterval(SQLSMALLINT ODBCDataType,
 	{
 	case SQL_CHAR:
 	case SQL_WCHAR:
+	case SQL_VARCHAR:
+	case SQL_LONGVARCHAR:
+	case SQL_WVARCHAR:
 		len = srcLength-1;
 		strPtr = (char *)srcDataPtr;
 		if (strPtr[ len - 1 ] == ' ')
@@ -4237,12 +4438,6 @@ unsigned long ODBC::ConvertSQLCharToInterval(SQLSMALLINT ODBCDataType,
 			len = strlen(strPtr);
 		}
 		break;
-	case SQL_VARCHAR:
-	case SQL_LONGVARCHAR:
-	case SQL_WVARCHAR:
-		len = *(USHORT *)srcDataPtr;
-		strPtr = (char *)srcDataPtr + sizeof(USHORT);
-		break;
 	case SQL_INTERVAL_MONTH:
 	case SQL_INTERVAL_YEAR:
 	case SQL_INTERVAL_YEAR_TO_MONTH:

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/win-odbc64/odbcclient/drvr35/cdesc.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/cdesc.cpp b/win-odbc64/odbcclient/drvr35/cdesc.cpp
index a7e261f..461c13c 100644
--- a/win-odbc64/odbcclient/drvr35/cdesc.cpp
+++ b/win-odbc64/odbcclient/drvr35/cdesc.cpp
@@ -426,6 +426,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:
@@ -453,6 +454,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:
@@ -556,9 +558,27 @@ 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;  //2 bytes for len and 2 bytes of null
+		{
+			if (SQLItemDesc->maxLen > 0x7fff)
+			{
+				m_SQLOctetLength = SQLItemDesc->maxLen + 6;  //4 bytes for len and 2 bytes of null
+			}
+			else
+			{
+				m_SQLOctetLength = SQLItemDesc->maxLen + 4;  //2 bytes for len and 2 bytes of null
+			}
+		}
 		else
-			m_SQLOctetLength = SQLItemDesc->maxLen+3;  //2 bytes for len and 1 byte of null
+		{ 
+			if (SQLItemDesc->maxLen > 0x7fff)
+			{
+				m_SQLOctetLength = SQLItemDesc->maxLen + 5;  //4 bytes for len and 1 byte of null
+			}
+			else
+			{
+				m_SQLOctetLength = SQLItemDesc->maxLen + 3;  //2 bytes for len and 1 byte of null
+			}
+		}
 		m_DescCaseSensitive = SQL_TRUE;
 		m_DescSearchable = SQL_PRED_SEARCHABLE;
 		break;
@@ -625,7 +645,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:

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/win-odbc64/odbcclient/drvr35/cdesc.h
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/cdesc.h b/win-odbc64/odbcclient/drvr35/cdesc.h
index ecd1019..d66c204 100644
--- a/win-odbc64/odbcclient/drvr35/cdesc.h
+++ b/win-odbc64/odbcclient/drvr35/cdesc.h
@@ -95,7 +95,7 @@ private:
 	SQLSMALLINT	m_DescDatetimeIntervalCode;
 	SQLINTEGER	m_DescOctetLength;
 	SQLUINTEGER	m_DescLength;
-	SQLSMALLINT	m_DescPrecision;
+	SQLINTEGER	m_DescPrecision;
 	SQLSMALLINT	m_DescScale;
 	SQLINTEGER	m_DescDatetimeIntervalPrecision;
 	SQLSMALLINT	m_DescFixedPrecScale;
@@ -115,8 +115,8 @@ private:
 	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;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp b/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
index c70b296..f9be84c 100644
--- a/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
+++ b/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
@@ -95,7 +95,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 							SQLSMALLINT	SQLDatetimeCode,
 							SQLPOINTER	targetDataPtr,
 							SQLINTEGER	targetLength,
-							SQLSMALLINT	targetPrecision,
+							SQLINTEGER	targetPrecision,
 							SQLSMALLINT	targetScale,
 							SQLSMALLINT targetUnsigned,
 							SQLINTEGER	targetCharSet,
@@ -284,7 +284,12 @@ 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 > 0x7fff){
+			Offset = sizeof(UINT);
+		}
+		else{
+			Offset = sizeof(USHORT);
+		}
 	case SQL_CHAR:
 	case SQL_WCHAR:
 		switch (CDataType)
@@ -561,14 +566,10 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 		}
 		if (Offset != 0)
 		{
-			if(DataLen>32767){
-				*(int *)targetDataPtr = DataLen;
-				outDataPtr = (unsigned char *)targetDataPtr + sizeof(int);
-			}
-			else{
-				*(unsigned short *)targetDataPtr = DataLen;
+			if (targetPrecision > 0x7fff)
+				outDataPtr = (unsigned char *)targetDataPtr + sizeof(UINT);
+			else
 				outDataPtr = (unsigned char *)targetDataPtr + sizeof(USHORT);
-			}
 		}
 		if (targetCharSet == SQLCHARSETCODE_UCS2)
 			OutLen = targetLength - Offset -2 ; // Remove for Null Pointer;
@@ -3023,8 +3024,13 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 					}
 					DataLen = translateLength;
 				}
-				if (Offset != 0)  
-					*(unsigned short *)targetDataPtr = DataLen*2;
+				if (Offset != 0)
+				{
+					if (targetPrecision > 0x7fff)
+						*(unsigned int *)targetDataPtr = DataLen * 2;
+					else
+						*(unsigned short *)targetDataPtr = DataLen * 2;
+				}
 			}
 			else if (translateOption == 0) // source charset and dest charset are the same - no translation
 			{
@@ -3036,7 +3042,12 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				}
 				memcpy(outDataPtr, DataPtr, DataLen);
 				if (Offset != 0)
-					*(unsigned short *)targetDataPtr = DataLen;
+				{
+					if (targetPrecision > 0x7fff)
+						*(unsigned int *)targetDataPtr = DataLen;
+					else
+						*(unsigned short *)targetDataPtr = DataLen;
+				}
 			}
 			else 
 			{
@@ -3064,7 +3075,13 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				}
 				DataLen = translateLength;
 				if (Offset != 0)
-					*(unsigned short *)targetDataPtr = DataLen;
+				{
+					if (targetPrecision > 0x7fff)
+						*(unsigned int *)targetDataPtr = DataLen;
+					else
+						*(unsigned short *)targetDataPtr = DataLen;
+				}
+
 			}
 
 			if (ODBCDataType == SQL_CHAR)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/win-odbc64/odbcclient/drvr35/ctosqlconv.h
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/ctosqlconv.h b/win-odbc64/odbcclient/drvr35/ctosqlconv.h
index 9c22f2f..458299f 100644
--- a/win-odbc64/odbcclient/drvr35/ctosqlconv.h
+++ b/win-odbc64/odbcclient/drvr35/ctosqlconv.h
@@ -44,7 +44,7 @@ unsigned long ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 							SQLSMALLINT	SQLDatetimeCode,
 							SQLPOINTER	targetDataPtr,
 							SQLINTEGER	targetLength,
-							SQLSMALLINT	targetPrecision,
+							SQLINTEGER	targetPrecision,
 							SQLSMALLINT	targetScale,
 							SQLSMALLINT targetUnsigned,
 							SQLINTEGER	targetCharSet,

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/c4a39d4d/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/sqltocconv.cpp b/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
index c584fab..69c8363 100644
--- a/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
+++ b/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
@@ -149,7 +149,6 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 							BOOL		ColumnwiseData,
 							CHAR		*replacementChar)
 {
-	
 	unsigned long retCode = SQL_SUCCESS;
 	SQLPOINTER		DataPtr;
 	SQLINTEGER		DataLen;
@@ -1043,7 +1042,7 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 					}
 					else
 					{
-					//remove spaces if any
+						//remove spaces if any
 						char* spaceStart = strchr((char*)srcDataPtr, ' ');
 						if (spaceStart != NULL)
 							srcLength = (spaceStart - (char*)srcDataPtr) + 1;
@@ -1055,36 +1054,78 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 						else
 							return IDS_22_003;
 					}
+
 					if (!ctoi64(cTmpBuf, tempVal64 ))
 						return IDS_22_003;
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					DataLen = *(USHORT *)srcDataPtr;
-					if (DataLen == 0)
-					return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+					if (isshort)
 					{
-						if(WCharToUTF8((wchar_t*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, error) != SQL_SUCCESS)
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-							return IDS_22_003;
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 1, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the length
-						srcLength = TransStringLength + 1;
+
+						if (!ctoi64(cTmpBuf, tempVal64))
+							return IDS_22_003;
 					}
 					else
 					{
-						memcpy(cTmpBuf, (char*)srcDataPtr, DataLen + 2);
-						cTmpBuf[DataLen + 2] = 0;
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 2, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr+4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
+						}
+
+						if (!ctoi64(cTmpBuf, tempVal64))
+							return IDS_22_003;
 					}
-					if (!ctoi64(cTmpBuf+2, tempVal64 ))
-						return IDS_22_003;
 				}
+				if ((retCode = ConvertSQLCharToNumeric(cTmpBuf, srcLength, ODBCDataType, dTmp)) != SQL_SUCCESS)
+					return retCode;
 			}
-			if ((retCode = ConvertSQLCharToNumeric(cTmpBuf, srcLength, ODBCDataType, dTmp)) != SQL_SUCCESS)
-				return retCode;
 			break;
 		case SQL_INTERVAL_MONTH:
 		case SQL_INTERVAL_YEAR:
@@ -1370,7 +1411,6 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 	case SQL_C_DATE:
 	case SQL_C_TYPE_DATE:
 		DataPtr = &dateTmp;
-		DataLen = sizeof(DATE_STRUCT);
 		switch (ODBCDataType)
 		{
 		case SQL_CHAR:
@@ -1399,7 +1439,7 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 					}
 					else
 					{
-					//remove spaces if any
+						//remove spaces if any
 						char* spaceStart = strchr((char*)srcDataPtr, ' ');
 						if (spaceStart != NULL)
 							srcLength = (spaceStart - (char*)srcDataPtr) + 1;
@@ -1414,25 +1454,59 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					DataLen = *(USHORT *)srcDataPtr;
-					if (DataLen == 0)
-						return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
-					{
-						if(WCharToUTF8((wchar_t*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, error) != SQL_SUCCESS)
+					if (isshort){
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-							return IDS_22_003;
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 1, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr + 2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the lengths
-						DataLen = sizeof(DATE_STRUCT); 
-						srcLength = TransStringLength + 1;
 					}
-					else
-					{
-						memcpy(cTmpBuf, (char*)srcDataPtr, DataLen + 2);
-						cTmpBuf[DataLen + 2] = 0;
+					else{
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 2, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr + 4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
+						}
 					}
 				}
 			}
@@ -1582,7 +1656,6 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 	case SQL_C_TIME:
 	case SQL_C_TYPE_TIME:
 		DataPtr = &timeTmp;
-		DataLen = sizeof(TIME_STRUCT);
 		switch (ODBCDataType)
 		{
 		case SQL_CHAR:
@@ -1626,24 +1699,61 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					SQLINTEGER tmpDataLen = *(USHORT *)srcDataPtr;
-					if (tmpDataLen == 0)
-					return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+					if (isshort)
 					{
-						if(WCharToUTF8((wchar_t*)srcDataPtr+1, tmpDataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, error) != SQL_SUCCESS)
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-							return IDS_22_003;
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 1, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr + 2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the length
-						srcLength = TransStringLength + 1;
 					}
 					else
 					{
-						memcpy(cTmpBuf, (char*)srcDataPtr , tmpDataLen + 2);
-						cTmpBuf[tmpDataLen + 2] = 0;
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 2, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr + 4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
+						}
 					}
 				}
 			}
@@ -1770,7 +1880,6 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 	case SQL_C_TIMESTAMP:
 	case SQL_C_TYPE_TIMESTAMP:
 		DataPtr = &timestampTmp;
-		DataLen = sizeof(TIMESTAMP_STRUCT);
 		switch (ODBCDataType)
 		{
 		case SQL_CHAR:
@@ -1808,28 +1917,62 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					DataLen = *(USHORT *)srcDataPtr;
-					if (DataLen == 0)
-					return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+					if (isshort)
 					{
-						if(WCharToUTF8((wchar_t*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, error) != SQL_SUCCESS)
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						// We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-						// But this should never happen!
-							return IDS_22_003;
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 1, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								// We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								// But this should never happen!
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr + 2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the length
-						srcLength = TransStringLength + 1;
 					}
 					else
 					{
-						memcpy(cTmpBuf, (char*)srcDataPtr, DataLen + 2);
-						cTmpBuf[DataLen + 2] = 0;
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 2, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								// We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								// But this should never happen!
+								return IDS_22_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr + 4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
+						}
 					}
-					//reset DataLen
-					DataLen = sizeof(TIMESTAMP_STRUCT);
 				}
 			}
 			if ((retCode = ConvertSQLCharToDate(ODBCDataType, cTmpBuf, srcLength, SQL_C_TIMESTAMP, 
@@ -2095,10 +2238,11 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		case SQL_VARCHAR:
 		case SQL_LONGVARCHAR:
 		case SQL_WVARCHAR:
-			if(isshort){
-				short_len=*(USHORT *)srcDataPtr;
-				charlength=short_len;
-				if (short_len == 0){	
+		{
+			if (isshort){
+				short_len = *(USHORT *)srcDataPtr;
+				charlength = short_len;
+				if (short_len == 0){
 					if (targetStrLenPtr != NULL)
 						*targetStrLenPtr = 0;
 					((char*)targetDataPtr)[0] = '\0';
@@ -2107,9 +2251,9 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				DataLen = short_len - Offset;
 			}
 			else{
-				int_len=*(int *)srcDataPtr;
-				charlength=int_len;
-				if(int_len == 0){
+				int_len = *(int *)srcDataPtr;
+				charlength = int_len;
+				if (int_len == 0){
 					if (targetStrLenPtr != NULL)
 						*targetStrLenPtr = 0;
 					((char*)targetDataPtr)[0] = '\0';
@@ -2123,18 +2267,20 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 			if (DataLen > targetLength)
 			{
 				retCode = IDS_01_004;
-				if(isshort)
+				if (isshort)
 					DataLenTruncated = short_len - Offset;
 				else
 					DataLenTruncated = int_len - Offset;
-				DataLen = targetLength-1;
+				DataLen = targetLength - 1;
 			}
-			if(isshort)
+			if (isshort)
 				DataPtr = (char *)srcDataPtr + 2 + Offset;
 			else
 				DataPtr = (char *)srcDataPtr + 4 + Offset;
-//			if (totalReturnedLength != NULL)
-//				*totalReturnedLength = DataLen + Offset;
+
+			//			if (totalReturnedLength != NULL)
+			//				*totalReturnedLength = DataLen + Offset;
+		}
 			break;
 		case SQL_INTERVAL_MONTH:
 		case SQL_INTERVAL_YEAR:
@@ -2185,6 +2331,7 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		default:
 			return IDS_07_006;
 		}
+		NullTerminate = TRUE;
 		break; // End of switch for SQL_C_BINARY 
 	case SQL_C_DEFAULT:
 		switch (ODBCDataType)
@@ -2608,28 +2755,55 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		case SQL_VARCHAR:
 		case SQL_LONGVARCHAR:
 		case SQL_WVARCHAR:
-			DataLen = *(USHORT *)srcDataPtr;
-			if (DataLen == 0)
-				return SQL_NO_DATA;
-			DataPtr = (char *)srcDataPtr + sizeof(USHORT);
-			if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+			if (isshort)
 			{
-				int TransStringLength = 0;
-				if(WCharToUTF8((wchar_t*)DataPtr, DataLen/2, (char*)cTmpBuf,
-					sizeof(cTmpBuf) , &TransStringLength, error) != SQL_SUCCESS)
+				DataLen = *(USHORT *)srcDataPtr;
+				if (DataLen == 0)
+					return SQL_NO_DATA;
+				DataPtr = (char *)srcDataPtr + sizeof(USHORT);
+				if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 				{
-				//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-				//Add more trace
-					return IDS_07_003;
+					int TransStringLength = 0;
+					if (WCharToUTF8((wchar_t*)DataPtr, DataLen / 2, (char*)cTmpBuf,
+						sizeof(cTmpBuf), &TransStringLength, error) != SQL_SUCCESS)
+					{
+						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+						//Add more trace
+						return IDS_07_003;
+					}
+				}
+				else
+				{
+					if (sizeof(cTmpBuf) < DataLen+1)
+						return IDS_07_003;
+					memcpy(cTmpBuf, DataPtr, DataLen);
+					cTmpBuf[DataLen] = 0;
 				}
-				srcLength = TransStringLength + 1;
 			}
 			else
 			{
-				if (sizeof(cTmpBuf) < DataLen )
-					return IDS_07_003;
-				memcpy(cTmpBuf, (char*)srcDataPtr + 2 , DataLen);
-				cTmpBuf[DataLen] = 0;
+				DataLen = *(UINT *)srcDataPtr;
+				if (DataLen == 0)
+					return SQL_NO_DATA;
+				DataPtr = (char *)srcDataPtr + sizeof(UINT);
+				if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+				{
+					int TransStringLength = 0;
+					if (WCharToUTF8((wchar_t*)DataPtr, DataLen / 2, (char*)cTmpBuf,
+						sizeof(cTmpBuf), &TransStringLength, error) != SQL_SUCCESS)
+					{
+						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+						//Add more trace
+						return IDS_07_003;
+					}
+				}
+				else
+				{
+					if (sizeof(cTmpBuf) < DataLen+1)
+						return IDS_07_003;
+					memcpy(cTmpBuf, DataPtr, DataLen);
+					cTmpBuf[DataLen] = 0;
+				}
 			}
 			useDouble = FALSE;
 			break;
@@ -2823,7 +2997,6 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 			strncpy(stopStr, tempPtr, strlen(tempPtr) - srcScale);
 			strcat(stopStr,".");
 			strcat(stopStr, tempPtr + strlen(tempPtr) - srcScale);
-
 		}
 
 		if ((retCode = ConvertCharToCNumeric( numericTmp, cTmpBuf)) != SQL_SUCCESS)
@@ -2884,28 +3057,63 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				}
 				else //SQL_LONG_VARCHAR
 				{
-					DataLen = *(USHORT *)srcDataPtr;
-					if (DataLen == 0)
-					return SQL_NO_DATA;
-					if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+					if (isshort)
 					{
-						if (sizeof (cTmpBuf) <= DataLen/2) //Avoid a seg-violation
-							return IDS_07_003;
-						if(WCharToUTF8((wchar_t*)srcDataPtr+1, DataLen/2, (char*)cTmpBuf+2,
-							(sizeof(cTmpBuf) - 2) , &TransStringLength, error) != SQL_SUCCESS)
+						DataLen = *(USHORT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
 						{
-						//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
-							return IDS_07_003;
+							if (sizeof(cTmpBuf) <= DataLen / 2) //Avoid a seg-violation
+								return IDS_07_003;
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 1, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_07_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr + 2, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
 						}
-						*(short *)cTmpBuf = TransStringLength; //reset the length
-						srcLength = TransStringLength + 1;
 					}
 					else
 					{
-						if (sizeof (cTmpBuf) <= DataLen + 2)
-							return IDS_07_003;
-						memcpy(cTmpBuf, (char*)srcDataPtr, DataLen + 2);
-						cTmpBuf[DataLen + 2] = 0;
+						DataLen = *(UINT *)srcDataPtr;
+						if (DataLen == 0)
+							return SQL_NO_DATA;
+						if (srcCharSet == SQLCHARSETCODE_UCS2) //convert from UTF-16 to UTF-8
+						{
+							if (sizeof(cTmpBuf) <= DataLen / 2) //Avoid a seg-violation
+								return IDS_07_003;
+							if (WCharToUTF8((wchar_t*)srcDataPtr + 2, DataLen / 2, (char*)cTmpBuf,
+								(sizeof(cTmpBuf)), &TransStringLength, error) != SQL_SUCCESS)
+							{
+								//We don't want to see a data truncation (SQL_SUCCESS_WITH_INFO) here
+								return IDS_07_003;
+							}
+							srcLength = TransStringLength + 1;
+						}
+						else
+						{
+							if ((DataLen + 1) <= sizeof(cTmpBuf))
+							{
+								memcpy(cTmpBuf, (char*)srcDataPtr + 4, DataLen);
+								srcLength = DataLen + 1;
+								cTmpBuf[DataLen] = 0;
+							}
+							else
+								return IDS_22_003;
+						}
 					}
 				}
 				if ((retCode = ConvertSQLCharToInterval(ODBCDataType, cTmpBuf, srcLength, CDataType, 
@@ -3073,6 +3281,7 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 			}											
 		}
 	}
+
 	if (targetDataPtr != NULL && ((DataPtr != NULL && DataLen > 0) || translatedDataPtr != NULL) && gDrvrGlobal.fpSQLDataSourceToDriver)
 	{
 		if(pdwGlobalTraceVariable && *pdwGlobalTraceVariable)
@@ -3591,10 +3800,12 @@ unsigned long ODBC::ConvertSQLCharToNumeric(SQLPOINTER srcDataPtr, SQLINTEGER sr
 	char	*str;
 	char    *errorCharPtr;
 
-	
 	switch (ODBCDataType) {
 	case SQL_CHAR:
 	case SQL_WCHAR:
+	case SQL_VARCHAR:
+	case SQL_LONGVARCHAR:
+	case SQL_WVARCHAR:
 		str = (char *)srcDataPtr;
 		tempLen = srcLength-1;
 		if (str[ tempLen - 1 ] == ' ')
@@ -3604,12 +3815,6 @@ unsigned long ODBC::ConvertSQLCharToNumeric(SQLPOINTER srcDataPtr, SQLINTEGER sr
 			tempLen = strlen(str);
 		}
 		break;
-	case SQL_VARCHAR:
-	case SQL_LONGVARCHAR:
-	case SQL_WVARCHAR:
-		tempLen = *(USHORT *)srcDataPtr;
-		str = (char *)srcDataPtr+sizeof(USHORT);
-		break;
 	case SQL_INTERVAL_MONTH:
 	case SQL_INTERVAL_YEAR:
 	case SQL_INTERVAL_YEAR_TO_MONTH:
@@ -3658,6 +3863,9 @@ unsigned long ODBC::ConvertSQLCharToDate(SQLSMALLINT ODBCDataType,
 	{
 	case SQL_CHAR:
 	case SQL_WCHAR:
+	case SQL_VARCHAR:
+	case SQL_LONGVARCHAR:
+	case SQL_WVARCHAR:
 		len = srcLength-1;
 		strPtr = (char *)srcDataPtr;
 		if (strPtr[ len - 1 ] == ' ')
@@ -3667,12 +3875,6 @@ unsigned long ODBC::ConvertSQLCharToDate(SQLSMALLINT ODBCDataType,
 			len = strlen(strPtr);
 		}
 		break;
-	case SQL_VARCHAR:
-	case SQL_LONGVARCHAR:
-	case SQL_WVARCHAR:
-		len = *(USHORT *)srcDataPtr;
-		strPtr = (char *)srcDataPtr + sizeof(USHORT);
-		break;
 	default:
 		return IDS_07_006;
 	}
@@ -3863,6 +4065,9 @@ unsigned long ODBC::ConvertSQLCharToInterval(SQLSMALLINT ODBCDataType,
 	{
 	case SQL_CHAR:
 	case SQL_WCHAR:
+	case SQL_VARCHAR:
+	case SQL_LONGVARCHAR:
+	case SQL_WVARCHAR:
 		len = srcLength-1;
 		strPtr = (char *)srcDataPtr;
 		if (strPtr[ len - 1 ] == ' ')
@@ -3872,12 +4077,6 @@ unsigned long ODBC::ConvertSQLCharToInterval(SQLSMALLINT ODBCDataType,
 			len = strlen(strPtr);
 		}
 		break;
-	case SQL_VARCHAR:
-	case SQL_LONGVARCHAR:
-	case SQL_WVARCHAR:
-		len = *(USHORT *)srcDataPtr;
-		strPtr = (char *)srcDataPtr + sizeof(USHORT);
-		break;
 	case SQL_INTERVAL_MONTH:
 	case SQL_INTERVAL_YEAR:
 	case SQL_INTERVAL_YEAR_TO_MONTH:


[2/3] incubator-trafodion git commit: [TRAFODION-1262]ODBC:Varchar col operation fails use macro instead of 0x7fff and fix trancation of charset conv in unixodbc

Posted by ry...@apache.org.
[TRAFODION-1262]ODBC:Varchar col operation fails
use macro instead of 0x7fff and fix trancation of charset conv in unixodbc


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/e0cf313f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/e0cf313f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/e0cf313f

Branch: refs/heads/master
Commit: e0cf313fe755538860d2cad4a204e1f182654014
Parents: c4a39d4
Author: rwbzx <xi...@esgyn.cn>
Authored: Fri Dec 2 18:18:03 2016 +0800
Committer: rwbzx <xi...@esgyn.cn>
Committed: Fri Dec 2 18:18:03 2016 +0800

----------------------------------------------------------------------
 core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp  |  4 ++--
 .../unixodbc/odbc/odbcclient/unixcli/cli/charsetconv.cpp  |  4 ++--
 .../unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp   | 10 +++++-----
 win-odbc64/odbcclient/drvr35/cdesc.cpp                    |  4 ++--
 win-odbc64/odbcclient/drvr35/ctosqlconv.cpp               | 10 +++++-----
 win-odbc64/odbcclient/drvr35/sqltocconv.cpp               |  3 +++
 6 files changed, 19 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e0cf313f/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp
----------------------------------------------------------------------
diff --git a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp
index b844519..96ad330 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/cdesc.cpp
@@ -598,14 +598,14 @@ unsigned long CDescRec::setDescRec(short DescMode, SQLItemDesc_def *SQLItemDesc)
 	case SQLTYPECODE_VARCHAR_WITH_LENGTH:
 		if (m_SQLCharset == SQLCHARSETCODE_UCS2)
 		{
-			if(SQLItemDesc->maxLen > 0x7fff)
+			if(SQLItemDesc->maxLen > SHRT_MAX)
 				m_SQLOctetLength = SQLItemDesc->maxLen+6;
 			else
 				m_SQLOctetLength = SQLItemDesc->maxLen+4;
 		}
 		else
 		{
-			if(SQLItemDesc->maxLen > 0x7fff)
+			if(SQLItemDesc->maxLen > SHRT_MAX)
 				m_SQLOctetLength = SQLItemDesc->maxLen+5;
 			else
 				m_SQLOctetLength = SQLItemDesc->maxLen+3;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e0cf313f/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/charsetconv.cpp
----------------------------------------------------------------------
diff --git a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/charsetconv.cpp b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/charsetconv.cpp
index 05a7a37..2f96082 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/charsetconv.cpp
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/charsetconv.cpp
@@ -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';
@@ -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';

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e0cf313f/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
----------------------------------------------------------------------
diff --git a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
index 5663f09..cd1ddef 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
@@ -362,7 +362,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 	case SQL_LONGVARCHAR:
 	case SQL_WVARCHAR:
 		{
-			if(targetPrecision > 0x7fff)
+			if(targetPrecision > SHRT_MAX)
 			{
 				Offset = sizeof(UINT);
 			}
@@ -655,7 +655,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 		if (Offset != 0)
 		{
 //#ifndef MXSUN
-			if(targetPrecision > 0x7fff){
+			if(targetPrecision > SHRT_MAX){
 				outDataPtr = (unsigned char *)targetDataPtr + sizeof(int);
 			}
 			else{
@@ -3218,7 +3218,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				}
 				if (Offset != 0)
 				{
-					if(targetPrecision > 0x7fff)
+					if(targetPrecision > SHRT_MAX)
 						*(unsigned int *)targetDataPtr = DataLen;
 					else
 						*(unsigned short *)targetDataPtr = DataLen;
@@ -3269,7 +3269,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				}
 				if (Offset != 0)
 				{
-					if(targetPrecision > 0x7fff)
+					if(targetPrecision > SHRT_MAX)
 					{
 						if(iconv->getUCS2Translation())
 							*(unsigned int *)targetDataPtr = DataLen*2;
@@ -3330,7 +3330,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				}
 				if (Offset != 0)
 				{
-					if(targetPrecision > 0x7fff)
+					if(targetPrecision > SHRT_MAX)
 						*(unsigned int *)targetDataPtr = DataLen;
 					else
 						*(unsigned short *)targetDataPtr = DataLen;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e0cf313f/win-odbc64/odbcclient/drvr35/cdesc.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/cdesc.cpp b/win-odbc64/odbcclient/drvr35/cdesc.cpp
index 461c13c..f1e01ea 100644
--- a/win-odbc64/odbcclient/drvr35/cdesc.cpp
+++ b/win-odbc64/odbcclient/drvr35/cdesc.cpp
@@ -559,7 +559,7 @@ unsigned long CDescRec::setDescRec(short DescMode, SQLItemDesc_def *SQLItemDesc)
 	case SQLTYPECODE_VARCHAR_WITH_LENGTH:
 		if (m_SQLCharset == SQLCHARSETCODE_UCS2)
 		{
-			if (SQLItemDesc->maxLen > 0x7fff)
+			if (SQLItemDesc->maxLen > SHRT_MAX)
 			{
 				m_SQLOctetLength = SQLItemDesc->maxLen + 6;  //4 bytes for len and 2 bytes of null
 			}
@@ -570,7 +570,7 @@ unsigned long CDescRec::setDescRec(short DescMode, SQLItemDesc_def *SQLItemDesc)
 		}
 		else
 		{ 
-			if (SQLItemDesc->maxLen > 0x7fff)
+			if (SQLItemDesc->maxLen > SHRT_MAX)
 			{
 				m_SQLOctetLength = SQLItemDesc->maxLen + 5;  //4 bytes for len and 1 byte of null
 			}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e0cf313f/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp b/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
index f9be84c..fb2a312 100644
--- a/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
+++ b/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
@@ -284,7 +284,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 	case SQL_VARCHAR:
 	case SQL_LONGVARCHAR:
 	case SQL_WVARCHAR:
-		if (targetPrecision > 0x7fff){
+		if (targetPrecision > SHRT_MAX){
 			Offset = sizeof(UINT);
 		}
 		else{
@@ -566,7 +566,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 		}
 		if (Offset != 0)
 		{
-			if (targetPrecision > 0x7fff)
+			if (targetPrecision > SHRT_MAX)
 				outDataPtr = (unsigned char *)targetDataPtr + sizeof(UINT);
 			else
 				outDataPtr = (unsigned char *)targetDataPtr + sizeof(USHORT);
@@ -3026,7 +3026,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				}
 				if (Offset != 0)
 				{
-					if (targetPrecision > 0x7fff)
+					if (targetPrecision > SHRT_MAX)
 						*(unsigned int *)targetDataPtr = DataLen * 2;
 					else
 						*(unsigned short *)targetDataPtr = DataLen * 2;
@@ -3043,7 +3043,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				memcpy(outDataPtr, DataPtr, DataLen);
 				if (Offset != 0)
 				{
-					if (targetPrecision > 0x7fff)
+					if (targetPrecision > SHRT_MAX)
 						*(unsigned int *)targetDataPtr = DataLen;
 					else
 						*(unsigned short *)targetDataPtr = DataLen;
@@ -3076,7 +3076,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				DataLen = translateLength;
 				if (Offset != 0)
 				{
-					if (targetPrecision > 0x7fff)
+					if (targetPrecision > SHRT_MAX)
 						*(unsigned int *)targetDataPtr = DataLen;
 					else
 						*(unsigned short *)targetDataPtr = DataLen;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e0cf313f/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/sqltocconv.cpp b/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
index 69c8363..ab56ccf 100644
--- a/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
+++ b/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
@@ -1411,6 +1411,7 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 	case SQL_C_DATE:
 	case SQL_C_TYPE_DATE:
 		DataPtr = &dateTmp;
+		DataLen = sizeof(DATE_STRUCT);
 		switch (ODBCDataType)
 		{
 		case SQL_CHAR:
@@ -1656,6 +1657,7 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 	case SQL_C_TIME:
 	case SQL_C_TYPE_TIME:
 		DataPtr = &timeTmp;
+		DataLen = sizeof(TIME_STRUCT);
 		switch (ODBCDataType)
 		{
 		case SQL_CHAR:
@@ -1880,6 +1882,7 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 	case SQL_C_TIMESTAMP:
 	case SQL_C_TYPE_TIMESTAMP:
 		DataPtr = &timestampTmp;
+		DataLen = sizeof(TIMESTAMP_STRUCT);
 		switch (ODBCDataType)
 		{
 		case SQL_CHAR:


[3/3] incubator-trafodion git commit: Merge [TRAFODION-1262] PR-853 ODBC:Varchar col operation fails

Posted by ry...@apache.org.
Merge [TRAFODION-1262] PR-853 ODBC:Varchar col operation fails


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/d6a5b79b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/d6a5b79b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/d6a5b79b

Branch: refs/heads/master
Commit: d6a5b79b083eb57996ad3276cb9adce64316ce30
Parents: 4d33839 e0cf313
Author: ryzuo <jo...@gmail.com>
Authored: Mon Dec 19 01:54:01 2016 +0000
Committer: ryzuo <jo...@gmail.com>
Committed: Mon Dec 19 01:54:01 2016 +0000

----------------------------------------------------------------------
 .../odbc/odbcclient/unixcli/cli/cdesc.cpp       |  17 +-
 .../odbc/odbcclient/unixcli/cli/cdesc.h         |   6 +-
 .../odbc/odbcclient/unixcli/cli/charsetconv.cpp |   4 +-
 .../odbc/odbcclient/unixcli/cli/ctosqlconv.cpp  |  49 +-
 .../odbc/odbcclient/unixcli/cli/ctosqlconv.h    |   2 +-
 .../odbc/odbcclient/unixcli/cli/sqltocconv.cpp  | 403 +++++++++++-----
 win-odbc64/odbcclient/drvr35/cdesc.cpp          |  25 +-
 win-odbc64/odbcclient/drvr35/cdesc.h            |   6 +-
 win-odbc64/odbcclient/drvr35/ctosqlconv.cpp     |  43 +-
 win-odbc64/odbcclient/drvr35/ctosqlconv.h       |   2 +-
 win-odbc64/odbcclient/drvr35/sqltocconv.cpp     | 454 ++++++++++++++-----
 11 files changed, 742 insertions(+), 269 deletions(-)
----------------------------------------------------------------------