You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by db...@apache.org on 2016/05/02 18:12:11 UTC

[32/60] incubator-trafodion git commit: TRAFODION-1933 JDBC TYpe4 driver build scripts migrated to use maven instead of ant

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
new file mode 100644
index 0000000..0d7c0b4
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
@@ -0,0 +1,927 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Date;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.text.DecimalFormat;
+import java.text.FieldPosition;
+import java.util.Properties;
+import java.util.logging.Level;
+
+class InterfaceResultSet {
+	InterfaceConnection ic_;
+	String stmtLabel_;
+
+	/* CHAR/CHARACTER */
+	static final int SQLTYPECODE_CHAR = 1;
+
+	/* NUMERIC */
+	static final int SQLTYPECODE_NUMERIC = 2;
+	static final int SQLTYPECODE_NUMERIC_UNSIGNED = -201;
+
+	/* DECIMAL */
+	static final int SQLTYPECODE_DECIMAL = 3;
+
+	static final int SQLTYPECODE_DECIMAL_UNSIGNED = -301;
+	static final int SQLTYPECODE_DECIMAL_LARGE = -302;
+	static final int SQLTYPECODE_DECIMAL_LARGE_UNSIGNED = -303;
+
+	/* INTEGER/INT */
+	static final int SQLTYPECODE_INTEGER = 4;
+
+	static final int SQLTYPECODE_INTEGER_UNSIGNED = -401;
+	static final int SQLTYPECODE_LARGEINT = -402;
+
+	/* SMALLINT */
+	static final int SQLTYPECODE_SMALLINT = 5;
+
+	static final int SQLTYPECODE_SMALLINT_UNSIGNED = -502;
+
+	static final int SQLTYPECODE_BPINT_UNSIGNED = -503;
+
+	/*
+	 * DOUBLE depending on precision
+	 */
+	static final int SQLTYPECODE_FLOAT = 6;
+
+	/*
+	 */
+	static final int SQLTYPECODE_REAL = 7;
+
+	/*
+	 */
+	static final int SQLTYPECODE_DOUBLE = 8;
+
+	/* DATE,TIME,TIMESTAMP */
+	static final int SQLTYPECODE_DATETIME = 9;
+
+	/* TIMESTAMP */
+	static final int SQLTYPECODE_INTERVAL = 10;
+
+	/* no ANSI value 11 */
+
+	/* VARCHAR/CHARACTER VARYING */
+	static final int SQLTYPECODE_VARCHAR = 12;
+
+	/* SQL/MP stype VARCHAR with length prefix:
+	 * */
+	static final int SQLTYPECODE_VARCHAR_WITH_LENGTH = -601;
+	static final int SQLTYPECODE_BLOB = -602;
+	static final int SQLTYPECODE_CLOB = -603;
+
+	/* LONG VARCHAR/ODBC CHARACTER VARYING */
+	static final int SQLTYPECODE_VARCHAR_LONG = -1; /* ## NEGATIVE??? */
+
+	/* no ANSI value 13 */
+
+	/* BIT */
+	static final int SQLTYPECODE_BIT = 14; /* not supported */
+
+	/* BIT VARYING */
+	static final int SQLTYPECODE_BITVAR = 15; /* not supported */
+
+	/* NCHAR -- CHAR(n) CHARACTER SET s -- where s uses two bytes per char */
+	static final int SQLTYPECODE_CHAR_DBLBYTE = 16;
+
+	/* NCHAR VARYING -- VARCHAR(n) CHARACTER SET s -- s uses 2 bytes per char */
+	static final int SQLTYPECODE_VARCHAR_DBLBYTE = 17;
+
+	/* Date/Time/TimeStamp related constants */
+	static final int SQLDTCODE_DATE = 1;
+	static final int SQLDTCODE_TIME = 2;
+	static final int SQLDTCODE_TIMESTAMP = 3;
+	static final int SQLDTCODE_MPDATETIME = 4;
+	static final int dateLength = 10;
+	static final int timeLength = 8;
+	static final int timestampLength = 26;
+
+	T4ResultSet t4resultSet_;
+
+	static Properties javaLangToJavaNio = null;
+
+	TrafT4ResultSet rs_;
+
+	InterfaceResultSet(TrafT4ResultSet rs) throws SQLException {
+		this.ic_ = ((TrafT4Connection) rs.connection_).getServerHandle();
+		stmtLabel_ = rs.stmtLabel_;
+		t4resultSet_ = new T4ResultSet(this);
+		rs_ = rs;
+	};
+
+	// -------------------------------------------------------------------
+	// from nskieee.cpp -- find the length for the data based on datatype
+	//
+	static int dataLengthFetchPerf(int SQLDataType, int SQLDateTimeCode, int SQLOctetLength, int maxRowLen,
+			int bufferLen, int ODBCDataType, int ODBCPrecision) {
+		int allocLength = 0;
+		switch (SQLDataType) {
+		case SQLTYPECODE_INTERVAL:
+			allocLength = SQLOctetLength;
+			break;
+		case SQLTYPECODE_VARCHAR_WITH_LENGTH:
+		case SQLTYPECODE_VARCHAR_LONG:
+		case SQLTYPECODE_VARCHAR_DBLBYTE:
+		case SQLTYPECODE_BITVAR:
+                case SQLTYPECODE_BLOB:
+                case SQLTYPECODE_CLOB:
+			allocLength = bufferLen + 2;
+			break;
+		case SQLTYPECODE_CHAR:
+
+			// allocLength = SQLOctetLength - 1; // no null at the end
+			allocLength = SQLOctetLength;
+			if (maxRowLen > 0) {
+				allocLength = (allocLength > maxRowLen) ? (maxRowLen + 1) : (allocLength);
+			}
+			break;
+		case SQLTYPECODE_BIT:
+		case SQLTYPECODE_CHAR_DBLBYTE:
+		case SQLTYPECODE_VARCHAR:
+			allocLength = SQLOctetLength - 1; // no null at the end
+			if (maxRowLen > 0) {
+				allocLength = (allocLength > maxRowLen) ? (maxRowLen + 1) : (allocLength);
+			}
+			break;
+		case SQLTYPECODE_DATETIME:
+			switch (SQLDateTimeCode) {
+			case SQLDTCODE_DATE:
+				allocLength = dateLength;
+				break;
+			case SQLDTCODE_TIME:
+				if (ODBCDataType == java.sql.Types.OTHER) // For
+				// HPT4Desc.SQLDTCODE_HOUR_TO_FRACTION
+				{
+					allocLength = SQLOctetLength;
+				} else {
+					allocLength = timeLength;
+				}
+				break;
+			case SQLDTCODE_TIMESTAMP:
+
+				/*
+				 * allocLength = timestampLength; if (SQLOctetLength <
+				 * timestampLength) { allocLength = 19; // timestamp without
+				 * fraction }
+				 */
+				allocLength = ODBCPrecision;
+				break;
+			default:
+				allocLength = SQLOctetLength;
+				break;
+			}
+
+			break;
+		default:
+			allocLength = SQLOctetLength; // exclude nullable
+			break;
+		}
+		return allocLength;
+	}
+
+	// -------------------------------------------------------------------
+	// get the column value data in String format
+	Object getFetchString(TrafT4Connection conn, int scale, int SQLDataType, int SQLDatetimeCode, int FSDataType,
+			byte[] ibuffer, int byteIndex, int byteLen, int SQLcharset, int ODBCDataType) throws SQLException {
+		Object retObj;
+		String tmpStr;
+		byte[] tbuffer;
+		BigDecimal tmpbd;
+
+		switch (SQLDataType) {
+
+		case SQLTYPECODE_CHAR:
+			tbuffer = new byte[byteLen];
+			System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
+			retObj = tbuffer;
+			break;
+		case SQLTYPECODE_VARCHAR:
+			tbuffer = new byte[byteLen];
+			System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
+			retObj = tbuffer;
+			break;
+		case SQLTYPECODE_INTERVAL:
+			tbuffer = new byte[byteLen];
+			System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
+			retObj = tbuffer;
+			break;
+		case SQLTYPECODE_VARCHAR_WITH_LENGTH:
+		case SQLTYPECODE_VARCHAR_LONG:
+		case SQLTYPECODE_BLOB:
+		case SQLTYPECODE_CLOB:
+			tbuffer = new byte[byteLen - 2];
+			System.arraycopy(ibuffer, byteIndex + 2, tbuffer, 0, byteLen - 2);
+
+			// retObj = new String(tbuffer); Swastik for LOB Support 10/29/2004
+			retObj = tbuffer;
+			break;
+		case SQLTYPECODE_DATETIME:
+			tmpStr = new String(Bytes.read_chars(ibuffer, byteIndex, byteLen));
+			switch (SQLDatetimeCode) {
+			case SQLDTCODE_DATE:
+				retObj = Date.valueOf(tmpStr);
+				break;
+			case SQLDTCODE_TIMESTAMP:
+				retObj = Timestamp.valueOf(tmpStr);
+				break;
+			case SQLDTCODE_TIME:
+
+				// Need to add code here to check if it's
+				// HPT4Desc.SQLDTCODE_HOUR_TO_FRACTION
+				if (ODBCDataType != java.sql.Types.OTHER) {
+					retObj = Time.valueOf(tmpStr);
+					break;
+				} else {
+					// Do default processing as it is
+					// HPT4Desc.SQLDTCODE_HOUR_TO_FRACTION
+				}
+			default:
+				retObj = tmpStr;
+				break;
+			}
+			break;
+		case SQLTYPECODE_SMALLINT:
+			short sValue = Bytes.extractShort(ibuffer, byteIndex, this.ic_.getByteSwap());
+			retObj = new Short(sValue);
+			if (scale > 0) {
+				retObj = new BigDecimal(new BigInteger(retObj.toString()), scale);
+			}
+			break;
+		case SQLTYPECODE_SMALLINT_UNSIGNED:
+			retObj = new Integer(Bytes.extractUShort(ibuffer, byteIndex, this.ic_.getByteSwap()));
+			if (scale > 0) {
+				retObj = new BigDecimal(new BigInteger(retObj.toString()), scale);
+			}
+			break;
+		case SQLTYPECODE_INTEGER:
+			retObj = new Integer(Bytes.extractInt(ibuffer, byteIndex, this.ic_.getByteSwap()));
+			if (scale > 0) {
+				retObj = new BigDecimal(new BigInteger(retObj.toString()), scale);
+			}
+			break;
+		case SQLTYPECODE_INTEGER_UNSIGNED:
+			retObj = new Long(Bytes.extractUInt(ibuffer, byteIndex, this.ic_.getByteSwap()));
+			if (scale > 0) {
+				retObj = new BigDecimal(new BigInteger(retObj.toString()), scale);
+			}
+			break;
+		case SQLTYPECODE_LARGEINT:
+			tbuffer = new byte[byteLen];
+			System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
+			retObj = new BigInteger(tbuffer);
+			if (scale > 0) {
+				retObj = new BigDecimal((BigInteger) retObj, scale);
+			}
+			break;
+		case SQLTYPECODE_NUMERIC:
+		case SQLTYPECODE_NUMERIC_UNSIGNED:
+			switch (FSDataType) {
+			case 130:
+			case 131:
+				tmpStr = String.valueOf(Bytes.extractShort(ibuffer, byteIndex, this.ic_.getByteSwap()));
+				break;
+			case 132:
+			case 133:
+				tmpStr = String.valueOf(Bytes.extractInt(ibuffer, byteIndex, this.ic_.getByteSwap()));
+				break;
+			case 134:
+				tmpStr = String.valueOf(Bytes.extractLong(ibuffer, byteIndex, this.ic_.getByteSwap()));
+				break;
+			default:
+				throw HPT4Messages.createSQLException(conn.props_, conn.getLocale(), "restricted_data_type", null);
+			}
+			retObj = new BigDecimal((new BigInteger(tmpStr)), scale);
+			break;
+		case SQLTYPECODE_DECIMAL:
+		case SQLTYPECODE_DECIMAL_UNSIGNED:
+		case SQLTYPECODE_DECIMAL_LARGE:
+		case SQLTYPECODE_DECIMAL_LARGE_UNSIGNED:
+			String retStr;
+
+			// check if the sign is minus (-80)
+			byte sign = (byte) (ibuffer[byteIndex] & (byte) (-80));
+
+			// first byte = inbyte - (-80)
+			if (sign == (byte) (-80)) {
+				byte firstByte = (byte) (ibuffer[byteIndex] - (byte) (-80));
+				retStr = "-" + firstByte + String.valueOf(Bytes.read_chars(ibuffer, byteIndex + 1, byteLen - 1));
+			} else {
+				retStr = String.valueOf(Bytes.read_chars(ibuffer, byteIndex, byteLen));
+			}
+			retObj = new BigDecimal(new BigInteger(retStr), scale);
+			break;
+		case SQLTYPECODE_REAL:
+			retObj = new Float(Float.intBitsToFloat(Bytes.extractInt(ibuffer, byteIndex, this.ic_.getByteSwap())));
+			break;
+		case SQLTYPECODE_DOUBLE:
+		case SQLTYPECODE_FLOAT:
+			retObj = new Double(Double.longBitsToDouble(Bytes.extractLong(ibuffer, byteIndex, this.ic_.getByteSwap())));
+			break;
+		case SQLTYPECODE_BIT:
+		case SQLTYPECODE_BITVAR:
+		case SQLTYPECODE_BPINT_UNSIGNED:
+		default:
+			throw HPT4Messages.createSQLException(conn.props_, conn.getLocale(), "restricted_data_type", null);
+		}
+		return retObj;
+	} // end getFetchString
+
+	private static String padZero(long i, int len) {
+		String s = String.valueOf(i);
+
+		while (s.length() < len)
+			s = '0' + s;
+
+		return s;
+	}
+
+	// -------------------------------------------------------------------
+	// get the column value data from Execute2 in String format
+	static Object getExecute2FetchString(TrafT4Connection conn, HPT4Desc desc, byte[] values, int noNullValue,
+			int ODBCDataType, boolean useOldDateFormat, boolean swap) throws SQLException {
+		Object retObj;
+		String tmpStr;
+		byte[] tbuffer;
+		BigDecimal tmpbd;
+		int length;
+		int year, month, day, hour, minute, second;
+		long nanoSeconds;
+
+		switch (desc.sqlDataType_) {
+		case SQLTYPECODE_CHAR:
+			length = desc.sqlOctetLength_;
+			tbuffer = new byte[length];
+			System.arraycopy(values, noNullValue, tbuffer, 0, length);
+			retObj = tbuffer;
+			break;
+		case SQLTYPECODE_VARCHAR:
+		case SQLTYPECODE_VARCHAR_WITH_LENGTH:
+		case SQLTYPECODE_VARCHAR_LONG:
+		case SQLTYPECODE_BLOB:
+		case SQLTYPECODE_CLOB:
+			boolean shortLength = desc.precision_ < Math.pow(2, 15);
+			int dataOffset = noNullValue + ((shortLength) ? 2 : 4);
+
+			length = (shortLength) ? Bytes.extractShort(values, noNullValue, swap) : Bytes.extractInt(values, noNullValue, swap);
+
+			tbuffer = new byte[length];
+			int len = values.length - (dataOffset);
+			System.arraycopy(values, (dataOffset), tbuffer, 0, (length > len) ? len : length);
+			retObj = tbuffer;
+			break;
+		case SQLTYPECODE_INTERVAL:
+			length = desc.sqlOctetLength_;
+			tbuffer = new byte[length];
+			System.arraycopy(values, noNullValue, tbuffer, 0, length);
+			retObj = tbuffer;
+			break;
+		case SQLTYPECODE_DATETIME:
+			switch (desc.sqlDatetimeCode_) {
+			case SQLDTCODE_DATE:
+				if (!useOldDateFormat) // new date format, only for bulk move
+				{
+					// "yyyy-mm-dd"
+					year = Bytes.extractUShort(values, noNullValue, swap);
+					month = values[noNullValue + 2];
+					day = values[noNullValue + 3];
+					String t = padZero(year,4) + "-" + padZero(month,2) + "-" + padZero(day,2);
+					retObj = Date.valueOf(t);
+				} else {// do the old way
+					length = dateLength;
+					retObj = Date.valueOf(new String(Bytes.read_chars(values, noNullValue, length)));
+				}
+				break;
+			case SQLDTCODE_TIMESTAMP:
+				if (!useOldDateFormat) // new date format, if not SQLCatalogs
+				{
+					// yyyy-mm-dd hh:mm:ss.fffffffff
+					year = Bytes.extractUShort(values, noNullValue, swap);
+					month = values[noNullValue + 2];
+					day = values[noNullValue + 3];
+					hour = values[noNullValue + 4];
+					minute = values[noNullValue + 5];
+					second = values[noNullValue + 6];
+
+					if (desc.sqlPrecision_ > 0) {
+						nanoSeconds = Bytes.extractUInt(values, noNullValue + 7, swap);
+
+						if (nanoSeconds > 999999) // returned in microseconds
+							nanoSeconds = 0;
+
+						// apply leading 0's for string conversion
+						tmpStr = "" + nanoSeconds;
+						length = tmpStr.length();
+						for (int i = 0; i < desc.sqlPrecision_ - length; i++) {
+							tmpStr = "0" + tmpStr;
+						}
+					} else {
+						tmpStr = "0";
+					}
+
+					retObj = Timestamp.valueOf(padZero((int) year, 4) + "-" + padZero(month, 2) + "-" + padZero(day, 2)
+							+ " " + padZero(hour, 2) + ":" + padZero(minute, 2) + ":" + padZero(second, 2) + "."
+							+ tmpStr);
+				} else { // do the old way
+					length = desc.precision_;
+					retObj = Timestamp.valueOf(new String(Bytes.read_chars(values, noNullValue, length)));
+				}
+				break;
+
+			case SQLDTCODE_TIME:
+				if (ODBCDataType == java.sql.Types.OTHER) // For
+				// HPT4Desc.SQLDTCODE_HOUR_TO_FRACTION
+				{
+					length = desc.sqlOctetLength_;
+					retObj = new String(Bytes.read_chars(values, noNullValue, length));
+				} else {
+					length = timeLength;
+					if (!useOldDateFormat) // new date format, only for bulk
+					// move
+					{
+						// "hh:mm:ss"
+						hour = values[noNullValue];
+						minute = values[noNullValue + 1];
+						second = values[noNullValue + 2];
+
+						if (desc.sqlPrecision_ > 0) {
+							nanoSeconds = Bytes.extractUInt(values, noNullValue + 3, swap);
+
+							if (nanoSeconds > 999999) // returned in microseconds
+								nanoSeconds = 0;
+
+							String formatStr = "";
+							for(int i=0;i<desc.sqlPrecision_;i++)
+								formatStr += "0";
+
+							StringBuffer sb = new StringBuffer();
+							DecimalFormat format = new DecimalFormat("00");
+							format.format(hour, sb, new FieldPosition(0));
+							sb.append(':');
+							format.format(minute, sb, new FieldPosition(0));
+							sb.append(':');
+							format.format(second, sb, new FieldPosition(0));
+							sb.append('.');
+							format = new DecimalFormat(formatStr);
+							format.format(nanoSeconds, sb, new FieldPosition(0));
+
+							retObj = sb.toString();
+						} else {
+							retObj = Time.valueOf(String.valueOf(hour) + ":" + String.valueOf(minute) + ":"
+									+ String.valueOf(second));
+						}
+					} else
+						// do the old way
+						retObj = Time.valueOf(new String(Bytes.read_chars(values, noNullValue, length)));
+				}
+				break;
+			default:
+				length = desc.sqlOctetLength_;
+				retObj = new String(Bytes.read_chars(values, noNullValue, length));
+				break;
+			}
+			break;
+		case SQLTYPECODE_SMALLINT:
+			short sValue = Bytes.extractShort(values, noNullValue, swap);
+			retObj = new Short(sValue);
+			if (desc.scale_ > 0) {
+				retObj = new BigDecimal(new BigInteger(retObj.toString()), desc.scale_);
+			}
+			break;
+		case SQLTYPECODE_SMALLINT_UNSIGNED:
+			int signedSValue = Bytes.extractUShort(values, noNullValue, swap);
+			if (desc.scale_ > 0) {
+				tmpbd = new BigDecimal(new BigInteger(String.valueOf(signedSValue)), (int) desc.scale_);
+			} else {
+				tmpbd = new BigDecimal(String.valueOf(signedSValue));
+			}
+			retObj = tmpbd;
+			break;
+		case SQLTYPECODE_INTEGER:
+			retObj = new Integer(Bytes.extractInt(values, noNullValue,swap));
+			if (desc.scale_ > 0) {
+				retObj = new BigDecimal(new BigInteger(retObj.toString()), desc.scale_);
+			}
+			break;
+		case SQLTYPECODE_INTEGER_UNSIGNED:
+			retObj = new Long(Bytes.extractUInt(values, noNullValue, swap));
+			if (desc.scale_ > 0) {
+				retObj = new BigDecimal(new BigInteger(retObj.toString()), desc.scale_);
+			}
+			break;
+		case SQLTYPECODE_LARGEINT:
+			retObj = new Long(Bytes.extractLong(values, noNullValue, swap));
+			if (desc.scale_ > 0) {
+				retObj = new BigDecimal(new BigInteger(retObj.toString()), desc.scale_);
+			}
+			break;
+		case SQLTYPECODE_NUMERIC:
+		case SQLTYPECODE_NUMERIC_UNSIGNED:
+			tbuffer = new byte[desc.sqlOctetLength_];
+			System.arraycopy(values, noNullValue, tbuffer, 0, desc.sqlOctetLength_);
+			retObj = InterfaceUtilities.convertSQLBigNumToBigDecimal(tbuffer, desc.scale_, swap);
+			break;
+		case SQLTYPECODE_DECIMAL:
+		case SQLTYPECODE_DECIMAL_UNSIGNED:
+		case SQLTYPECODE_DECIMAL_LARGE:
+		case SQLTYPECODE_DECIMAL_LARGE_UNSIGNED:
+			String retStr;
+
+			// check if the sign is minus (-80)
+			byte sign = (byte) (values[noNullValue] & (byte) (-80));
+
+			// first byte = inbyte - (-80)
+			if (sign == (byte) (-80)) {
+				byte firstByte = (byte) (values[noNullValue] - (byte) (-80));
+				retStr = "-" + firstByte
+						+ String.valueOf(Bytes.read_chars(values, noNullValue + 1, desc.sqlOctetLength_ - 1));
+			} else {
+				retStr = String.valueOf(Bytes.read_chars(values, noNullValue, desc.sqlOctetLength_));
+			}
+			retObj = new BigDecimal(new BigInteger(retStr), desc.scale_);
+			break;
+		case SQLTYPECODE_REAL:
+			retObj = new Float(Float.intBitsToFloat(Bytes.extractInt(values, noNullValue, swap)));
+			break;
+		case SQLTYPECODE_DOUBLE:
+		case SQLTYPECODE_FLOAT:
+			retObj = new Double(Double.longBitsToDouble(Bytes.extractLong(values, noNullValue, swap)));
+			break;
+		case SQLTYPECODE_BIT:
+		case SQLTYPECODE_BITVAR:
+		case SQLTYPECODE_BPINT_UNSIGNED:
+		default:
+			throw HPT4Messages.createSQLException(conn.props_, conn.getLocale(), "restricted_data_type", null);
+		}
+		return retObj;
+	} // end getExecute2FetchString
+
+	// -------------------------------------------------------------------
+	void setFetchOutputs(TrafT4ResultSet rs, int rowsAffected, boolean endOfData, byte[] outputDataValue)
+			throws SQLException
+
+	{
+		Row[] rowArray;
+		Object[] objectArray;
+		Object columnValue;
+
+		int columnCount;
+		int rowIndex;
+		int columnIndex;
+		int byteIndex = 0;
+		short SQLDataInd = 0;
+		int byteLen = 0;
+		int maxRowLen = rs.connection_.ic_.getTransportBufferSize(); // maxRowLen
+
+		rowArray = new Row[rowsAffected];
+
+		// get the number of colums
+		columnCount = rs.getNoOfColumns();
+
+		for (rowIndex = 0; rowIndex < rowsAffected; rowIndex++) {
+			if (rs.connection_.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+				Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, rs, outputDataValue, rowsAffected,
+						endOfData, 0);
+				String temp = "Reading row = " + rowIndex;
+				rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "setFetchOutputs", temp, p);
+			}
+			objectArray = new Object[columnCount];
+
+			for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
+				if (rs.connection_.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+					Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, rs, outputDataValue,
+							rowsAffected, endOfData, 0);
+					String temp = "Reading column = " + columnIndex;
+					rs.connection_.props_.t4Logger_
+							.logp(Level.FINEST, "InterfaceResultSet", "setFetchOutputs", temp, p);
+				}
+				SQLDataInd = new Byte(outputDataValue[byteIndex++]).shortValue();
+				if (rs.connection_.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+					Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, rs, outputDataValue,
+							rowsAffected, endOfData, 0);
+					String temp = "Row = " + rowIndex + "," + "Column = " + columnIndex + " SQLDataInd is = "
+							+ SQLDataInd;
+					rs.connection_.props_.t4Logger_
+							.logp(Level.FINEST, "InterfaceResultSet", "setFetchOutputs", temp, p);
+				}
+				if (SQLDataInd == 0) {
+					short varDataLen;
+					if (outputDataValue.length > (byteIndex + 2)) {
+						varDataLen = Bytes.extractShort(outputDataValue, byteIndex, this.ic_.getByteSwap());
+					} else {
+						varDataLen = 0;
+
+					}
+					byteLen = dataLengthFetchPerf(rs.outputDesc_[columnIndex].sqlDataType_,
+							rs.outputDesc_[columnIndex].sqlDatetimeCode_, rs.outputDesc_[columnIndex].sqlOctetLength_,
+							maxRowLen, // maxLength
+							varDataLen, rs.outputDesc_[columnIndex].dataType_, rs.outputDesc_[columnIndex].precision_);
+
+					columnValue = getFetchString(rs.connection_, rs.outputDesc_[columnIndex].scale_,
+							rs.outputDesc_[columnIndex].sqlDataType_, rs.outputDesc_[columnIndex].sqlDatetimeCode_,
+							rs.outputDesc_[columnIndex].fsDataType_, outputDataValue, byteIndex, byteLen,
+							rs.outputDesc_[columnIndex].sqlCharset_, rs.outputDesc_[columnIndex].dataType_);
+
+					byteIndex = byteIndex + byteLen;
+
+					switch (rs.outputDesc_[columnIndex].sqlDataType_) {
+					case SQLTYPECODE_VARCHAR_WITH_LENGTH:
+					case SQLTYPECODE_VARCHAR_LONG:
+					case SQLTYPECODE_VARCHAR_DBLBYTE:
+					case SQLTYPECODE_BITVAR:
+					case SQLTYPECODE_CHAR:
+					case SQLTYPECODE_CHAR_DBLBYTE:
+					case SQLTYPECODE_VARCHAR:
+					case SQLTYPECODE_BLOB:
+					case SQLTYPECODE_CLOB:
+						byteIndex++;
+						break;
+					}
+
+					if (columnValue == null) {
+						throw HPT4Messages
+								.createSQLException(rs.connection_.props_, ic_.getLocale(), "null_data", null);
+					}
+				} else {
+					columnValue = null;
+
+				}
+				objectArray[columnIndex] = columnValue;
+			}
+			rowArray[rowIndex] = new Row(columnCount, objectArray);
+		}
+		rs.setFetchOutputs(rowArray, rowsAffected, endOfData);
+	}
+
+	// ----------------------------------------------------------------------------
+	void setExecute2FetchOutputs(TrafT4ResultSet rs, int rowsAffected, boolean endOfData, byte[] values)
+			throws SQLException {
+		if (rs.useOldDateFormat()) {
+			setFetchOutputs(rs, rowsAffected, endOfData, values);
+			return;
+		}
+		Object[] objectArray;
+		Object columnValue;
+		Row[] rowArray = new Row[rowsAffected];
+
+		int columnCount = rs.getNoOfColumns();
+		int rowIndex;
+		int columnIndex;
+		int byteIndex = 0;
+		int SQLDataInd = 0;
+		int byteLen = 0;
+		int maxRowLen = rs.connection_.ic_.getTransportBufferSize(); // maxRowLen
+
+		objectArray = new Object[columnCount];
+
+		int dataLength = 0;
+
+		if (rs.outputDesc_ != null && rs.outputDesc_.length > 0) {
+			dataLength = rs.outputDesc_[0].rowLength_;
+		}
+
+		int rowOffset = 0;
+		for (rowIndex = 0; rowIndex < rowsAffected; rowIndex++) {
+			rowOffset = rowIndex * dataLength;
+
+			for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
+				int noNullValueOffset = rs.outputDesc_[columnIndex].noNullValue_;
+				int nullValueOffset = rs.outputDesc_[columnIndex].nullValue_;
+
+				if (nullValueOffset != -1)
+					nullValueOffset += rowOffset;
+				if (noNullValueOffset != -1)
+					noNullValueOffset += rowOffset;
+
+				if (rs.connection_.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+					Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, rs, endOfData, values);
+					String temp = "Processing column = " + columnIndex + ":   noNullValueOffset = " + noNullValueOffset
+							+ ":   nullValueOffset = " + nullValueOffset;
+					rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "setExecute2FetchOutputs",
+							temp, p);
+				}
+
+				if (nullValueOffset != -1 && Bytes.extractShort(values, nullValueOffset, this.ic_.getByteSwap()) == -1) {
+					columnValue = null;
+				} else {
+					columnValue = getExecute2FetchString(rs.connection_, rs.outputDesc_[columnIndex], values,
+							noNullValueOffset, rs.outputDesc_[columnIndex].dataType_, rs.useOldDateFormat(), this.ic_.getByteSwap());
+					if (columnValue == null) {
+						throw HPT4Messages
+								.createSQLException(rs.connection_.props_, ic_.getLocale(), "null_data", null);
+					}
+				} // end if else
+
+				objectArray[columnIndex] = columnValue;
+			} // end for
+
+			rowArray[rowIndex] = new Row(columnCount, objectArray);
+		}
+		rs.setFetchOutputs(rowArray, rowsAffected, endOfData);
+
+	} // end setExectue2FetchOutputs
+
+	// ----------------------------------------------------------------------------
+	// Interface methods
+	boolean fetch(String stmtLabel, int maxRowCnt, int queryTimeout, int holdability, TrafT4ResultSet rs)
+			throws SQLException {
+		int sqlAsyncEnable = 0;
+		int stmtHandle = 0;
+		int stmtCharset = 1;
+		String cursorName = "";
+		int cursorCharset = 1;
+		String stmtOptions = "";
+
+		boolean endOfData = false;
+		boolean dataFound = false;
+		String sqlStmt = ""; // qs_interface
+
+		if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+			Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, stmtLabel, maxRowCnt, queryTimeout,
+					holdability);
+			String temp = "Entering Fetch";
+			rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "fetch", temp, p);
+		}
+
+		if (rs_.stmt_ != null && rs_.stmt_.sql_ != null) {
+			sqlStmt = rs_.stmt_.sql_.toUpperCase();
+		}
+
+		FetchReply fr;
+
+		try {
+			fr = t4resultSet_.Fetch(sqlAsyncEnable, queryTimeout, stmtHandle, stmtCharset, maxRowCnt, cursorName,
+					cursorCharset, stmtOptions);
+
+		} catch (SQLException tex) {
+			if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+				Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, stmtLabel, maxRowCnt, queryTimeout,
+						holdability);
+				String temp = "SQLException while fetching.";
+				rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "fetch", temp, p);
+			}
+			throw tex;
+		}
+
+		switch (fr.returnCode) {
+		case TRANSPORT.CEE_SUCCESS:
+		case TRANSPORT.SQL_SUCCESS_WITH_INFO:
+
+			// do warning processing
+			if (fr.errorList.length != 0) {
+				HPT4Messages.setSQLWarning(rs.connection_.props_, rs, fr.errorList);
+			}
+			//endOfData = (fr.rowsAffected < maxRowCnt) ? true : false;
+
+			if (fr.rowsAffected > 0) {
+				if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+					Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, stmtLabel, maxRowCnt,
+							queryTimeout, holdability);
+					String temp = "Data Found. Setting fetch outputs";
+					rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "fetch", temp, p);
+				}
+				if (rs.keepRawBuffer_ == true) {
+					rs.rawBuffer_ = fr.outValues;
+				}
+
+				setExecute2FetchOutputs(rs, fr.rowsAffected, endOfData, fr.outValues);
+
+				dataFound = true;
+			}
+			break;
+		case 100: // fix this
+		case odbc_SQLSvc_Fetch_exc_.odbc_SQLSvc_Fetch_SQLNoDataFound_exn_:
+			dataFound = false;
+			endOfData = true;
+			break;
+
+		default:
+			HPT4Messages.throwSQLException(rs.connection_.props_, fr.errorList);
+
+		}
+
+		if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+			Object p[] = T4LoggingUtilities.makeParams(rs.connection_.props_, stmtLabel, maxRowCnt, queryTimeout,
+					holdability);
+			String temp = "Exiting Fetch.";
+			rs.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "fetch", temp, p);
+		}
+
+		// see if the rows fetched is valid
+		return dataFound;
+	};
+
+	void close() throws SQLException {
+		ic_.isConnectionOpen();
+		if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+			Object p[] = T4LoggingUtilities.makeParams(rs_.connection_.props_);
+			String temp = "Closing resultset.";
+			rs_.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "close", temp, p);
+		}
+
+		int rval = 0;
+		CloseReply cry_ = null;
+
+		//
+		// If the query is non-unique, then close the result set (cursor).
+		// If the query was a unique select, then the result set was implicitly
+		// closed by NCS.
+		//
+		if (rs_ != null && rs_.stmt_ != null && rs_.stmt_.ist_ != null
+				&& rs_.stmt_.ist_.sqlQueryType_ != TRANSPORT.SQL_SELECT_UNIQUE) {
+			cry_ = t4resultSet_.Close();
+
+			switch (cry_.m_p1.exception_nr) {
+			case TRANSPORT.CEE_SUCCESS:
+
+				// ignore the SQLWarning for the static close
+				break;
+			case odbc_SQLSvc_Close_exc_.odbc_SQLSvc_Close_SQLError_exn_:
+				if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+					Object p[] = T4LoggingUtilities.makeParams(rs_.connection_.props_);
+					String temp = "odbc_SQLSvc_Close_SQLError_exn_";
+					rs_.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "close", temp, p);
+				}
+
+				HPT4Messages.throwSQLException(rs_.connection_.props_, cry_.m_p1.SQLError);
+			default:
+				if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+					Object p[] = T4LoggingUtilities.makeParams(rs_.connection_.props_);
+					String temp = "UnknownException occurred during close.";
+					rs_.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "close", temp, p);
+				}
+				throw HPT4Messages.createSQLException(rs_.connection_.props_, ic_.getLocale(),
+						"ids_unknown_reply_error", null);
+			} // end switch
+		} // end if
+
+		if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+			Object p[] = T4LoggingUtilities.makeParams(rs_.connection_.props_);
+			String temp = "Closed resultset.";
+			rs_.connection_.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "close", temp, p);
+		}
+	};
+
+	// ----------------------------------------------------------------------------
+	static Object[] getExecute2Outputs(TrafT4Connection conn, HPT4Desc[] desc, byte[] values, boolean swap) throws SQLException
+
+	{
+		Object[] objectArray;
+		Object columnValue;
+		int columnIndex;
+		int columnCount = (desc == null) ? 0 : desc.length;
+
+		objectArray = new Object[columnCount];
+
+		for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
+			int noNullValueOffset = desc[columnIndex].noNullValue_;
+			int nullValueOffset = desc[columnIndex].nullValue_;
+
+			if (conn.props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+				Object p[] = T4LoggingUtilities.makeParams(conn.props_, conn, desc, values);
+				String temp = "Processing column = " + columnIndex + ":   noNullValueOffset = " + noNullValueOffset
+						+ ":   nullValueOffset = " + nullValueOffset;
+				conn.props_.t4Logger_.logp(Level.FINEST, "InterfaceResultSet", "getExecute2Outputs", temp, p);
+			}
+
+			if ((nullValueOffset != -1 && Bytes.extractShort(values, nullValueOffset, swap) == -1)
+					|| (desc[columnIndex].paramMode_ == HPT4ParameterMetaData.parameterModeIn)) {
+				columnValue = null;
+			} else {
+				columnValue = getExecute2FetchString(conn, desc[columnIndex], values, noNullValueOffset,
+						desc[columnIndex].dataType_, false, swap);
+				if (columnValue == null) {
+					throw HPT4Messages.createSQLException(conn.props_, conn.getLocale(), "null_data", null);
+				}
+			} // end if else
+
+			objectArray[columnIndex] = columnValue;
+		} // end for
+
+		return objectArray;
+
+	} // end getExectue2Outputs
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/72e17019/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
new file mode 100644
index 0000000..e6c7af8
--- /dev/null
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceStatement.java
@@ -0,0 +1,1392 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.jdbc.t4;
+
+import java.math.BigDecimal;
+import java.sql.DataTruncation;
+import java.sql.Date;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.logging.Level;
+
+class InterfaceStatement {
+	InterfaceConnection ic_;
+	private long rowCount_;
+	static final short SQL_DROP = 1;
+	static short EXTERNAL_STMT = 0;
+	int sqlStmtType_ = TRANSPORT.TYPE_UNKNOWN;
+	int stmtType_ = 0;
+	T4Statement t4statement_;
+	int queryTimeout_;
+	String stmtLabel_;
+	String cursorName_;
+	TrafT4Statement stmt_;
+
+	int sqlQueryType_;
+	int stmtHandle_;
+	int estimatedCost_;
+	boolean prepare2 = false;
+	boolean stmtIsLock = false; 
+
+	// used for SPJ transaction
+	static Class LmUtility_class_ = null;
+	static java.lang.reflect.Method LmUtility_getTransactionId_ = null;
+
+	PrepareReply pr_;
+
+	// ----------------------------------------------------------------------
+	InterfaceStatement(TrafT4Statement stmt) throws SQLException {
+		this.ic_ = ((TrafT4Connection) stmt.getConnection()).getServerHandle();
+		queryTimeout_ = stmt.queryTimeout_;
+		stmtLabel_ = stmt.stmtLabel_;
+		cursorName_ = stmt.cursorName_;
+		t4statement_ = new T4Statement(this);
+		stmt_ = stmt;
+	};
+
+	public int getSqlQueryType() {
+		return sqlQueryType_;
+	}
+
+	private String convertDateFormat(String dt) {
+		String tokens[] = dt.split("[/]", 3);
+
+		if (tokens.length != 3) {
+			return dt;
+		}
+		StringBuffer sb = new StringBuffer();
+		sb.append(tokens[0]).append("-").append(tokens[1]).append("-").append(tokens[2]);
+		return sb.toString();
+	}
+
+	// ----------------------------------------------------------------------
+	/**
+	 * This method will take an object and convert it to the approperite format
+	 * for sending to TrafT4.
+	 * 
+	 * @param locale
+	 *            The locale for this operation
+	 * @param pstmt
+	 *            The prepared statement associated with the object
+	 * @param paramValue
+	 *            The object to convert
+	 * @param paramNumber
+	 *            The parameter number associated with this object
+	 * @param values
+	 *            The array to place the converted object into
+	 */
+	void convertObjectToSQL2(Locale locale, TrafT4Statement pstmt, Object paramValue, int paramRowCount, int paramNumber,
+			byte[] values, int rowNumber) throws SQLException {
+		byte[] tmpBarray = null;
+		int i;
+		BigDecimal tmpbd;
+		
+		int precision = pstmt.inputDesc_[paramNumber].precision_;
+		int scale = pstmt.inputDesc_[paramNumber].scale_;
+		int sqlDatetimeCode = pstmt.inputDesc_[paramNumber].sqlDatetimeCode_;
+		int FSDataType = pstmt.inputDesc_[paramNumber].fsDataType_;
+		int OdbcDataType = pstmt.inputDesc_[paramNumber].dataType_;
+		int maxLength = pstmt.inputDesc_[paramNumber].sqlOctetLength_;
+		int dataType = pstmt.inputDesc_[paramNumber].sqlDataType_;
+		int dataCharSet = pstmt.inputDesc_[paramNumber].sqlCharset_;
+		int dataLen;
+
+		// setup the offsets
+		int noNullValue = pstmt.inputDesc_[paramNumber].noNullValue_;
+		int nullValue = pstmt.inputDesc_[paramNumber].nullValue_;
+		int dataLength = pstmt.inputDesc_[paramNumber].maxLen_;
+
+                boolean shortLength = precision < Math.pow(2, 15);
+                int dataOffset = ((shortLength) ? 2 : 4);
+
+		if ((dataType == InterfaceResultSet.SQLTYPECODE_VARCHAR_WITH_LENGTH)
+		 || (dataType == InterfaceResultSet.SQLTYPECODE_BLOB)
+		 || (dataType == InterfaceResultSet.SQLTYPECODE_CLOB)) {
+			dataLength += dataOffset;
+
+			if (dataLength % 2 != 0)
+				dataLength++;
+		}
+
+		noNullValue = (noNullValue * paramRowCount) + (rowNumber * dataLength);
+
+		if (nullValue != -1)
+			nullValue = (nullValue * paramRowCount) + (rowNumber * 2);
+
+		if (paramValue == null) {
+			if (nullValue == -1) {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale,
+						"null_parameter_for_not_null_column", new Integer(paramNumber));
+			}
+
+			// values[nullValue] = -1;
+			Bytes.insertShort(values, nullValue, (short) -1, this.ic_.getByteSwap());
+			return;
+		}
+
+		switch (dataType) {
+		case InterfaceResultSet.SQLTYPECODE_CHAR:
+			if (paramValue == null) {
+				// Note for future optimization. We can probably remove the next
+				// 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 HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
+							charSet);
+				}
+			} // end if (paramValue instanceof String)
+			else {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_parameter_value",
+						"CHAR data should be either bytes or String for column: " + paramNumber);
+			}
+
+			//
+			// We now have a byte array containing the parameter
+			//
+
+			dataLen = tmpBarray.length;
+			if (maxLength >= dataLen) {
+				System.arraycopy(tmpBarray, 0, values, noNullValue, dataLen);
+				// Blank pad for rest of the buffer
+				if (maxLength > dataLen) {
+					if (dataCharSet == InterfaceUtilities.SQLCHARSETCODE_UNICODE) {
+						// pad with Unicode spaces (0x00 0x32)
+						int i2 = dataLen;
+						while (i2 < maxLength) {
+							values[noNullValue + i2] = (byte) ' ';
+							values[noNullValue + (i2 + 1)] = (byte) 0 ;
+							i2 = i2 + 2;
+						}
+					} else {
+						Arrays.fill(values, (noNullValue + dataLen), (noNullValue + maxLength), (byte) ' ');
+					}
+				}
+			} else {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_string_parameter",
+						"CHAR input data is longer than the length for column: " + paramNumber);
+			}
+
+			break;
+		case InterfaceResultSet.SQLTYPECODE_VARCHAR:
+			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 HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
+							charSet);
+				}
+
+			} // end if (paramValue instanceof String)
+			else {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_parameter_value",
+						"VARCHAR data should be either bytes or String for column: " + paramNumber);
+			}
+
+			dataLen = tmpBarray.length;
+			if (maxLength > dataLen) {
+				Bytes.insertShort(values, noNullValue, (short) dataLen, this.ic_.getByteSwap());
+				System.arraycopy(tmpBarray, 0, values, noNullValue + 2, dataLen);
+			} else {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_parameter_value",
+						"VARCHAR input data is longer than the length for column: " + paramNumber);
+			}
+			break;
+		case InterfaceResultSet.SQLTYPECODE_DATETIME:
+			Date tmpdate = null;
+			switch (sqlDatetimeCode) {
+			case InterfaceResultSet.SQLDTCODE_DATE:
+				try {
+					if (((String) paramValue)
+							.matches("(\\d{4}-\\d{1,2}-\\d{1,2})|(\\d{1,2}\\.\\d{1,2}\\.\\d{4})|(\\d{1,2}/\\d{1,2}/\\d{4})")) {
+						tmpdate = Date.valueOf((String) ((String) paramValue)
+								.replaceFirst("(\\d{1,2})\\.(\\d{1,2})\\.(\\d{4})",	"$3-$2-$1")
+								.replaceFirst("(\\d{1,2})/(\\d{1,2})/(\\d{4})",	"$3-$1-$2"));
+					}else{
+						throw new IllegalArgumentException();
+					}
+				} catch (IllegalArgumentException iex) {
+					throw HPT4Messages
+							.createSQLException(
+									pstmt.connection_.props_,
+									locale,
+									"invalid_parameter_value",
+									"["+paramValue+"] Date format is incorrect or date value is invalide. "
+											+ "  Supported format: YYYY-MM-DD, MM/DD/YYYY, DD.MM.YYYY");
+				}
+				try {
+					byte[] temp1 = tmpdate.toString().getBytes("ASCII");
+					System.arraycopy(temp1, 0, values, noNullValue, temp1.length);
+				} catch (java.io.UnsupportedEncodingException e) {
+					Object[] messageArguments = new Object[1];
+					messageArguments[0] = e.getMessage();
+					throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
+							messageArguments);
+				}
+				break;
+			case InterfaceResultSet.SQLDTCODE_TIMESTAMP:
+				Timestamp tmpts;
+				try {
+					tmpts = Timestamp.valueOf((String) paramValue);
+				} catch (IllegalArgumentException iex) {
+					throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_parameter_value",
+							"Timestamp data format is incorrect for column: " + paramNumber + " = " + paramValue);
+				}
+
+				// ODBC precision is nano secs. JDBC precision is micro secs
+				// so substract 3 from ODBC precision.
+				maxLength = maxLength - 3;
+				try {
+					tmpBarray = tmpts.toString().getBytes("ASCII");
+				} catch (java.io.UnsupportedEncodingException e) {
+					Object[] messageArguments = new Object[1];
+					messageArguments[0] = e.getMessage();
+					throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
+							messageArguments);
+				}
+				dataLen = tmpBarray.length;
+
+				if (maxLength > dataLen) {
+					System.arraycopy(tmpBarray, 0, values, noNullValue, dataLen);
+
+					// Don't know when we need this. padding blanks. Legacy??
+					Arrays.fill(values, (noNullValue + dataLen), (noNullValue + maxLength), (byte) ' ');
+				} else {
+					System.arraycopy(tmpBarray, 0, values, noNullValue, maxLength);
+				}
+				break;
+			case InterfaceResultSet.SQLDTCODE_TIME:
+				// If the OdbcDataType is equal to Types.Other, that means
+				// that this is HOUR_TO_FRACTION and should be treated
+				// as a Type.Other --> see in SQLDesc.java
+				if (OdbcDataType != java.sql.Types.OTHER) // do the processing
+				// for TIME
+				{
+					Time tmptime;
+					try {
+						if (paramValue instanceof byte[]) {
+							tmptime = Time.valueOf(new String((byte[]) paramValue, "ASCII"));
+						} else {
+							tmptime = Time.valueOf(paramValue.toString());
+						}
+						byte[] tempb1 = tmptime.toString().getBytes("ASCII");
+						System.arraycopy(tempb1, 0, values, noNullValue, tempb1.length);
+					} catch (IllegalArgumentException iex) {
+						throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale,
+								"invalid_parameter_value", "Time data format is incorrect for column: " + paramNumber
+										+ " = " + paramValue);
+					} catch (java.io.UnsupportedEncodingException e) {
+						Object[] messageArguments = new Object[1];
+						messageArguments[0] = e.getMessage();
+						throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
+								messageArguments);
+					}
+					break;
+				} else {
+					// HPT4Desc.SQLDTCODE_HOUR_TO_FRACTION data type!!!
+					// let the next case structure handle it
+				}
+			case HPT4Desc.SQLDTCODE_YEAR:
+			case HPT4Desc.SQLDTCODE_YEAR_TO_MONTH:
+			case HPT4Desc.SQLDTCODE_MONTH:
+			case HPT4Desc.SQLDTCODE_MONTH_TO_DAY:
+			case HPT4Desc.SQLDTCODE_DAY:
+			case HPT4Desc.SQLDTCODE_HOUR:
+			case HPT4Desc.SQLDTCODE_HOUR_TO_MINUTE:
+			case HPT4Desc.SQLDTCODE_MINUTE:
+			case HPT4Desc.SQLDTCODE_MINUTE_TO_SECOND:
+				// case HPT4Desc.SQLDTCODE_MINUTE_TO_FRACTION:
+			case HPT4Desc.SQLDTCODE_SECOND:
+				// case HPT4Desc.SQLDTCODE_SECOND_TO_FRACTION:
+			case HPT4Desc.SQLDTCODE_YEAR_TO_HOUR:
+			case HPT4Desc.SQLDTCODE_YEAR_TO_MINUTE:
+			case HPT4Desc.SQLDTCODE_MONTH_TO_HOUR:
+			case HPT4Desc.SQLDTCODE_MONTH_TO_MINUTE:
+			case HPT4Desc.SQLDTCODE_MONTH_TO_SECOND:
+				// case HPT4Desc.SQLDTCODE_MONTH_TO_FRACTION:
+			case HPT4Desc.SQLDTCODE_DAY_TO_HOUR:
+			case HPT4Desc.SQLDTCODE_DAY_TO_MINUTE:
+			case HPT4Desc.SQLDTCODE_DAY_TO_SECOND:
+				// case HPT4Desc.SQLDTCODE_DAY_TO_FRACTION:
+			default:
+				if (paramValue instanceof String) {
+					try {
+						tmpBarray = ((String) paramValue).getBytes("ASCII");
+					} catch (Exception e) {
+						throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
+								"ASCII");
+					}
+				} else if (paramValue instanceof byte[]) {
+					tmpBarray = (byte[]) paramValue;
+				} else {
+					throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale,
+							"invalid_cast_specification", "DATETIME data should be either bytes or String for column: "
+									+ paramNumber);
+				}
+				dataLen = tmpBarray.length;
+				if (maxLength == dataLen) {
+					System.arraycopy(tmpBarray, 0, values, noNullValue, maxLength);
+				} else if (maxLength > dataLen) {
+					System.arraycopy(tmpBarray, 0, values, noNullValue, dataLen);
+
+					// Don't know when we need this. padding blanks. Legacy??
+					Arrays.fill(values, (noNullValue + dataLen), (noNullValue + maxLength), (byte) ' ');
+				} else {
+					throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_parameter_value",
+							"DATETIME data longer than column length: " + paramNumber);
+				}
+				break;
+			}
+			break;
+		case InterfaceResultSet.SQLTYPECODE_INTERVAL:
+			if (paramValue instanceof byte[]) {
+				tmpBarray = (byte[]) paramValue;
+			} else if (paramValue instanceof String) {
+				try {
+					tmpBarray = ((String) paramValue).getBytes("ASCII");
+				} catch (Exception e) {
+					throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
+							"ASCII");
+				}
+			} else {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_cast_specification",
+						"INTERVAL data should be either bytes or String for column: " + paramNumber);
+			}
+
+			dataLen = tmpBarray.length;
+			if (maxLength >= dataLen) {
+				dataLen = tmpBarray.length;
+				if (maxLength == dataLen) {
+					System.arraycopy(tmpBarray, 0, values, noNullValue, maxLength);
+				} else if (maxLength > dataLen) {
+					System.arraycopy(tmpBarray, 0, values, noNullValue, dataLen);
+
+					// Don't know when we need this. padding blanks. Legacy??
+					Arrays.fill(values, (noNullValue + dataLen), (noNullValue + maxLength), (byte) ' ');
+				}
+			} else {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_parameter_value",
+						"INTERVAL data longer than column length: " + paramNumber);
+			}
+
+			break;
+		case InterfaceResultSet.SQLTYPECODE_VARCHAR_WITH_LENGTH:
+		case InterfaceResultSet.SQLTYPECODE_VARCHAR_LONG:
+		case InterfaceResultSet.SQLTYPECODE_BLOB:
+		case InterfaceResultSet.SQLTYPECODE_CLOB:
+			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 HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
+							charSet);
+				}
+			} // end if (paramValue instanceof String)
+			else {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_cast_specification",
+						"VARCHAR data should be either bytes or String for column: " + paramNumber);
+			}
+
+			dataLen = tmpBarray.length;
+			if (maxLength > (dataLen + dataOffset)) { 
+				maxLength = dataLen + dataOffset;
+
+                                if (shortLength) {
+				   System.arraycopy(Bytes.createShortBytes((short) dataLen, this.ic_.getByteSwap()), 0, values, noNullValue, dataOffset);
+                                } else {
+				   System.arraycopy(Bytes.createIntBytes((int) dataLen, this.ic_.getByteSwap()), 0, values, noNullValue, dataOffset);
+                                }
+				System.arraycopy(tmpBarray, 0, values, (noNullValue + dataOffset), dataLen);
+			} else {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_string_parameter",
+						"VARCHAR data longer than column length: " + paramNumber);
+			}
+			break;
+		case InterfaceResultSet.SQLTYPECODE_INTEGER:
+			tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+			if (scale > 0) {
+				tmpbd = tmpbd.movePointRight(scale);
+			}
+
+			// data truncation check
+			if (pstmt.roundingMode_ == BigDecimal.ROUND_UNNECESSARY) {
+				Utility.checkLongTruncation(paramNumber, tmpbd);
+
+			}
+			Utility.checkIntegerBoundary(locale, tmpbd);
+
+			// check boundary condition for Numeric.
+			Utility.checkDecimalBoundary(locale, tmpbd, precision);
+
+			Bytes.insertInt(values, noNullValue, tmpbd.intValue(), this.ic_.getByteSwap());
+			break;
+		case InterfaceResultSet.SQLTYPECODE_INTEGER_UNSIGNED:
+			tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+			if (scale > 0) {
+				tmpbd = tmpbd.movePointRight(scale);
+			}
+
+			// data truncation check
+			if (pstmt.roundingMode_ == BigDecimal.ROUND_UNNECESSARY) {
+				Utility.checkLongTruncation(paramNumber, tmpbd);
+
+				// range checking
+			}
+			Utility.checkUnsignedIntegerBoundary(locale, tmpbd);
+
+			// check boundary condition for Numeric.
+			Utility.checkDecimalBoundary(locale, tmpbd, precision);
+
+			Bytes.insertInt(values, noNullValue, tmpbd.intValue(), this.ic_.getByteSwap());
+			break;
+		case InterfaceResultSet.SQLTYPECODE_SMALLINT:
+			tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+			if (scale > 0) {
+				tmpbd = tmpbd.movePointRight(scale);
+			}
+
+			// data truncation check
+			if (pstmt.roundingMode_ == BigDecimal.ROUND_UNNECESSARY) {
+				Utility.checkLongTruncation(paramNumber, tmpbd);
+
+				// range checking
+			}
+			Utility.checkShortBoundary(locale, tmpbd);
+
+			// check boundary condition for Numeric.
+			Utility.checkDecimalBoundary(locale, tmpbd, precision);
+
+			Bytes.insertShort(values, noNullValue, tmpbd.shortValue(), this.ic_.getByteSwap());
+			break;
+		case InterfaceResultSet.SQLTYPECODE_SMALLINT_UNSIGNED:
+			tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+			if (scale > 0) {
+				tmpbd = tmpbd.movePointRight(scale);
+			}
+
+			// data truncation check
+			if (pstmt.roundingMode_ == BigDecimal.ROUND_UNNECESSARY) {
+				Utility.checkLongTruncation(paramNumber, tmpbd);
+
+				// range checking
+			}
+			Utility.checkSignedShortBoundary(locale, tmpbd);
+
+			// check boundary condition for Numeric.
+			Utility.checkDecimalBoundary(locale, tmpbd, precision);
+
+			Bytes.insertShort(values, noNullValue, tmpbd.shortValue(), this.ic_.getByteSwap());
+			break;
+		case InterfaceResultSet.SQLTYPECODE_LARGEINT:
+			tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+
+			if (scale > 0) {
+				tmpbd = tmpbd.movePointRight(scale);
+
+				// check boundary condition for Numeric.
+			}
+			Utility.checkDecimalBoundary(locale, tmpbd, precision);
+			Bytes.insertLong(values, noNullValue, tmpbd.longValue(), this.ic_.getByteSwap());
+			break;
+		case InterfaceResultSet.SQLTYPECODE_DECIMAL:
+		case InterfaceResultSet.SQLTYPECODE_DECIMAL_UNSIGNED:
+
+			// create an parameter with out "."
+			try {
+				tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+				if (scale > 0) {
+					tmpbd = tmpbd.movePointRight(scale);
+
+				}
+
+				tmpbd = Utility.setScale(tmpbd, scale, pstmt.roundingMode_);
+
+				// data truncation check.
+				if (pstmt.roundingMode_ == BigDecimal.ROUND_UNNECESSARY) {
+					Utility.checkLongTruncation(paramNumber, tmpbd);
+
+					// get only the mantissa part
+				}
+				try {
+					tmpBarray = String.valueOf(tmpbd.longValue()).getBytes("ASCII");
+				} catch (java.io.UnsupportedEncodingException e) {
+					Object[] messageArguments = new Object[1];
+					messageArguments[0] = e.getMessage();
+					throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "unsupported_encoding",
+							messageArguments);
+				}
+			} catch (NumberFormatException nex) {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "invalid_parameter_value",
+						"DECIMAL data format incorrect for column: " + paramNumber + ". Error is: " + nex.getMessage());
+			}
+
+			dataLen = tmpBarray.length;
+
+			// pad leading zero's if datalen < maxLength
+			int desPos = 0;
+			int srcPos = 0;
+			boolean minus = false;
+
+			// check if data is negative.
+			if (tmpbd.signum() == -1) {
+				minus = true;
+				srcPos++;
+				dataLen--;
+			}
+
+			// pad beginning 0 for empty space.
+			int numOfZeros = maxLength - dataLen;
+
+			// DataTruncation is happening.
+			if (numOfZeros < 0) {
+				throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "data_truncation_exceed", new int[]{dataLen, maxLength});
+			}
+
+			for (i = 0; i < numOfZeros; i++) {
+				values[noNullValue + desPos] = (byte) '0';
+				desPos = desPos + 1;
+			}
+			System.arraycopy(tmpBarray, srcPos, values, noNullValue + desPos, dataLen);
+
+			// handling minus sign in decimal. OR -80 with the first byte for
+			// minus
+			if (minus) {
+				values[noNullValue] = (byte) ((byte) (-80) | values[noNullValue]);
+			}
+			break;
+		case InterfaceResultSet.SQLTYPECODE_REAL:
+			tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+			Utility.checkFloatBoundary(locale, tmpbd);
+			float fvalue = tmpbd.floatValue();
+			int bits = Float.floatToIntBits(fvalue);
+
+			Bytes.insertInt(values, noNullValue, bits, this.ic_.getByteSwap());
+			break;
+		case InterfaceResultSet.SQLTYPECODE_FLOAT:
+			tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+			Utility.checkFloatBoundary(locale, tmpbd);
+			Bytes.insertLong(values, noNullValue, Double.doubleToLongBits(tmpbd.doubleValue()), this.ic_.getByteSwap());
+			break;
+		case InterfaceResultSet.SQLTYPECODE_DOUBLE:
+			tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+			Utility.checkDoubleBoundary(locale, tmpbd);
+			Bytes.insertLong(values, noNullValue, Double.doubleToLongBits(tmpbd.doubleValue()), this.ic_.getByteSwap());
+			break;
+		case InterfaceResultSet.SQLTYPECODE_NUMERIC:
+		case InterfaceResultSet.SQLTYPECODE_NUMERIC_UNSIGNED:
+			tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+			byte[] b = InterfaceUtilities.convertBigDecimalToSQLBigNum(tmpbd, maxLength, scale);
+			System.arraycopy(b, 0, values, noNullValue, maxLength);
+			break;
+		// You will not get this type, since server internally converts it
+		// SMALLINT, INTERGER or LARGEINT
+		case InterfaceResultSet.SQLTYPECODE_DECIMAL_LARGE:
+		case InterfaceResultSet.SQLTYPECODE_DECIMAL_LARGE_UNSIGNED:
+		case InterfaceResultSet.SQLTYPECODE_BIT:
+		case InterfaceResultSet.SQLTYPECODE_BITVAR:
+		case InterfaceResultSet.SQLTYPECODE_BPINT_UNSIGNED:
+		default:
+			if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+				Object p[] = T4LoggingUtilities.makeParams(stmt_.connection_.props_, locale, pstmt, paramValue,
+						paramNumber);
+				String temp = "Restricted_Datatype_Error";
+				ic_.t4props_.t4Logger_.logp(Level.FINEST, "InterfaceStatement", "convertObjectToSQL2", temp, p);
+			}
+
+			throw HPT4Messages.createSQLException(pstmt.connection_.props_, locale, "restricted_data_type", null);
+		}
+		if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+			Object p[] = T4LoggingUtilities
+					.makeParams(stmt_.connection_.props_, locale, pstmt, paramValue, paramNumber);
+			String temp = "datatype = " + dataType;
+			ic_.t4props_.t4Logger_.logp(Level.FINEST, "InterfaceStatement", "convertObjectToSQL2", temp, p);
+		}
+
+	} // end convertObjectToSQL2
+
+	private SQLWarningOrError[] mergeErrors(SQLWarningOrError[] client, SQLWarningOrError[] server) {
+		SQLWarningOrError[] target = new SQLWarningOrError[client.length + server.length];
+
+		int si = 0; // server index
+		int ci = 0; // client index
+		int ti = 0; // target index
+
+		int sr; // server rowId
+		int cr; // client rowId
+
+		int so = 0; // server offset
+
+		while (ci < client.length && si < server.length) {
+			cr = client[ci].rowId;
+			sr = server[si].rowId + so;
+
+			if (cr <= sr || server[si].rowId == 0) {
+				so++;
+				target[ti++] = client[ci++];
+			} else {
+				server[si].rowId += so;
+				target[ti++] = server[si++];
+			}
+		}
+
+		// we only have one array left
+		while (ci < client.length) {
+			target[ti++] = client[ci++];
+		}
+
+		while (si < server.length) {
+			if (server[si].rowId != 0)
+				server[si].rowId += so;
+			target[ti++] = server[si++];
+		}
+
+		return target;
+	}
+
+	SQL_DataValue_def fillInSQLValues2(Locale locale, TrafT4Statement stmt, int paramRowCount, int paramCount,
+			Object[] paramValues, ArrayList clientErrors) throws SQLException
+
+	{
+		SQL_DataValue_def dataValue = new SQL_DataValue_def();
+
+		if (paramRowCount == 0 && paramValues != null && paramValues.length > 0)
+			paramRowCount = 1; // fake a single row if we are doing inputParams
+		// for an SPJ
+
+		// TODO: we should really figure out WHY this could happen
+		if (stmt.inputParamsLength_ < 0) {
+			dataValue.buffer = new byte[0];
+			dataValue.length = 0;
+		} else {
+			int bufLen = stmt.inputParamsLength_ * paramRowCount;
+
+			dataValue.buffer = new byte[bufLen];
+
+			for (int row = 0; row < paramRowCount; row++) {
+				for (int col = 0; col < paramCount; col++) {
+					try {
+						convertObjectToSQL2(locale, stmt, paramValues[row * paramCount + col], paramRowCount, col,
+								dataValue.buffer, row - clientErrors.size());
+					} catch (HPT4Exception e) {
+						if (paramRowCount == 1) // for single rows we need to
+							// throw immediately
+							throw e;
+
+						clientErrors.add(new SQLWarningOrError(row + 1, e.getErrorCode(), e.getMessage(), e
+								.getSQLState()));
+						break; // skip the rest of the row
+					}
+				}
+			}
+
+			// fix the column offsets if we had errors
+			if (clientErrors.size() > 0) {
+				int oldOffset;
+				int newOffset;
+				int noNullValue;
+				int nullValue;
+				int colLength;
+				int dataType;
+
+				for (int i = 1; i < paramCount; i++) // skip the first col
+				{
+					noNullValue = stmt.inputDesc_[i].noNullValue_;
+					nullValue = stmt.inputDesc_[i].nullValue_;
+					colLength = stmt.inputDesc_[i].maxLen_;
+					dataType = stmt.inputDesc_[i].dataType_;
+					if (dataType == InterfaceResultSet.SQLTYPECODE_VARCHAR_WITH_LENGTH
+							|| dataType == InterfaceResultSet.SQLTYPECODE_BLOB
+							|| dataType == InterfaceResultSet.SQLTYPECODE_CLOB
+							|| dataType == InterfaceResultSet.SQLTYPECODE_VARCHAR_LONG
+							|| dataType == InterfaceResultSet.SQLTYPECODE_VARCHAR) {
+                                                boolean shortLength = colLength < Math.pow(2, 15);
+                                                int dataOffset = ((shortLength) ? 2 : 4);
+                                                colLength += dataOffset;
+
+						if (colLength % 2 != 0)
+							colLength++;
+					}
+
+					if (nullValue != -1) {
+						oldOffset = nullValue * paramRowCount;
+						newOffset = oldOffset - (nullValue * clientErrors.size());
+						System.arraycopy(dataValue.buffer, oldOffset, dataValue.buffer, newOffset,
+								2 * (paramRowCount - clientErrors.size()));
+					}
+
+					oldOffset = noNullValue * paramRowCount;
+					newOffset = oldOffset - (noNullValue * clientErrors.size());
+					System.arraycopy(dataValue.buffer, oldOffset, dataValue.buffer, newOffset, colLength
+							* (paramRowCount - clientErrors.size()));
+				}
+			}
+
+			dataValue.length = stmt.inputParamsLength_ * (paramRowCount - clientErrors.size());
+		}
+		return dataValue;
+	}
+
+	boolean hasParameters(String sql) {
+		boolean foundParam = false;
+
+		String[] s = sql.split("\"[^\"]*\"|'[^']*'");
+		for (int i = 0; i < s.length; i++) {
+			if (s[i].indexOf('?') != -1) {
+				foundParam = true;
+				break;
+			}
+		}
+
+		return foundParam;
+	}
+	
+	/**
+	 * Get the transaction status
+	 * 
+	 * @param sql
+	 * @return
+	 */
+	private short getTransactionStatus(String sql) {
+		String tokens[] = sql.split("[^a-zA-Z]+", 3);
+		short rt1 = 0;
+		if (tokens.length > 1 && tokens[1].equalsIgnoreCase("WORK")) {
+			if (tokens[0].equalsIgnoreCase("BEGIN"))
+				rt1 = TRANSPORT.TYPE_BEGIN_TRANSACTION;
+		} else if (tokens[0].equalsIgnoreCase("COMMIT")
+				|| tokens[0].equalsIgnoreCase("ROLLBACK")) {
+			rt1 = TRANSPORT.TYPE_END_TRANSACTION;
+		}
+		
+		return rt1;
+	}
+	
+	// -------------------------------------------------------------
+	//TODO: this whole function needs to be rewritten
+	short getSqlStmtType(String str) {
+		str=str.replaceAll("\\n"," ");
+		str=str.replaceAll("\\s*/\\*.*?\\*/\\s*", " ").trim();
+
+		// 7708
+		stmtIsLock = false;
+
+		String tokens[] = str.split("[^a-zA-Z]+", 3);
+		short rt1 = TRANSPORT.TYPE_UNKNOWN;
+		String str3 = "";
+
+		if (tokens[0].length() > 0)
+			str3 = tokens[0].toUpperCase();
+		else
+			str3 = tokens[1].toUpperCase();
+
+		if(str3.equals("JOINXATXN")){
+			rt1 = TRANSPORT.TYPE_SELECT;
+		}
+		else if(str3.equals("WMSOPEN")) {
+			rt1 = TRANSPORT.TYPE_QS_OPEN;
+		}
+		else if(str3.equals("WMSCLOSE")) {
+			rt1 = TRANSPORT.TYPE_QS_CLOSE;
+		}
+		else if(str3.equals("CMDOPEN")) {
+			rt1 = TRANSPORT.TYPE_CMD_OPEN;
+		}
+		else if(str3.equals("CMDCLOSE")) {
+			rt1 = TRANSPORT.TYPE_CMD_CLOSE;
+		}
+		else {
+			switch(this.ic_.getMode()) {
+			case InterfaceConnection.MODE_SQL:
+				if ((str3.equals("SELECT")) || (str3.equals("SHOWSHAPE")) || (str3.equals("INVOKE"))
+						|| (str3.equals("SHOWCONTROL")) || (str3.equals("SHOWDDL")) || (str3.equals("EXPLAIN"))
+						|| (str3.equals("SHOWPLAN")) || (str3.equals("REORGANIZE")) || (str3.equals("MAINTAIN"))
+						|| (str3.equals("SHOWLABEL")) || (str3.equals("VALUES"))
+						|| (str3.equals("REORG")) || (str3.equals("SEL")) || (str3.equals("GET")) || (str3.equals("SHOWSTATS"))
+						|| str3.equals("GIVE") || str3.equals("STATUS") || str3.equals("INFO") || str3.equals("LIST")
+						) {
+					rt1 = TRANSPORT.TYPE_SELECT;
+				}
+				else if (str3.equals("UPDATE") || str3.equals("MERGE")) {
+					rt1 = TRANSPORT.TYPE_UPDATE;
+				} else if (str3.equals("DELETE") || str3.equals("STOP") || str3.equals("START")) {
+					rt1 = TRANSPORT.TYPE_DELETE;
+				} else if (str3.equals("INSERT") || str3.equals("INS") || str3.equals("UPSERT")) {
+					if (hasParameters(str)) {
+						rt1 = TRANSPORT.TYPE_INSERT_PARAM;
+					} else {
+						rt1 = TRANSPORT.TYPE_INSERT;
+					}
+				}
+				else if (str3.equals("CREATE")) {
+					rt1 = TRANSPORT.TYPE_CREATE;
+				} else if (str3.equals("GRANT")) {
+					rt1 = TRANSPORT.TYPE_GRANT;
+				} else if (str3.equals("DROP")) {
+					rt1 = TRANSPORT.TYPE_DROP;
+				} else if (str3.equals("CALL")) {
+					rt1 = TRANSPORT.TYPE_CALL;
+				} else if (str3.equals("EXPLAIN")) {
+					rt1 = TRANSPORT.TYPE_EXPLAIN;
+				} else if (str3.equals("INFOSTATS")) {
+					rt1 = TRANSPORT.TYPE_STATS;
+				}
+				break;
+			case InterfaceConnection.MODE_WMS:
+				if (str3.equals("STATUS") || str3.equals("INFO")) {
+					rt1 = TRANSPORT.TYPE_SELECT;
+				}
+				break;
+				/* FROM ODBC
+					if (_strnicmp(token, "STATUS", 6) == 0)
+						m_StmtType = TYPE_SELECT;
+					else if (_strnicmp(token, "CANCEL", 6) == 0)
+						m_StmtType = TYPE_UNKNOWN;
+					else if (_strnicmp(token, "SUSPEND", 7) == 0)
+						m_StmtType = TYPE_UNKNOWN;
+					else if (_strnicmp(token, "RESUME", 6) == 0)
+						m_StmtType = TYPE_UNKNOWN;
+					else if (_strnicmp(token, "ALTPRI", 6) == 0)
+						m_StmtType = TYPE_UNKNOWN;
+					else if (_strnicmp(token, "ADD", 3) == 0)
+						m_StmtType = TYPE_UNKNOWN;
+					else if (_strnicmp(token, "ALTER", 5) == 0)
+						m_StmtType = TYPE_UNKNOWN;
+					else if (_strnicmp(token, "DELETE", 6) == 0)
+						m_StmtType = TYPE_UNKNOWN;
+					else if (_strnicmp(token, "INFO", 4) == 0)
+						m_StmtType = TYPE_SELECT;
+					else
+						m_StmtType = TYPE_UNKNOWN;
+				}*/
+			case InterfaceConnection.MODE_CMD:
+				if (str3.equals("STATUS") || str3.equals("INFO") || str3.equals("LIST")) {
+					rt1 = TRANSPORT.TYPE_SELECT;
+				}
+				else if(str3.equals("ADD") || str3.equals("ALTER")) {
+					rt1 = TRANSPORT.TYPE_INSERT;
+				}
+				else if(str3.equals("DELETE") || str3.equals("STOP") || str3.equals("START")) {
+					rt1 = TRANSPORT.TYPE_DELETE;
+				}
+				break;
+			}
+		}
+		
+		return rt1;
+
+	} // end getSqlStmtType
+
+	// -------------------------------------------------------------
+	long getRowCount() {
+		return rowCount_;
+	}
+
+	// -------------------------------------------------------------
+	void setRowCount(long rowCount) {
+		if (rowCount < 0) {
+			rowCount_ = -1;
+		} else {
+			rowCount_ = rowCount;
+		}
+	}
+
+	// -------------------------------------------------------------
+	static HPT4Desc[] NewDescArray(SQLItemDescList_def desc) {
+		int index;
+		HPT4Desc[] HPT4DescArray;
+		SQLItemDesc_def SQLDesc;
+
+		if (desc.list == null || desc.list.length == 0) {
+			return null;
+		}
+
+		HPT4DescArray = new HPT4Desc[desc.list.length];
+
+		for (index = 0; index < desc.list.length; index++) {
+			SQLDesc = desc.list[index];
+			boolean nullInfo = (((new Byte(SQLDesc.nullInfo)).shortValue()) == 1) ? true : false;
+			boolean signType = (((new Byte(SQLDesc.signType)).shortValue()) == 1) ? true : false;
+			HPT4DescArray[index] = new HPT4Desc(SQLDesc.dataType, (short) SQLDesc.datetimeCode, SQLDesc.maxLen,
+					SQLDesc.precision, SQLDesc.scale, nullInfo, SQLDesc.colHeadingNm, signType, SQLDesc.ODBCDataType,
+					SQLDesc.ODBCPrecision, SQLDesc.SQLCharset, SQLDesc.ODBCCharset, SQLDesc.CatalogName,
+					SQLDesc.SchemaName, SQLDesc.TableName, SQLDesc.dataType, SQLDesc.intLeadPrec, SQLDesc.paramMode);
+		}
+		return HPT4DescArray;
+	}
+
+	// -------------------------------------------------------------
+	static HPT4Desc[] NewDescArray(Descriptor2[] descArray) {
+		int index;
+		HPT4Desc[] HPT4DescArray;
+		Descriptor2 desc;
+
+		if (descArray == null || descArray.length == 0) {
+			return null;
+		}
+
+		HPT4DescArray = new HPT4Desc[descArray.length];
+
+		for (index = 0; index < descArray.length; index++) {
+			desc = descArray[index];
+			boolean nullInfo = false;
+			boolean signType = false;
+
+			if (desc.nullInfo_ != 0) {
+				nullInfo = true;
+			}
+			if (desc.signed_ != 0) {
+				signType = true;
+
+			}
+			HPT4DescArray[index] = new HPT4Desc(desc.noNullValue_, desc.nullValue_, desc.version_, desc.dataType_,
+					(short) desc.datetimeCode_, desc.maxLen_, (short) desc.precision_, (short) desc.scale_, nullInfo,
+					signType, desc.odbcDataType_, desc.odbcPrecision_, desc.sqlCharset_, desc.odbcCharset_,
+					desc.colHeadingNm_, desc.tableName_, desc.catalogName_, desc.schemaName_, desc.headingName_,
+					desc.intLeadPrec_, desc.paramMode_, desc.dataType_, desc.getRowLength());
+		}
+		return HPT4DescArray;
+	}
+
+	// -------------------------------------------------------------
+	// Interface methods
+	void executeDirect(int queryTimeout, TrafT4Statement stmt) throws SQLException {
+		short executeAPI = stmt.getOperationID();
+		byte[] messageBuffer = stmt.getOperationBuffer();
+		GenericReply gr = null;
+
+		gr = t4statement_.ExecuteGeneric(executeAPI, messageBuffer);
+		stmt.operationReply_ = gr.replyBuffer;
+
+		if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+			Object p[] = T4LoggingUtilities.makeParams(stmt_.connection_.props_, queryTimeout, stmt);
+			String temp = "Exiting ExecDirect.";
+			ic_.t4props_.t4Logger_.logp(Level.FINEST, "InterfaceStatement", "executeDirect", temp, p);
+		}
+	} // end executeDirect
+
+	// --------------------------------------------------------------------------
+	int close() throws SQLException {
+		int rval = 0;
+		CloseReply cry_ = null;
+		ic_.isConnectionOpen();
+		if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+			Object p[] = T4LoggingUtilities.makeParams(stmt_.connection_.props_);
+			String temp = "Closing = " + stmtLabel_;
+			ic_.t4props_.t4Logger_.logp(Level.FINEST, "InterfaceStatement", "close", temp, p);
+		}
+
+		cry_ = t4statement_.Close();
+		switch (cry_.m_p1.exception_nr) {
+		case TRANSPORT.CEE_SUCCESS:
+
+			// ignore the SQLWarning for the static close
+			break;
+		case odbc_SQLSvc_Close_exc_.odbc_SQLSvc_Close_SQLError_exn_:
+			HPT4Messages.throwSQLException(stmt_.connection_.props_, cry_.m_p1.SQLError);
+		default:
+			throw HPT4Messages.createSQLException(stmt_.connection_.props_, ic_.getLocale(), "ids_unknown_reply_error",
+					null);
+		} // end switch
+
+		return cry_.m_p2; // rowsAffected
+	} // end close
+
+	// --------------------------------------------------------------------------
+	void cancel() throws SQLException {
+		ic_.cancel();
+	}
+
+	// --------------------------------------------------------------------------
+	// Interface methods for prepared statement
+	void prepare(String sql, int queryTimeout, TrafT4PreparedStatement pstmt) throws SQLException {
+		int sqlAsyncEnable = 0;
+		this.stmtType_ = this.EXTERNAL_STMT;
+		this.sqlStmtType_ = getSqlStmtType(sql);
+		this.setTransactionStatus(pstmt.connection_, sql);
+		int stmtLabelCharset = 1;
+		String cursorName = pstmt.cursorName_;
+		int cursorNameCharset = 1;
+		String moduleName = pstmt.moduleName_;
+		int moduleNameCharset = 1;
+		long moduleTimestamp = pstmt.moduleTimestamp_;
+		String sqlString = sql;
+		int sqlStringCharset = 1;
+		String stmtOptions = "";
+		int maxRowsetSize = pstmt.getMaxRows();
+
+		byte[] txId;
+
+//3196 - NDCS transaction for SPJ	
+//		if (ic_.t4props_.getSPJEnv())
+//			txId = getUDRTransaction(this.ic_.getByteSwap());
+//		else
+//			txId = Bytes.createIntBytes(0, false);
+		txId = Bytes.createIntBytes(0, false);
+
+		if (sqlStmtType_ == TRANSPORT.TYPE_STATS) {
+			throw HPT4Messages.createSQLException(pstmt.connection_.props_, ic_.getLocale(), "infostats_invalid_error",
+					null);
+		} else if (sqlStmtType_ == TRANSPORT.TYPE_CONFIG) {
+			throw HPT4Messages.createSQLException(pstmt.connection_.props_, ic_.getLocale(),
+					"config_cmd_invalid_error", null);
+		}
+
+		PrepareReply pr = t4statement_.Prepare(sqlAsyncEnable, (short) this.stmtType_, this.sqlStmtType_,
+				pstmt.stmtLabel_, stmtLabelCharset, cursorName, cursorNameCharset, moduleName, moduleNameCharset,
+				moduleTimestamp, sqlString, sqlStringCharset, stmtOptions, maxRowsetSize, txId);
+
+		pr_ = pr;
+		this.sqlQueryType_ = pr.sqlQueryType;
+
+		switch (pr.returnCode) {
+		case TRANSPORT.SQL_SUCCESS:
+		case TRANSPORT.SQL_SUCCESS_WITH_INFO:
+			HPT4Desc[] OutputDesc = InterfaceStatement.NewDescArray(pr.outputDesc);
+			HPT4Desc[] InputDesc = InterfaceStatement.NewDescArray(pr.inputDesc);
+			pstmt.setPrepareOutputs2(InputDesc, OutputDesc, pr.inputNumberParams, pr.outputNumberParams,
+					pr.inputParamLength, pr.outputParamLength, pr.inputDescLength, pr.outputDescLength);
+
+			if (pr.errorList != null && pr.errorList.length > 0) {
+				HPT4Messages.setSQLWarning(stmt_.connection_.props_, pstmt, pr.errorList);
+			}
+
+			this.stmtHandle_ = pr.stmtHandle;
+
+			break;
+
+		case odbc_SQLSvc_Prepare_exc_.odbc_SQLSvc_Prepare_SQLError_exn_:
+
+		default:
+			HPT4Messages.throwSQLException(stmt_.connection_.props_, pr.errorList);
+		}
+
+		if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+			Object p[] = T4LoggingUtilities.makeParams(stmt_.connection_.props_, sql, queryTimeout, pstmt);
+			String temp = "Exiting prepare...";
+			ic_.t4props_.t4Logger_.logp(Level.FINEST, "InterfaceStatement", "prepare", temp, p);
+		}
+	};
+
+	// used to keep the same transaction inside an SPJ. we call out to the UDR
+	// server and use their transaction for all executes.
+	byte[] getUDRTransaction(boolean swapBytes) throws SQLException {
+		byte[] ret = null;
+
+		try {
+			// To get references to method
+			InterfaceStatement.LmUtility_class_ = Class.forName("com.tandem.sqlmx.LmUtility");
+			InterfaceStatement.LmUtility_getTransactionId_ = InterfaceStatement.LmUtility_class_.getMethod(
+					"getTransactionId", new Class[] {});
+
+			// To invoke the method
+			short[] tId = (short[]) InterfaceStatement.LmUtility_getTransactionId_.invoke(null, new Object[] {});
+
+			ret = new byte[tId.length * 2];
+
+			for (int i = 0; i < tId.length; i++) {
+				Bytes.insertShort(ret, i * 2, tId[i], swapBytes);
+			}
+		} catch (Exception e) {
+			ic_.t4props_.t4Logger_.logp(Level.FINEST, "InterfaceStatement", "getUDRTransaction",
+					"Error calling UDR for transaction id");
+
+			String s = e.toString() + "\r\n";
+			StackTraceElement[] st = e.getStackTrace();
+
+			for (int i = 0; i < st.length; i++) {
+				s += st[i].toString() + "\r\n";
+			}
+
+			throw new SQLException(s);
+		}
+
+		return ret;
+	}
+
+	// -------------------------------------------------------------------
+	void execute(short executeAPI, int paramRowCount, int paramCount, Object[] paramValues, int queryTimeout
+	// executeDirect
+			, String sql, TrafT4Statement stmt
+
+	) throws SQLException {
+		cursorName_ = stmt.cursorName_;
+		rowCount_ = 0;
+
+		int sqlAsyncEnable = (stmt.getResultSetHoldability() == TrafT4ResultSet.HOLD_CURSORS_OVER_COMMIT) ? 1 : 0;
+		int inputRowCnt = paramRowCount;
+		int maxRowsetSize = stmt.getMaxRows();
+		String sqlString = (sql == null) ? stmt.getSQL() : sql;
+		int sqlStringCharset = 1;
+		int cursorNameCharset = 1;
+		int stmtLabelCharset = 1;
+		byte[] txId;
+		ArrayList clientErrors = new ArrayList();
+
+//3196 - NDCS transaction for SPJ	
+//		if (ic_.t4props_.getSPJEnv())
+//			txId = getUDRTransaction(this.ic_.getByteSwap());
+//		else if (stmt.transactionToJoin != null)
+//			txId = stmt.transactionToJoin;
+//		else if (stmt.connection_.transactionToJoin != null)
+//			txId = stmt.connection_.transactionToJoin;
+//		else
+//			txId = Bytes.createIntBytes(0, false); // 0 length, no data
+		if (stmt.transactionToJoin != null)
+			txId = stmt.transactionToJoin;
+		else if (stmt.connection_.transactionToJoin != null)
+			txId = stmt.connection_.transactionToJoin;
+		else
+			txId = Bytes.createIntBytes(0, false); // 0 length, no data
+
+		SQL_DataValue_def inputDataValue;
+		SQLValueList_def inputValueList = new SQLValueList_def();
+		byte[] inputParams = null;
+
+		if (executeAPI == TRANSPORT.SRVR_API_SQLEXECDIRECT) {
+			sqlStmtType_ = getSqlStmtType(sql);
+			setTransactionStatus(stmt.connection_, sql);
+			stmt.outputDesc_ = null; // clear the output descriptors
+		}
+
+		if (stmt.usingRawRowset_ == true) {
+			executeAPI = TRANSPORT.SRVR_API_SQLEXECUTE2;
+			inputDataValue = new SQL_DataValue_def();
+			inputDataValue.userBuffer = stmt.rowwiseRowsetBuffer_;
+			inputDataValue.length = stmt.rowwiseRowsetBuffer_.limit() - 4;
+
+			if (this.sqlQueryType_ == 16) // use the param values
+			{
+				try {
+					inputRowCnt = Integer.parseInt(paramValues[0].toString());
+					maxRowsetSize = Integer.parseInt(paramValues[1].toString());
+				} catch (Exception e) {
+					throw new SQLException(
+							"Error setting inputRowCnt and maxRowsetSize.  Parameters not set or invalid.");
+				}
+			} else {
+				inputRowCnt = paramRowCount - 1;
+			}
+
+		} else {
+			inputDataValue = fillInSQLValues2(ic_.getLocale(), stmt, inputRowCnt, paramCount, paramValues, clientErrors);
+
+			if (ic_.t4props_.t4Logger_.isLoggable(Level.FINEST) == true) {
+				Object p[] = T4LoggingUtilities.makeParams(stmt_.connection_.props_, paramRowCount, paramCount,
+						paramValues, queryTimeout, stmt);
+				String temp = "invoke ==> Execute2";
+				ic_.t4props_.t4Logger_.logp(Level.FINEST, "InterfaceStatement", "execute", temp, p);
+			}
+		}
+
+		ExecuteReply er = t4statement_.Execute(executeAPI, sqlAsyncEnable, inputRowCnt - clientErrors.size(),
+				maxRowsetSize, this.sqlStmtType_, this.stmtHandle_, sqlString, sqlStringCharset, this.cursorName_,
+				cursorNameCharset, stmt.stmtLabel_, stmtLabelCharset, inputDataValue, inputValueList, txId,
+				stmt.usingRawRowset_);
+
+		if (executeAPI == TRANSPORT.SRVR_API_SQLEXECDIRECT) {
+			this.sqlQueryType_ = er.queryType;
+		}
+
+		if (clientErrors.size() > 0) {
+			if (er.errorList == null)
+				er.errorList = (SQLWarningOrError[]) clientErrors.toArray(new SQLWarningOrError[clientErrors.size()]);
+			else
+				er.errorList = mergeErrors((SQLWarningOrError[]) clientErrors
+						.toArray(new SQLWarningOrError[clientErrors.size()]), er.errorList);
+		}
+
+		stmt_.result_set_offset = 0;
+		rowCount_ = er.rowsAffected;
+		
+		int numStatus;
+		
+		if (stmt_.connection_.props_.getDelayedErrorMode())
+		{
+			if (stmt_._lastCount > 0) {
+				numStatus = stmt_._lastCount;
+			}
+			else {
+				numStatus = inputRowCnt;
+			}
+		}
+		else
+		{
+			numStatus = inputRowCnt;
+		}
+
+	    if (numStatus < 1)
+	    {
+	    	numStatus = 1;
+	    }
+
+	    stmt.batchRowCount_ = new int[numStatus];
+	    boolean batchException = false;	//3164
+
+	    if (stmt_.connection_.props_.getDelayedErrorMode() && stmt_._lastCount < 1) {
+			Arrays.fill(stmt.batchRowCount_, -2); // fill with success
+	    } 
+	    else if (er.returnCode == TRANSPORT.SQL_SUCCESS || er.returnCode == TRANSPORT.SQL_SUCCESS_WITH_INFO
+				|| er.returnCode == TRANSPORT.NO_DATA_FOUND) {
+			Arrays.fill(stmt.batchRowCount_, -2); // fill with success
+			if (er.errorList != null) // if we had errors with valid rowIds,
+			// update the array
+			{
+				for (int i = 0; i < er.errorList.length; i++) {
+					int row = er.errorList[i].rowId - 1;
+					if (row >= 0 && row < stmt.batchRowCount_.length) {
+						stmt.batchRowCount_[row] = -3;
+						batchException = true;	//3164
+					}
+				}
+			}
+			
+			//set the statement mode as the command succeeded
+			if (sqlStmtType_ == TRANSPORT.TYPE_QS_OPEN) {
+				this.ic_.setMode(InterfaceConnection.MODE_WMS);
+			} else if (sqlStmtType_ == TRANSPORT.TYPE_QS_CLOSE) {
+				this.ic_.setMode(InterfaceConnection.MODE_SQL);
+			} else if(sqlStmtType_ == TRANSPORT.TYPE_CMD_OPEN) {
+				this.ic_.setMode(InterfaceConnection.MODE_CMD);
+			} else if(sqlStmtType_ == TRANSPORT.TYPE_CMD_CLOSE) {
+				this.ic_.setMode(InterfaceConnection.MODE_SQL);
+			}
+
+			// set the statement label if we didnt get one back.
+			if (er.stmtLabels == null || er.stmtLabels.length == 0) {
+				er.stmtLabels = new String[1];
+				er.stmtLabels[0] = stmt.stmtLabel_;
+			}
+
+			// get the descriptors from the proper location
+			HPT4Desc[][] desc = null;
+
+			// try from execute data first
+			if (er.outputDesc != null && er.outputDesc.length > 0) {
+				desc = new HPT4Desc[er.outputDesc.length][];
+
+				for (int i = 0; i < er.outputDesc.length; i++) {
+					desc[i] = InterfaceStatement.NewDescArray(er.outputDesc[i]);
+				}
+			}
+			// try from the prepare data
+			else if (stmt.outputDesc_ != null && stmt.outputDesc_.length > 0) {
+				desc = new HPT4Desc[1][];
+				desc[0] = stmt.outputDesc_;
+			}
+
+			if (this.sqlStmtType_ == TRANSPORT.TYPE_CALL) {
+				TrafT4CallableStatement cstmt = (TrafT4CallableStatement) stmt;
+				Object[] outputValueArray;
+				if(er.returnCode == TRANSPORT.NO_DATA_FOUND) { //this should really only happen with LAST0 specified
+					outputValueArray = new Object[cstmt.outputDesc_.length];
+				}
+				else {
+					outputValueArray = InterfaceResultSet.getExecute2Outputs(cstmt.connection_, cstmt.outputDesc_, 
+						er.outValues, this.ic_.getByteSwap());
+				}
+				
+				cstmt.setExecuteCallOutputs(outputValueArray, (short) er.rowsAffected);
+				stmt.setMultipleResultSets(er.numResultSets, desc, er.stmtLabels, er.proxySyntax);
+			} else {
+				// fix until we start returning numResultsets for more than just
+				// SPJs
+				if (desc != null && desc.length > 0 && er.numResultSets == 0) {
+					er.numResultSets = 1;
+				}
+
+				if (er.outValues != null && er.outValues.length > 0) {
+					stmt.setExecute2Outputs(er.outValues, (short) er.rowsAffected, false, er.proxySyntax, desc[0]);
+				} else {
+					stmt.setMultipleResultSets(er.numResultSets, desc, er.stmtLabels, er.proxySyntax);
+				}
+			}
+			if (er.errorList != null) {
+				HPT4Messages.setSQLWarning(stmt_.connection_.props_, stmt, er.errorList);
+			}
+		} else {
+			Arrays.fill(stmt.batchRowCount_, -3); // fill with failed
+			HPT4Messages.throwSQLException(stmt_.connection_.props_, er.errorList);
+		}
+	    //3164
+	    if (batchException) {
+	    	HPT4Messages.throwSQLException(stmt_.connection_.props_, er.errorList);
+	    }
+	}
+
+	protected void setTransactionStatus(TrafT4Connection conn, String sql) {
+		short tranStatus = getTransactionStatus(sql);
+		if(tranStatus == TRANSPORT.TYPE_BEGIN_TRANSACTION){
+			conn.setBeginTransaction(true);
+		}else if (tranStatus == TRANSPORT.TYPE_END_TRANSACTION){
+			conn.setBeginTransaction(false);
+		}
+		
+	}
+} // end class InterfaceStatement