trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lium...@apache.org
Subject [2/5] incubator-trafodion git commit: [TRAFODION-2385] windows odbc support tinyint, boolean, largeint unsigned
Date Thu, 22 Jun 2017 12:25:55 GMT
[TRAFODION-2385] windows odbc support tinyint,boolean,largeint unsigned


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

Branch: refs/heads/master
Commit: fe53516b5c50c848589fb12dc5fa80cb01e7f009
Parents: 8bb7d25
Author: Weixin-Xu <weixin.xu@esgyn.cn>
Authored: Mon Jun 5 13:40:38 2017 +0800
Committer: Weixin-Xu <weixin.xu@esgyn.cn>
Committed: Mon Jun 5 13:40:38 2017 +0800

----------------------------------------------------------------------
 win-odbc64/odbcclient/drvr35/cdesc.cpp      |   3 +-
 win-odbc64/odbcclient/drvr35/cstmt.cpp      |   1 +
 win-odbc64/odbcclient/drvr35/ctosqlconv.cpp | 106 ++++++++++++++++++-
 win-odbc64/odbcclient/drvr35/sqltocconv.cpp | 127 ++++++++++++++++++++++-
 win-odbc64/sql/cli/sqlcli.h                 |  10 ++
 5 files changed, 243 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe53516b/win-odbc64/odbcclient/drvr35/cdesc.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/cdesc.cpp b/win-odbc64/odbcclient/drvr35/cdesc.cpp
index f1e01ea..a8b2d94 100644
--- a/win-odbc64/odbcclient/drvr35/cdesc.cpp
+++ b/win-odbc64/odbcclient/drvr35/cdesc.cpp
@@ -2277,7 +2277,8 @@ SQLRETURN CDesc::BuildValueList(CStmt *pHandle,  //AMR - changed this
pointer ty
 
 				if(IPDDescRecPtr->m_ODBCDataType == SQL_VARCHAR ||
 				   IPDDescRecPtr->m_ODBCDataType == SQL_LONGVARCHAR ||
-				   IPDDescRecPtr->m_ODBCDataType == SQL_CHAR)
+				   IPDDescRecPtr->m_ODBCDataType == SQL_CHAR &&
+				   IPDDescRecPtr->m_SQLDataType != SQLTYPECODE_BOOLEAN)
 					SQLValue->dataValue._length = IPDDescRecPtr->m_SQLOctetLength-1;
 				else if (IPDDescRecPtr->m_ODBCDataType == SQL_WVARCHAR ||
 						 IPDDescRecPtr->m_ODBCDataType == SQL_WCHAR) 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe53516b/win-odbc64/odbcclient/drvr35/cstmt.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/cstmt.cpp b/win-odbc64/odbcclient/drvr35/cstmt.cpp
index d1ab20d..3dce053 100644
--- a/win-odbc64/odbcclient/drvr35/cstmt.cpp
+++ b/win-odbc64/odbcclient/drvr35/cstmt.cpp
@@ -3535,6 +3535,7 @@ BOOL CStmt::setFetchOutputPerf(SQL_DataValue_def*& outputDataValue,
long rowsFet
                 memOffSet += SQLMaxLength ;
                 break;
             case SQLTYPECODE_LARGEINT:
+			case SQLTYPECODE_LARGEINT_UNSIGNED:
                 memOffSet = ((memOffSet + 8 - 1) >> 3) << 3;
                 VarOffSet = memOffSet;
                 memOffSet += SQLMaxLength ;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe53516b/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp b/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
index fb2a312..5b0037a 100644
--- a/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
+++ b/win-odbc64/odbcclient/drvr35/ctosqlconv.cpp
@@ -130,6 +130,8 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 	USHORT		usTmp;
 	SLONG		lTmp;
 	ULONG		ulTmp;
+	SCHAR		tTmp;
+	UCHAR		utTmp;
 	CHAR		cTmpBuf[256];
 	CHAR		cTmpBuf2[256];
 	CHAR		cTmpFraction[10];
@@ -246,6 +248,12 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 		targetUnsigned = true;
 	}
 
+	if (SQLDataType == SQLTYPECODE_BOOLEAN)
+	{
+		ODBCDataType = SQL_BOOLEAN;
+	}
+
+
 	if (CDataType == SQL_C_DEFAULT)
 	{
 		getCDefault(tODBCDataType, ODBCAppVersion, CDataType);
@@ -589,6 +597,8 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 			DataLen = sizeof(fltTmp);
 			break;
 		}
+	case SQL_BOOLEAN:
+	case SQL_TINYINT:
 	case SQL_SMALLINT:
 	case SQL_INTEGER:
 	case SQL_FLOAT:
@@ -814,6 +824,50 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 
 				switch (ODBCDataType)
 				{
+				case SQL_BOOLEAN:
+					if (dTmp < 0)
+						return IDS_22_003_02;  //negValue in unsigned column
+					if (dTmp > 1)
+						return IDS_22_003;
+					tTmp = (SCHAR)dTmp;
+					if (dTmp != tTmp)
+						retCode = IDS_01_S07;
+					DataPtr = &tTmp;
+					DataLen = sizeof(SCHAR);
+					break;
+				case SQL_TINYINT:
+					if (targetUnsigned)
+					{
+						if (dTmp < 0)
+							return IDS_22_003_02;  //negValue in unsigned column
+						if (dTmp > UCHAR_MAX)
+							return IDS_22_003;
+						utTmp = (UCHAR)dTmp;
+						if (dTmp != utTmp)
+							retCode = IDS_01_S07;
+						DataPtr = &utTmp;
+						DataLen = sizeof(UCHAR);
+					}
+					else
+					{
+						if (unsignedInteger)
+						{
+							if (dTmp < 0 || dTmp > UCHAR_MAX)
+								return IDS_22_003;
+							tTmp = (SCHAR)dTmp;
+						}
+						else
+						{
+							if (dTmp < SCHAR_MIN || dTmp > SCHAR_MAX)
+								return IDS_22_003;
+							tTmp = (SCHAR)dTmp;
+							if (dTmp != tTmp)
+								retCode = IDS_01_S07;
+						}
+						DataPtr = &tTmp;
+						DataLen = sizeof(SCHAR);
+					}
+					break;
 				case SQL_SMALLINT:
 					if (targetUnsigned)
 					{
@@ -972,9 +1026,38 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 
 				switch( SQLDataType )
 				{
+				case SQLTYPECODE_BOOLEAN:
+					if (tempVal64 < 0 || tempVal64 > 1)
+						return IDS_22_003_02;
+					tTmp = (SCHAR)tempVal64;
+					if (tempVal64 != tTmp)
+						retCode = IDS_01_S07;
+					DataPtr = &tTmp;
+					DataLen = sizeof(SCHAR);
+					break;
+				case SQLTYPECODE_TINYINT_UNSIGNED:
+					if (tempVal64 < 0)
+						return IDS_22_003_02;
+					if (tempVal64 > UCHAR_MAX)
+						return IDS_22_003;
+					utTmp = (UCHAR)tempVal64;
+					if (tempVal64 != utTmp)
+						retCode = IDS_01_S07;
+					DataPtr = &utTmp;
+					DataLen = sizeof(UCHAR);
+					break;
+				case SQLTYPECODE_TINYINT:
+					if (tempVal64 < SCHAR_MIN || tempVal64 > SCHAR_MAX)
+						return IDS_22_003_02;
+					tTmp = (SCHAR)tempVal64;
+					if (tempVal64 != tTmp)
+						retCode = IDS_01_S07;
+					DataPtr = &tTmp;
+					DataLen = sizeof(SCHAR);
+					break;
 				case SQLTYPECODE_SMALLINT_UNSIGNED:
 					if (tempVal64 < 0)
-					       return IDS_22_003_02;
+						return IDS_22_003_02;
 					if ((USHORT)tempVal64 > USHRT_MAX)
 						return IDS_22_003;
 					usTmp = (USHORT)tempVal64;
@@ -1059,6 +1142,12 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 		{
 			switch (ODBCDataType)
 			{
+			case SQL_BOOLEAN:
+				DataLen = sizeof(SCHAR);
+				break;
+			case SQL_TINYINT:
+				DataLen = sizeof(SCHAR);
+				break;
 			case SQL_SMALLINT:
 				DataLen = sizeof(SHORT);
 				break;
@@ -1507,6 +1596,21 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				dTmp *= scaleOffset;
 				switch (SQLDataType)
 				{
+				case SQLTYPECODE_BOOLEAN:
+					tTmp = (SCHAR)dTmp;
+					DataPtr = &tTmp;
+					DataLen = sizeof(SCHAR);
+					break;
+				case SQLTYPECODE_TINYINT_UNSIGNED:
+					utTmp = (UCHAR)dTmp;
+					DataPtr = &utTmp;
+					DataLen = sizeof(UCHAR);
+					break;
+				case SQLTYPECODE_TINYINT:
+					tTmp = (SCHAR)dTmp;
+					DataPtr = &tTmp;
+					DataLen = sizeof(SCHAR);
+					break;
 				case SQLTYPECODE_SMALLINT_UNSIGNED:
 					usTmp = (USHORT)dTmp;
 					DataPtr = &usTmp;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe53516b/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
----------------------------------------------------------------------
diff --git a/win-odbc64/odbcclient/drvr35/sqltocconv.cpp b/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
index c1c1484..486cc63 100644
--- a/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
+++ b/win-odbc64/odbcclient/drvr35/sqltocconv.cpp
@@ -304,6 +304,18 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		srcUnsigned = true;
 	}
 
+	if (ODBCDataType == SQL_BIGINT && SQLDataType == SQLTYPECODE_LARGEINT_UNSIGNED &&
+				srcPrecision == 19 && srcScale == 0)
+	{
+		srcUnsigned = true;
+	}
+
+	if (SQLDataType == SQLTYPECODE_BOOLEAN)
+	{
+		ODBCDataType = SQL_BOOLEAN;
+	}
+
+
 	if (CDataType == SQL_C_DEFAULT)
 	{
 		getCDefault(tODBCDataType, ODBCAppVersion, CDataType);
@@ -475,6 +487,31 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 //			if (totalReturnedLength != NULL)
 //				*totalReturnedLength = DataLen + Offset;
 			break;
+		case SQL_BOOLEAN:
+			tTmp = *((SCHAR *) srcDataPtr);
+			_ltoa(tTmp, cTmpBuf, 10);
+			DataLen = strlen(cTmpBuf);
+			if (DataLen > targetLength)
+				return IDS_22_003;
+			DataPtr = cTmpBuf;
+			break;
+		case SQL_TINYINT:
+			if (srcUnsigned)
+			{
+				utTmp = *((UCHAR *) srcDataPtr);
+				_ultoa(utTmp, cTmpBuf, 10);
+			}
+			else
+			{
+				tTmp = *((SCHAR *) srcDataPtr);
+				_ltoa(tTmp, cTmpBuf, 10);
+			}
+			DataLen = strlen(cTmpBuf);
+			if (DataLen > targetLength)
+				return IDS_22_003;
+			DataPtr = cTmpBuf;
+			LocalizeNumericString = TRUE;
+			break;
 		case SQL_SMALLINT:
 			if (srcUnsigned)
 				lTmp = *((USHORT *) srcDataPtr);
@@ -505,7 +542,10 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 			LocalizeNumericString = TRUE;
 			break;
 		case SQL_BIGINT:
-			sprintf( cTmpBuf, "%I64d", *((__int64 *)srcDataPtr));
+			if (srcUnsigned)
+				_snprintf(cTmpBuf, sizeof(__int64), "%I64u", *((__int64 *)srcDataPtr));
+			else
+				_snprintf(cTmpBuf, sizeof(__int64), "%I64d", *((__int64 *)srcDataPtr));
 			DataLen = strlen(cTmpBuf);
 			if (DataLen > targetLength)
 				return IDS_22_003;
@@ -800,6 +840,31 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 //			if (totalReturnedLength != NULL)
 //				*totalReturnedLength = DataLen + Offset;
 			break;
+		case SQL_BOOLEAN:
+			tTmp = *((SCHAR *) srcDataPtr);
+			_ltoa(tTmp, cTmpBuf, 10);
+			DataLen = strlen(cTmpBuf);
+			if (DataLen > targetLength)
+				return IDS_22_003;
+			DataPtr = cTmpBuf;
+			break;
+		case SQL_TINYINT:
+			if (srcUnsigned)
+			{
+				utTmp = *((UCHAR *) srcDataPtr);
+				_ultoa(utTmp, cTmpBuf, 10);
+			}
+			else
+			{
+				tTmp = *((SCHAR *) srcDataPtr);
+				_ltoa(tTmp, cTmpBuf, 10);
+			}
+			DataLen = strlen(cTmpBuf);
+			if (DataLen > targetLength)
+				return IDS_22_003;
+			DataPtr = cTmpBuf;
+			LocalizeNumericString = TRUE;
+			break;
 		case SQL_SMALLINT:
 			if (srcUnsigned)
 				lTmp = *((USHORT *) srcDataPtr);
@@ -1143,6 +1208,21 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 			if ((retCode = ConvertSQLCharToNumeric(srcDataPtr, srcLength, ODBCDataType, dTmp)) !=
SQL_SUCCESS)
 				return retCode;
 			break;
+		case SQL_BOOLEAN:
+			dTmp = *((SCHAR *) srcDataPtr);
+			break;
+		case SQL_TINYINT:
+			if (srcUnsigned)
+			{
+				dTmp = *((UCHAR *) srcDataPtr);
+				unsignedInteger = TRUE;
+			}
+			else
+			{
+				dTmp = *((SCHAR *) srcDataPtr);
+				signedInteger = TRUE;
+			}
+			break;
 		case SQL_SMALLINT:
 			if (srcUnsigned)
 			{
@@ -1186,7 +1266,10 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 			if (tempVal64 < -DBL_MAX || tempVal64 > DBL_MAX)
 				return IDS_22_003;
 			dTmp = tempVal64;
-			signedInteger = TRUE;
+			if (srcUnsigned)
+				unsignedInteger = TRUE;
+			else
+				signedInteger = TRUE;
 			break;
 		case SQL_NUMERIC:
 			switch (SQLDataType)
@@ -2318,6 +2401,8 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 //			if (totalReturnedLength != NULL)
 //				*totalReturnedLength = DataLen + Offset;
 			break;
+		case SQL_BOOLEAN:
+		case SQL_TINYINT:
 		case SQL_SMALLINT:
 		case SQL_INTEGER:
 		case SQL_BIGINT:
@@ -2435,6 +2520,25 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 			DataPtr = &intervalTmp;
 			DataLen = sizeof(SQL_INTERVAL_STRUCT);
 			break;
+		case SQL_BOOLEAN:
+			tTmp = *((SCHAR *) srcDataPtr);
+			DataPtr = &tTmp;
+			DataLen = sizeof(SCHAR);
+			break;
+		case SQL_TINYINT:
+			if (srcUnsigned)
+			{
+				utTmp = *((UCHAR *) srcDataPtr);
+				DataPtr = &utTmp;
+				DataLen = sizeof(UCHAR);
+			}
+			else
+			{
+				tTmp = *(SCHAR *) srcDataPtr;
+				DataPtr = &tTmp;
+				DataLen = sizeof(SCHAR);
+			}
+			break;
 		case SQL_SMALLINT:
 			if (srcUnsigned)
 			{
@@ -2836,6 +2940,19 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 			strncpy( cTmpBuf, tempPtr, DataLen );
 			useDouble = FALSE;
 			break;
+		case SQL_TINYINT:
+			if (srcUnsigned)
+			{
+				utTmp = *(UCHAR *)srcDataPtr;
+				_ultoa(utTmp, cTmpBuf, 10);
+			}
+			else
+			{
+				lTmp = *(SCHAR *)srcDataPtr;
+				_ltoa(tTmp, cTmpBuf, 10);
+			}
+			useDouble = FALSE;
+			break;
 		case SQL_SMALLINT:
 			if (srcUnsigned)
 			{
@@ -3149,6 +3266,12 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				if (retCode != IDS_01_S07)
 					return retCode;
 			break;
+		case SQL_TINYINT:
+			if (srcUnsigned)
+				dTmp = *(UCHAR *)srcDataPtr;
+			else
+				dTmp = *(SCHAR *)srcDataPtr;
+			break;
 		case SQL_SMALLINT:
 			if (srcUnsigned)
 				dTmp = *(USHORT *)srcDataPtr;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe53516b/win-odbc64/sql/cli/sqlcli.h
----------------------------------------------------------------------
diff --git a/win-odbc64/sql/cli/sqlcli.h b/win-odbc64/sql/cli/sqlcli.h
index e076735..982f609 100644
--- a/win-odbc64/sql/cli/sqlcli.h
+++ b/win-odbc64/sql/cli/sqlcli.h
@@ -354,6 +354,11 @@ enum SQLTYPE_CODE {
     /* INTEGER/INT Tandem extensions */
     SQLTYPECODE_INTEGER_UNSIGNED       = -401,
     SQLTYPECODE_LARGEINT               = -402,
+	SQLTYPECODE_LARGEINT_UNSIGNED      = -405,
+
+	/* TINYINT */
+	SQLTYPECODE_TINYINT                = -403,
+	SQLTYPECODE_TINYINT_UNSIGNED	   = -404,
 
     /* SMALLINT */
     SQLTYPECODE_SMALLINT = 5,
@@ -416,6 +421,9 @@ enum SQLTYPE_CODE {
     /* LONG VARCHAR/ODBC CHARACTER VARYING */
     SQLTYPECODE_VARCHAR_LONG  = -1,		/* ## NEGATIVE??? */
 
+	/* BOOLEAN */
+	SQLTYPECODE_BOOLEAN  = -701,
+
     /* no ANSI value 13 */
 
     /* BIT */
@@ -425,6 +433,8 @@ enum SQLTYPE_CODE {
     SQLTYPECODE_BITVAR   = 15   /* not supported */
 };
 
+#define SQL_BOOLEAN			13
+
 /* #ifndef SQLDTCODE_DATE */
 /* specifies the type of datetime data type */
 enum SQLDATETIME_CODE {


Mime
View raw message