trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbirds...@apache.org
Subject [1/2] trafodion git commit: TRAFODION-3019 pstmt.setByte cannot support string.getbyte well
Date Mon, 09 Apr 2018 14:59:16 GMT
Repository: trafodion
Updated Branches:
  refs/heads/master 51cdb91d7 -> 0551efb0b


TRAFODION-3019 pstmt.setByte cannot support string.getbyte well


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

Branch: refs/heads/master
Commit: 7914d91ec16e631adacf5d866675bb6f7326e7fa
Parents: 659e8ec
Author: aven <shengchen.ma@esgyn.cn>
Authored: Wed Apr 4 10:22:22 2018 +0800
Committer: aven <shengchen.ma@esgyn.cn>
Committed: Wed Apr 4 10:22:22 2018 +0800

----------------------------------------------------------------------
 .../trafodion/jdbc/t4/InterfaceStatement.java   | 45 ++++++++++----------
 .../jdbc_type2/native/SQLMXCommonFunctions.cpp  |  9 ++++
 .../org/apache/trafodion/jdbc/t2/SQLMXDesc.java |  2 +-
 .../jdbc/t2/SQLMXPreparedStatement.java         | 24 ++++++++---
 4 files changed, 52 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/7914d91e/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java
b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java
index ff5179e..7b42ed1 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java
@@ -161,28 +161,29 @@ class InterfaceStatement {
 				// line,
 				// because the array is already initialized to 0.
 				Bytes.insertShort(values, noNullValue, (short) 0, this.ic_.getByteSwap());
-			} else if (paramValue instanceof byte[]) {
-				tmpBarray = (byte[]) paramValue;
-			} else if (paramValue instanceof String) {
-				String charSet = "";
-
-				try {
-					if (this.ic_.getISOMapping() == InterfaceUtilities.SQLCHARSETCODE_ISO88591
-							&& !this.ic_.getEnforceISO() && dataCharSet == InterfaceUtilities.SQLCHARSETCODE_ISO88591)
-						charSet = ic_.t4props_.getISO88591();
-					else
-					{
-						if(dataCharSet == InterfaceUtilities.SQLCHARSETCODE_UNICODE && this.ic_.getByteSwap())
-							charSet = "UTF-16LE";
-						else
-							charSet = InterfaceUtilities.getCharsetName(dataCharSet);
-					}
-					tmpBarray = ((String) paramValue).getBytes(charSet);
-				} catch (Exception e) {
-					throw TrafT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
-							charSet);
-				}
-			} // end if (paramValue instanceof String)
+            } else if (paramValue instanceof byte[] || paramValue instanceof String) {
+                String charSet = "";
+
+                try {
+                    if (this.ic_.getISOMapping() == InterfaceUtilities.SQLCHARSETCODE_ISO88591
+                            && !this.ic_.getEnforceISO() && dataCharSet ==
InterfaceUtilities.SQLCHARSETCODE_ISO88591)
+                        charSet = ic_.t4props_.getISO88591();
+                    else {
+                        if (dataCharSet == InterfaceUtilities.SQLCHARSETCODE_UNICODE &&
this.ic_.getByteSwap())
+                            charSet = "UTF-16LE";
+                        else
+                            charSet = InterfaceUtilities.getCharsetName(dataCharSet);
+                    }
+                    if (paramValue instanceof byte[]) {
+                        tmpBarray = (new String((byte[]) paramValue)).getBytes(charSet);
+                    } else {
+                        tmpBarray = (((String) paramValue)).getBytes(charSet);
+                    }
+                } catch (Exception e) {
+                    throw TrafT4Messages.createSQLException(pstmt.connection_.props_, locale,
"unsupported_encoding",
+                            charSet);
+                }
+            } // end if (paramValue instanceof String)
 			else {
 				throw TrafT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_parameter_value",
 						"CHAR data should be either bytes or String for column: " + paramNumber);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7914d91e/core/conn/jdbc_type2/native/SQLMXCommonFunctions.cpp
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type2/native/SQLMXCommonFunctions.cpp b/core/conn/jdbc_type2/native/SQLMXCommonFunctions.cpp
index 75d4613..9151076 100644
--- a/core/conn/jdbc_type2/native/SQLMXCommonFunctions.cpp
+++ b/core/conn/jdbc_type2/native/SQLMXCommonFunctions.cpp
@@ -1577,6 +1577,15 @@ static Charset_def CHARSET_INFORMATION[] = {
 							if (dataLengthNotExceeded(charSet, dataLen, allocLength))
 							{
 								memcpy(dataPtr, (const void *)byteValue, dataLen);
+                                memset(dataPtr + (dataLen), ' ', allocLength - (dataLen));
+                                if (charSet == SQLCHARSETCODE_UCS2)
+                                {
+                                    // Back fill target buffer with double byte 'space' characters
(i.e. 0x00 0x20)
+                                    for (int i = (dataLen+1); i < allocLength-dataLen;
i+=2)
+                                    {
+                                        *(dataPtr+i) = 0;
+                                    }
+                                }
 							}
 							else
 							{

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7914d91e/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXDesc.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXDesc.java
b/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXDesc.java
index 252c790..9a2d70e 100644
--- a/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXDesc.java
+++ b/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXDesc.java
@@ -424,7 +424,7 @@ class SQLMXDesc
     public static final int SQLCHARSETCODE_GB2312           = 17;
 
 	public static final String SQLCHARSETSTRING_UNKNOWN     = "UNKNOWN";
-	public static final String SQLCHARSETSTRING_ISO88591    = "ISO88591";
+	public static final String SQLCHARSETSTRING_ISO88591    = "ISO-8859-1";
 	public static final String SQLCHARSETSTRING_KANJI       = "KANJI";
 	public static final String SQLCHARSETSTRING_KSC5601     = "KSC5601";
     public static final String SQLCHARSETSTRING_SJIS        = "MS932";

http://git-wip-us.apache.org/repos/asf/trafodion/blob/7914d91e/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXPreparedStatement.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXPreparedStatement.java
b/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXPreparedStatement.java
index 352bfe1..e7fd377 100644
--- a/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXPreparedStatement.java
+++ b/core/conn/jdbc_type2/src/main/java/org/apache/trafodion/jdbc/t2/SQLMXPreparedStatement.java
@@ -26,6 +26,7 @@ package org.apache.trafodion.jdbc.t2;
 
 import java.io.InputStream;
 import java.io.Reader;
+import java.io.UnsupportedEncodingException;
 import java.lang.ref.WeakReference;
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -1953,11 +1954,12 @@ public class SQLMXPreparedStatement extends SQLMXStatement implements
 			}
 
 
-			byte[] tmpArray = new byte[x.length];
-			System.arraycopy(x, 0, tmpArray, 0, x.length);
+			//byte[] tmpArray = new byte[x.length];
+			//System.arraycopy(x, 0, tmpArray, 0, x.length);
 
 			validateSetInvocation(parameterIndex);
 			dataType = inputDesc_[parameterIndex - 1].dataType_;
+            int dataCharSet = inputDesc_[parameterIndex - 1].sqlCharset_;
 			switch (dataType) {
 			case Types.BLOB:
 				long dataLocator = connection_.getDataLocator(
@@ -1969,12 +1971,24 @@ public class SQLMXPreparedStatement extends SQLMXStatement implements
 				isAnyLob_ = true;
 				paramContainer_.setLong(parameterIndex, dataLocator);
 				break;
+            case Types.CHAR:
+            case Types.VARCHAR:
+            case Types.LONGVARCHAR:
+                String charSet = SQLMXDesc.SQLCHARSETSTRING_ISO88591;
+                if (dataCharSet == SQLMXDesc.SQLCHARSETCODE_UCS2)
+                    charSet = "UTF-16LE";
+                try {
+                    x = (new String(x)).getBytes(charSet);
+                } catch (UnsupportedEncodingException e) {
+                    e.printStackTrace();
+                    throw Messages.createSQLException(connection_.locale_, "unsupported_encoding",
+                            new Object[] { charSet });
+                }
+                paramContainer_.setObject(parameterIndex, x);
+                break;
 			case Types.DATE:
 			case Types.TIME:
 			case Types.TIMESTAMP:
-			case Types.CHAR:
-			case Types.VARCHAR:
-			case Types.LONGVARCHAR:
 			case Types.BINARY:
 			case Types.VARBINARY:
 			case Types.LONGVARBINARY:


Mime
View raw message