trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lium...@apache.org
Subject [3/5] incubator-trafodion git commit: [TRAFODION-2385] linux SQLTYPECODE_BOOLEAN using
Date Thu, 22 Jun 2017 12:25:56 GMT
[TRAFODION-2385] linux SQLTYPECODE_BOOLEAN using


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

Branch: refs/heads/master
Commit: 2b987205db02192911c11e0d19fd66193ab025ae
Parents: fe53516
Author: Weixin Xu <weixin.xu@esgyn.cn>
Authored: Mon Jun 12 17:11:37 2017 +0800
Committer: Weixin Xu <weixin.xu@esgyn.cn>
Committed: Mon Jun 12 17:11:37 2017 +0800

----------------------------------------------------------------------
 .../odbc/odbcclient/unixcli/cli/ctosqlconv.cpp  | 122 ++++++++++++++-----
 .../odbc/odbcclient/unixcli/cli/sqltocconv.cpp  |  81 ++++++------
 core/sql/cli/sqlcli.h                           |   2 -
 3 files changed, 133 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/2b987205/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 504c454..6d8f11b 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/ctosqlconv.cpp
@@ -326,11 +326,6 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 		targetUnsigned = true;
 	}
 
-    if (SQLDataType == SQLTYPECODE_BOOLEAN)
-    {
-        ODBCDataType = SQL_BOOLEAN;
-    }
-
 	if (CDataType == SQL_C_DEFAULT)
 	{
 		getCDefault(tODBCDataType, ODBCAppVersion, targetCharSet, CDataType);
@@ -379,6 +374,93 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 			}
 		}
 	case SQL_CHAR:
+        if( SQLDataType == SQLTYPECODE_BOOLEAN )
+        {
+            switch (CDataType)
+            {
+            case SQL_C_WCHAR:
+                if (iconv->isAppUTF16())
+                {
+                    if (srcLength != SQL_NTS)
+                        srcLength = srcLength/2;
+                    if (iconv->WCharToUTF8((UChar*)srcDataPtr, srcLength, srcDataLocale,
sizeof(srcDataLocale), (int*)&translateLength, (char*)errorMsg) != SQL_SUCCESS)
+                        return IDS_193_DRVTODS_ERROR;
+                    srcDataPtr = srcDataLocale;
+                    srcLength = translateLength;
+                }
+            case SQL_C_CHAR:
+                retCode = ConvertCharToNumeric(srcDataPtr, srcLength, dTmp);
+                if (retCode != SQL_SUCCESS)
+                    return retCode;
+                break;
+            case SQL_C_SHORT:
+            case SQL_C_SSHORT:
+                dTmp = *(SSHORT *)srcDataPtr;
+                break;
+            case SQL_C_USHORT:
+                dTmp = *(USHORT *)srcDataPtr;
+                break;
+            case SQL_C_TINYINT:
+            case SQL_C_STINYINT:
+                dTmp = *(SCHAR *)srcDataPtr;
+                break;
+            case SQL_C_UTINYINT:
+            case SQL_C_BIT:
+                dTmp = *(UCHAR *)srcDataPtr;
+                break;
+            case SQL_C_SLONG:
+            case SQL_C_LONG:
+                dTmp = *(SLONG_P *)srcDataPtr;
+                break;
+            case SQL_C_ULONG:
+                dTmp = *(ULONG_P *)srcDataPtr;
+                break;
+            case SQL_C_FLOAT:
+                dTmp = *(SFLOAT *)srcDataPtr;
+                break;
+            case SQL_C_DOUBLE:
+                dTmp = *(DOUBLE *)srcDataPtr;
+                break;
+            case SQL_C_BINARY:
+                DataPtr = srcDataPtr;
+                break;
+            case SQL_C_DEFAULT:
+                if (ODBCAppVersion >= SQL_OV_ODBC3)
+                    DataPtr = srcDataPtr;
+                else
+                {
+                    retCode = ConvertCharToNumeric(srcDataPtr, srcLength, dTmp);
+                    if (retCode!= SQL_SUCCESS)
+                        return retCode;
+                }
+                break;
+            case SQL_C_SBIGINT:
+                dTmp = *(__int64 *)srcDataPtr;
+                break;
+            case SQL_C_NUMERIC:
+                ConvertCNumericToChar((SQL_NUMERIC_STRUCT*)srcDataPtr, cTmpBuf);
+                srcLength = strlen(cTmpBuf);
+                retCode = ConvertCharToNumeric((char*)cTmpBuf, srcLength, dTmp);
+                if (retCode != SQL_SUCCESS)
+                    return retCode;
+                break;
+            default:
+                return IDS_07_006;
+            }
+            if (DataPtr == NULL)
+            {
+                if(dTmp < 0)
+                    return IDS_22_003_02;
+                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_WCHAR:
 		switch (CDataType)
 		{
@@ -696,7 +778,6 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 			DataLen = sizeof(fltTmp);
 			break;
 		}
-    case SQL_BOOLEAN:
     case SQL_TINYINT:
 	case SQL_SMALLINT:
 	case SQL_INTEGER:
@@ -922,17 +1003,6 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 			{
 				switch (ODBCDataType)
 				{
-                case SQL_BOOLEAN:
-                    if (dTmp < 0)
-                        return IDS_22_003_02;
-                    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)
                     {
@@ -1127,17 +1197,6 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 
 				switch( SQLDataType )
 				{
-                case SQLTYPECODE_BOOLEAN:
-                    if (tempVal64 < 0)
-                        return IDS_22_003_02;
-                    if (tempVal64 > 1)
-                        return IDS_22_003;
-                    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;
@@ -1248,9 +1307,6 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 		{
 			switch (ODBCDataType)
 			{
-            case SQL_BOOLEAN:
-                DataLen = sizeof(SCHAR);
-                break;
             case SQL_TINYINT:
                 DataLen = sizeof(SCHAR);
                 break;
@@ -3260,7 +3316,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 				 DataPtr, DataLen);
 		if (DataPtr != NULL && DataLen > 0 &&
 			(ODBCDataType == SQL_CHAR || ODBCDataType == SQL_VARCHAR || ODBCDataType == SQL_LONGVARCHAR
||
-			ODBCDataType == SQL_WCHAR || ODBCDataType == SQL_WVARCHAR) && CDataType != SQL_C_BINARY)
+			ODBCDataType == SQL_WCHAR || ODBCDataType == SQL_WVARCHAR) && CDataType != SQL_C_BINARY
&& SQLDataType != SQLTYPECODE_BOOLEAN)
 		{
 			SQLRETURN rc = SQL_SUCCESS;
 			if (targetCharSet == SQLCHARSETCODE_ISO88591)
@@ -3460,7 +3516,7 @@ unsigned long ODBC::ConvertCToSQL(SQLINTEGER	ODBCAppVersion,
 			if (Datatype_Dependent_Swap((BYTE *)outDataPtr-Offset, SQLDataType, targetCharSet, DataLen,
IEEE_TO_TANDEM) != STATUS_OK)
 				return IDS_HY_000;
 		}
-		if (ODBCDataType == SQL_CHAR || ODBCDataType == SQL_VARCHAR)
+		if (ODBCDataType == SQL_CHAR && SQLDataType != SQLTYPECODE_BOOLEAN || ODBCDataType
== SQL_VARCHAR)
 			memset((unsigned char *)outDataPtr+DataLen, ' ', targetLength-DataLen-Offset-1);
 	}
 	if (dataTruncatedWarning)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/2b987205/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 3c6af61..b1fdcb9 100644
--- a/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/sqltocconv.cpp
+++ b/core/conn/unixodbc/odbc/odbcclient/unixcli/cli/sqltocconv.cpp
@@ -354,11 +354,6 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
         srcUnsigned = true;
     }
 
-    if (SQLDataType == SQLTYPECODE_BOOLEAN)
-    {
-        ODBCDataType = SQL_BOOLEAN;
-    }
-
 	if (CDataType == SQL_C_DEFAULT)
 	{
 		getCDefault(tODBCDataType, ODBCAppVersion, srcCharSet, CDataType);
@@ -415,6 +410,16 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		switch (ODBCDataType)
 		{
 		case SQL_CHAR:
+            if(SQLDataType == SQLTYPECODE_BOOLEAN)
+            {
+                tTmp = *((SCHAR *) srcDataPtr);
+                _ltoa(tTmp, cTmpBuf, 10);
+                DataLen = strlen(cTmpBuf);
+                if(DataLen > targetLength)
+                    return IDS_22_003;
+                DataPtr = cTmpBuf;
+                break;
+            }
 		case SQL_WCHAR:
 			charlength = srcLength-1;
 			if (charlength == 0)
@@ -534,14 +539,6 @@ 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)
             {
@@ -589,15 +586,19 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 			LocalizeNumericString = TRUE;
 			break;
 		case SQL_BIGINT:
-/*#if !defined MXHPUX && !defined MXOSS && !defined MXAIX && !defined
MXSUNSPARC
-			sprintf( cTmpBuf, "%Ld", *((__int64 *)srcDataPtr));
-#else
-			sprintf( cTmpBuf, "%lld", *((__int64 *)srcDataPtr));
-#endif*/
+#if !defined MXHPUX && !defined MXOSS && !defined MXAIX && !defined
MXSUNSPARC
+//			sprintf( cTmpBuf, "%Ld", *((__int64 *)srcDataPtr));
             if (srcUnsigned)
-                snprintf( cTmpBuf, sizeof(__int64), "%lu", *((__int64 *)srcDataPtr));
+                snprintf( cTmpBuf, sizeof(unsigned __int64), "%lu", *((unsigned __int64 *)srcDataPtr));
             else
                 snprintf( cTmpBuf, sizeof(__int64), "%ld", *((__int64 *)srcDataPtr));
+#else
+//			sprintf( cTmpBuf, "%lld", *((__int64 *)srcDataPtr));
+            if (srcUnsigned)
+                snprintf( cTmpBuf, sizeof(unsigned __int64), "%llu", *((unsigned __int64
*)srcDataPtr));
+            else
+                snprintf( cTmpBuf, sizeof(__int64), "%lld", *((__int64 *)srcDataPtr));
+#endif
 			DataLen = strlen(cTmpBuf);
 			if (DataLen > targetLength)
 				return IDS_22_003;
@@ -770,6 +771,16 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		switch (ODBCDataType)
 		{
 		 case SQL_CHAR:
+            if(SQLDataType == SQLTYPECODE_BOOLEAN)
+            {
+                tTmp = *((SCHAR *) srcDataPtr);
+                _ltoa(tTmp, cTmpBuf, 10);
+                DataLen = strlen(cTmpBuf);
+                if(DataLen > targetLength)
+                    return IDS_22_003;
+                DataPtr = cTmpBuf;
+                break;
+            }
 		 case SQL_WCHAR:
 			charlength = srcLength-1;
 			if (charlength == 0)
@@ -900,14 +911,6 @@ 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)
             {
@@ -1148,6 +1151,11 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		switch (ODBCDataType)
 		{
 		case SQL_CHAR:
+            if(SQLDataType == SQLTYPECODE_BOOLEAN)
+            {
+                dTmp = *((SCHAR *) srcDataPtr);
+                break;
+            }
 		case SQL_VARCHAR:
 		case SQL_LONGVARCHAR:
 		case SQL_WCHAR:
@@ -1269,9 +1277,6 @@ 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)
             {
@@ -1543,7 +1548,8 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 				ODBCDataType != SQL_VARCHAR &&
 				ODBCDataType != SQL_LONGVARCHAR && 
 				ODBCDataType != SQL_WCHAR &&
-				ODBCDataType != SQL_WVARCHAR)
+				ODBCDataType != SQL_WVARCHAR ||
+                SQLDataType == SQLTYPECODE_BOOLEAN)
 				tempVal64 = dTmp;
 			DataPtr = &tempVal64;
 			DataLen = sizeof(tempVal64);
@@ -2477,7 +2483,6 @@ 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:
@@ -2507,6 +2512,13 @@ unsigned long ODBC::ConvertSQLToC(SQLINTEGER	ODBCAppVersion,
 		switch (ODBCDataType)
 		{
 		case SQL_CHAR:
+            if(SQLDataType == SQLTYPECODE_BOOLEAN)
+            {
+                tTmp = *((SCHAR *) srcDataPtr);
+                DataPtr = &tTmp;
+                DataLen = sizeof(SCHAR);
+                break;
+            }
 		case SQL_WCHAR:
 			charlength = srcLength-1;
 			if (charlength == 0)
@@ -2596,11 +2608,6 @@ 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:
             tTmp = *((SCHAR *) srcDataPtr);
             DataPtr = &tTmp;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/2b987205/core/sql/cli/sqlcli.h
----------------------------------------------------------------------
diff --git a/core/sql/cli/sqlcli.h b/core/sql/cli/sqlcli.h
index b68fee5..98149de 100644
--- a/core/sql/cli/sqlcli.h
+++ b/core/sql/cli/sqlcli.h
@@ -430,8 +430,6 @@ 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