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 2017/05/30 16:35:27 UTC
[1/3] incubator-trafodion git commit: TRAFODION-2385 jdbcT4 support
boolean, tinyint, largeint
Repository: incubator-trafodion
Updated Branches:
refs/heads/master 22b739ef5 -> 8fe0d62ad
TRAFODION-2385 jdbcT4 support boolean, tinyint, largeint
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/e32f6b9b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/e32f6b9b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/e32f6b9b
Branch: refs/heads/master
Commit: e32f6b9b3bff11c7609f6a2f8676e387ccefcfa7
Parents: f60c1b0
Author: mashengchen <ma...@gmail.com>
Authored: Thu May 18 10:29:56 2017 +0000
Committer: mashengchen <ma...@gmail.com>
Committed: Thu May 18 10:29:56 2017 +0000
----------------------------------------------------------------------
.../trafodion/jdbc/t4/InterfaceStatement.java | 21 ++-
.../jdbc/t4/TrafT4PreparedStatement.java | 44 ++++++-
.../org/trafodion/jdbc/t4/TrafT4ResultSet.java | 32 ++++-
.../java/org/trafodion/jdbc/t4/Utility.java | 11 +-
.../org/trafodion/jdbc_test/TestBoolean.java | 85 ++++++++++++
.../org/trafodion/jdbc_test/TestLargeInt.java | 131 +++++++++++++++++++
.../org/trafodion/jdbc_test/TestTinyInt.java | 131 +++++++++++++++++++
7 files changed, 436 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e32f6b9b/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 06aaa64..120f084 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
@@ -529,7 +529,7 @@ class InterfaceStatement {
Utility.checkUnsignedTinyintBoundary(locale, tmpbd);
- Bytes.insertShort(values, noNullValue, tmpbd.byteValueExact(), this.ic_.getByteSwap());
+ Bytes.insertShort(values, noNullValue, tmpbd.byteValue(), this.ic_.getByteSwap());
break;
case InterfaceResultSet.SQLTYPECODE_SMALLINT:
tmpbd = Utility.getBigDecimalValue(locale, paramValue);
@@ -563,7 +563,7 @@ class InterfaceStatement {
// range checking
}
- Utility.checkSignedShortBoundary(locale, tmpbd);
+ Utility.checkUnsignedShortBoundary(locale, tmpbd);
// check boundary condition for Numeric.
Utility.checkDecimalBoundary(locale, tmpbd, precision);
@@ -578,9 +578,21 @@ class InterfaceStatement {
// check boundary condition for Numeric.
}
+ Utility.checkLongBoundary(locale, tmpbd);
Utility.checkDecimalBoundary(locale, tmpbd, precision);
Bytes.insertLong(values, noNullValue, tmpbd.longValue(), this.ic_.getByteSwap());
break;
+ case InterfaceResultSet.SQLTYPECODE_LARGEINT_UNSIGNED:
+ tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+
+ if (scale > 0) {
+ tmpbd = tmpbd.movePointRight(scale);
+
+ // check boundary condition for Numeric.
+ }
+ Utility.checkUnsignedLongBoundary(locale, tmpbd);
+ Bytes.insertLong(values, noNullValue, tmpbd.longValue(), this.ic_.getByteSwap());
+ break;
case InterfaceResultSet.SQLTYPECODE_DECIMAL:
case InterfaceResultSet.SQLTYPECODE_DECIMAL_UNSIGNED:
@@ -671,6 +683,11 @@ class InterfaceStatement {
byte[] b = InterfaceUtilities.convertBigDecimalToSQLBigNum(tmpbd, maxLength, scale);
System.arraycopy(b, 0, values, noNullValue, maxLength);
break;
+ case InterfaceResultSet.SQLTYPECODE_BOOLEAN:
+ tmpbd = Utility.getBigDecimalValue(locale, paramValue);
+
+ Bytes.insertShort(values, noNullValue, tmpbd.shortValue(), this.ic_.getByteSwap());
+ break;
// You will not get this type, since server internally converts it
// SMALLINT, INTERGER or LARGEINT
case InterfaceResultSet.SQLTYPECODE_DECIMAL_LARGE:
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e32f6b9b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
index f10a33c..04fa6aa 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
@@ -576,10 +576,13 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
validateSetInvocation(parameterIndex);
inputDesc_[parameterIndex - 1].checkValidNumericConversion(connection_.getLocale());
+ int sqltype = inputDesc_[parameterIndex - 1].sqlDataType_;
if (x != null) {
- Utility.checkDecimalTruncation(parameterIndex, connection_.getLocale(), x,
- inputDesc_[parameterIndex - 1].precision_, inputDesc_[parameterIndex - 1].scale_);
+ if (sqltype == InterfaceResultSet.SQLTYPECODE_LARGEINT){
+ Utility.checkDecimalTruncation(parameterIndex, connection_.getLocale(), x,
+ inputDesc_[parameterIndex - 1].precision_, inputDesc_[parameterIndex - 1].scale_);
+ }
addParamValue(parameterIndex, x.toString());
} else {
addParamValue(parameterIndex, null);
@@ -1051,10 +1054,29 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
}
validateSetInvocation(parameterIndex);
inputDesc_[parameterIndex - 1].checkValidNumericConversion(connection_.getLocale());
- Utility.checkLongBoundary(connection_.getLocale(), BigDecimal.valueOf(x));
addParamValue(parameterIndex, Long.toString(x));
}
+ private void setLong(int parameterIndex, BigDecimal x) throws SQLException {
+ if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
+ Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x);
+ connection_.props_.t4Logger_.logp(Level.FINE, "TrafT4PreparedStatement", "setLong", "", p);
+ }
+ if (connection_.props_.getLogWriter() != null) {
+ LogRecord lr = new LogRecord(Level.FINE, "");
+ Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, x);
+ lr.setParameters(p);
+ lr.setSourceClassName("TrafT4PreparedStatement");
+ lr.setSourceMethodName("setLong");
+ T4LogFormatter lf = new T4LogFormatter();
+ String temp = lf.format(lr);
+ connection_.props_.getLogWriter().println(temp);
+ }
+ validateSetInvocation(parameterIndex);
+ inputDesc_[parameterIndex - 1].checkValidNumericConversion(connection_.getLocale());
+ addParamValue(parameterIndex, x);
+ }
+
public void setNull(int parameterIndex, int sqlType) throws SQLException {
if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == true) {
Object p[] = T4LoggingUtilities.makeParams(connection_.props_, parameterIndex, sqlType);
@@ -1192,6 +1214,7 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
if (x == null) {
setNull(parameterIndex, Types.NULL);
} else {
+ int type = inputDesc_[parameterIndex - 1].sqlDataType_;
switch (targetSqlType) {
case Types.CHAR:
case Types.VARCHAR:
@@ -1258,9 +1281,14 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
break;
case Types.BIGINT:
tmpbd = Utility.getBigDecimalValue(locale, x);
- Utility.checkLongBoundary(locale, tmpbd);
//Utility.checkLongTruncation(parameterIndex, tmpbd);
- setLong(parameterIndex, tmpbd.longValue());
+ if (type == InterfaceResultSet.SQLTYPECODE_LARGEINT_UNSIGNED){
+ Utility.checkUnsignedLongBoundary(locale, tmpbd);
+ setLong(parameterIndex, tmpbd);
+ } else{
+ Utility.checkLongBoundary(locale, tmpbd);
+ setLong(parameterIndex, tmpbd.longValue());
+ }
break;
case Types.DECIMAL:
// precision = getPrecision(parameterIndex - 1);
@@ -1279,7 +1307,11 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
case Types.TINYINT:
tmpbd = Utility.getBigDecimalValue(locale, x);
tmpbd = Utility.setScale(tmpbd, scale, roundingMode_);
- Utility.checkSignedTinyintBoundary(locale, tmpbd);
+ if (type == InterfaceResultSet.SQLTYPECODE_TINYINT_UNSIGNED) {
+ Utility.checkUnsignedTinyintBoundary(locale, tmpbd);
+ } else {
+ Utility.checkSignedTinyintBoundary(locale, tmpbd);
+ }
setShort(parameterIndex, tmpbd.shortValue());
break;
case Types.FLOAT:
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e32f6b9b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
index 4793787..a3d1826 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
@@ -698,6 +698,7 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
throw TrafT4Messages.createSQLException(connection_.props_, connection_.getLocale(),
"invalid_cast_specification", null);
}
+
d1 = d.doubleValue();
// To allow -128.999.. and 127.999...
if (d1 > (double) Byte.MIN_VALUE - 1 && d1 < (double) Byte.MAX_VALUE + 1) {
@@ -1470,13 +1471,16 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
validateGetInvocation(columnIndex);
dataType = outputDesc_[columnIndex - 1].dataType_;
precision = outputDesc_[columnIndex - 1].sqlPrecision_;
+ int sqltype = outputDesc_[columnIndex - 1].sqlDataType_;
switch (dataType) {
case Types.TINYINT:
- byteValue = getByte(columnIndex);
if (wasNull_) {
return null;
+ }
+ if (sqltype == InterfaceResultSet.SQLTYPECODE_TINYINT_UNSIGNED) {
+ return new Short(getShort(columnIndex));
} else {
- return new Byte(byteValue);
+ return new Byte(getByte(columnIndex));
}
case Types.SMALLINT:
shortValue = getShort(columnIndex);
@@ -1493,11 +1497,13 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
return new Integer(intValue);
}
case Types.BIGINT:
- longValue = getLong(columnIndex);
if (wasNull_) {
return null;
+ }
+ if (sqltype == InterfaceResultSet.SQLTYPECODE_LARGEINT_UNSIGNED) {
+ return getBigDecimal(columnIndex);
} else {
- return new Long(longValue);
+ return new Long(getLong(columnIndex));
}
case Types.REAL:
floatValue = getFloat(columnIndex);
@@ -1525,6 +1531,12 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
return new Boolean(booleanValue);
}
case Types.CHAR:
+ if (wasNull_) {
+ return null;
+ }
+ if (sqltype == InterfaceResultSet.SQLTYPECODE_BOOLEAN) {
+ return new Boolean(getBoolean(columnIndex));
+ }
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.BLOB:
@@ -1815,6 +1827,7 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
wasNull_ = false;
targetSqlType = outputDesc_[columnIndex - 1].dataType_;
precision = outputDesc_[columnIndex - 1].sqlPrecision_;
+ int sqltype = outputDesc_[columnIndex - 1].sqlDataType_;
switch (targetSqlType) {
@@ -1865,6 +1878,11 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
data = String.valueOf(getShort(columnIndex));
break;
case Types.TINYINT:
+ if (sqltype == InterfaceResultSet.SQLTYPECODE_TINYINT_UNSIGNED) {
+ data = String.valueOf(getShort(columnIndex));
+ } else {
+ data = String.valueOf(getByte(columnIndex));
+ }
data = String.valueOf(getByte(columnIndex));
break;
case Types.REAL:
@@ -1889,7 +1907,11 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
}
break;
case Types.BIGINT:
- data = String.valueOf(getLong(columnIndex));
+ if (sqltype == InterfaceResultSet.SQLTYPECODE_LARGEINT_UNSIGNED) {
+ data = String.valueOf(getBigDecimal(columnIndex));
+ } else {
+ data = String.valueOf(getLong(columnIndex));
+ }
break;
case Types.INTEGER:
data = String.valueOf(getInt(columnIndex));
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e32f6b9b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Utility.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Utility.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Utility.java
index e984187..6eb0899 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Utility.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Utility.java
@@ -162,12 +162,11 @@ class Utility {
* @return none
*
*/
- static void checkSignedLongBoundary(Locale locale, BigDecimal inbd) throws SQLException {
- long inlong = inbd.longValue();
+ static void checkUnsignedLongBoundary(Locale locale, BigDecimal inbd) throws SQLException {
BigDecimal maxbd = new BigDecimal(Long.MAX_VALUE);
- maxbd = maxbd.add(maxbd);
- if ((inlong < 0) || (inbd.compareTo(maxbd) > 0)) {
- throw TrafT4Messages.createSQLException(null, locale, "numeric_out_of_range", String.valueOf(inlong));
+ maxbd = maxbd.add(maxbd).add(BigDecimal.valueOf(1));
+ if ((inbd.compareTo(BigDecimal.valueOf(0)) < 0) || (inbd.compareTo(maxbd) > 0)) {
+ throw TrafT4Messages.createSQLException(null, locale, "numeric_out_of_range", String.valueOf(inbd));
}
} // end checkIntegerBoundary
@@ -183,7 +182,7 @@ class Utility {
* @return none
*
*/
- static void checkSignedShortBoundary(Locale locale, BigDecimal inbd) throws SQLException {
+ static void checkUnsignedShortBoundary(Locale locale, BigDecimal inbd) throws SQLException {
long inlong = inbd.longValue();
long maxushort = (Short.MAX_VALUE * 2) + 1;
if ((inlong < 0) || (inlong > maxushort)) {
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e32f6b9b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBoolean.java
----------------------------------------------------------------------
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBoolean.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBoolean.java
new file mode 100644
index 0000000..d22fe56
--- /dev/null
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestBoolean.java
@@ -0,0 +1,85 @@
+/**
+ * @@@ 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 @@
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.junit.Test;
+
+public class TestBoolean {
+
+ @Test
+ public void JDBCBoolean() throws SQLException {
+ Connection conn = null;
+ Statement stmt = null;
+ PreparedStatement prepStmt = null;
+ ResultSet rs = null;
+ String sql = "insert into boolean_tbl values (?,?);";
+ try {
+ conn = Utils.getUserConnection();
+ conn.createStatement().executeUpdate("cqd traf_boolean_io 'ON'");
+ stmt = conn.createStatement();
+ stmt.executeUpdate("set schema " + Utils.catalog + "." + Utils.schema);
+ stmt.executeUpdate("create table if not exists boolean_tbl (c0 int not null, c1 boolean)");
+ stmt.executeUpdate("delete from boolean_tbl");
+
+ prepStmt = conn.prepareStatement(sql);
+ prepStmt.setInt(1, 1);
+ prepStmt.setBoolean(2, true);
+ prepStmt.addBatch();
+
+ prepStmt.setInt(1, 2);
+ prepStmt.setBoolean(2, false);
+ prepStmt.addBatch();
+
+ prepStmt.executeBatch();
+
+ rs = stmt.executeQuery("select c1 from boolean_tbl;");
+ boolean[] result = new boolean[2];
+ int i = 0;
+ while (rs.next()) {
+ result[i] = Boolean.valueOf(rs.getObject(1).toString());
+ i++;
+ }
+ rs.close();
+ assertEquals("Rows one returned true", true, result[0]);
+ assertEquals("Rows two returned false", false, result[1]);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ assertNull(e.getMessage());
+ } finally {
+ stmt.close();
+ prepStmt.close();
+ conn.close();
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e32f6b9b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestLargeInt.java
----------------------------------------------------------------------
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestLargeInt.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestLargeInt.java
new file mode 100644
index 0000000..7f8222d
--- /dev/null
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestLargeInt.java
@@ -0,0 +1,131 @@
+/**
+ * @@@ 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 @@
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.junit.Test;
+
+public class TestLargeInt {
+
+ @Test
+ public void JDBCLargeIntSigned() throws SQLException {
+ Connection conn = null;
+ Statement stmt = null;
+ PreparedStatement prepStmt = null;
+ ResultSet rs = null;
+ String sql = "insert into largeint_signed_tbl values (?,?);";
+ try {
+ conn = Utils.getUserConnection();
+ stmt = conn.createStatement();
+ stmt.executeUpdate("set schema " + Utils.catalog + "." + Utils.schema);
+ stmt.executeUpdate("create table if not exists largeint_signed_tbl (c0 int not null, c1 largeint signed)");
+ stmt.executeUpdate("delete from largeint_signed_tbl");
+
+ prepStmt = conn.prepareStatement(sql);
+
+ prepStmt.setInt(1, 1);
+ prepStmt.setObject(2, Long.MIN_VALUE);
+ prepStmt.addBatch();
+
+ prepStmt.setInt(1, 2);
+ prepStmt.setObject(2, Long.MAX_VALUE);
+ prepStmt.addBatch();
+
+ prepStmt.executeBatch();
+
+ rs = stmt.executeQuery("select c1 from largeint_signed_tbl;");
+ Object[] result = new Object[2];
+ int i = 0;
+ while (rs.next()) {
+ result[i] = rs.getObject(1);
+ i++;
+ }
+ rs.close();
+ assertEquals("Rows one returned -9223372036854775808", -9223372036854775808l, result[0]);
+ assertEquals("Rows two returned 9223372036854775807", 9223372036854775807l, result[1]);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ assertNull(e.getMessage());
+ } finally {
+ stmt.close();
+ prepStmt.close();
+ conn.close();
+ }
+ }
+
+ @Test
+ public void JDBCLargeIntUnsigned() throws SQLException {
+ Connection conn = null;
+ Statement stmt = null;
+ PreparedStatement prepStmt = null;
+ ResultSet rs = null;
+ String sql = "insert into largeint_unsigned_tbl values (?,?);";
+ try {
+ conn = Utils.getUserConnection();
+ stmt = conn.createStatement();
+ stmt.executeUpdate("set schema " + Utils.catalog + "." + Utils.schema);
+ stmt.executeUpdate("create table if not exists largeint_unsigned_tbl (c0 int not null, c1 largeint unsigned)");
+ stmt.executeUpdate("delete from largeint_unsigned_tbl");
+
+ prepStmt = conn.prepareStatement(sql);
+
+ prepStmt.setInt(1, 1);
+ prepStmt.setObject(2, 0);
+ prepStmt.addBatch();
+
+ prepStmt.setInt(1, 2);
+ BigDecimal maxbd = new BigDecimal(Long.MAX_VALUE);
+ maxbd = maxbd.add(maxbd).add(BigDecimal.valueOf(1));
+ prepStmt.setObject(2, maxbd);
+ prepStmt.addBatch();
+
+ prepStmt.executeBatch();
+
+ rs = stmt.executeQuery("select c1 from largeint_unsigned_tbl;");
+ Object[] result = new Object[2];
+ int i = 0;
+ while (rs.next()) {
+ result[i] = rs.getObject(1);
+ i++;
+ }
+ rs.close();
+ assertEquals("Rows one returned 0", BigDecimal.valueOf(0), result[0]);
+ assertEquals("Rows two returned 18446744073709551615", maxbd.toString(), result[1].toString());
+ } catch (SQLException e) {
+ e.printStackTrace();
+ assertNull(e.getMessage());
+ } finally {
+ stmt.close();
+ prepStmt.close();
+ conn.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e32f6b9b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestTinyInt.java
----------------------------------------------------------------------
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestTinyInt.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestTinyInt.java
new file mode 100644
index 0000000..efbf65c
--- /dev/null
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestTinyInt.java
@@ -0,0 +1,131 @@
+/**
+ * @@@ 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 @@
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.junit.Test;
+
+public class TestTinyInt {
+
+ @Test
+ public void JDBCTinyIntSigned() throws SQLException {
+ Connection conn = null;
+ Statement stmt = null;
+ PreparedStatement prepStmt = null;
+ ResultSet rs = null;
+ String sql = "insert into tinyint_signed_tbl values (?,?);";
+ try {
+ conn = Utils.getUserConnection();
+ conn.createStatement().executeUpdate("cqd traf_tinyint_return_values 'ON'");//
+ conn.createStatement().executeUpdate("cqd traf_tinyint_input_params 'ON'");//
+ stmt = conn.createStatement();
+ stmt.executeUpdate("set schema " + Utils.catalog + "." + Utils.schema);
+ stmt.executeUpdate("create table if not exists tinyint_signed_tbl (c0 int not null, c1 tinyint signed)");
+ stmt.executeUpdate("delete from tinyint_signed_tbl");
+
+ prepStmt = conn.prepareStatement(sql);
+
+ prepStmt.setInt(1, 1);
+ prepStmt.setObject(2, -128);
+ prepStmt.addBatch();
+
+ prepStmt.setInt(1, 2);
+ prepStmt.setObject(2, 127);
+ prepStmt.addBatch();
+
+ prepStmt.executeBatch();
+
+ rs = stmt.executeQuery("select c1 from tinyint_signed_tbl;");
+ Object[] result = new Object[2];
+ int i = 0;
+ while (rs.next()) {
+ result[i] = Integer.valueOf(rs.getObject(1).toString());
+ i++;
+ }
+ rs.close();
+ assertEquals("Rows one returned -128", -128, result[0]);
+ assertEquals("Rows two returned 127", 127, result[1]);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ assertNull(e.getMessage());
+ } finally {
+ stmt.close();
+ prepStmt.close();
+ conn.close();
+ }
+ }
+
+ @Test
+ public void JDBCTinyIntUnsigned() throws SQLException {
+ Connection conn = null;
+ Statement stmt = null;
+ PreparedStatement prepStmt = null;
+ ResultSet rs = null;
+ String sql = "insert into tinyint_unsigned_tbl values (?,?);";
+ try {
+ conn = Utils.getUserConnection();
+ stmt = conn.createStatement();
+ stmt.executeUpdate("set schema " + Utils.catalog + "." + Utils.schema);
+ stmt.executeUpdate("create table if not exists tinyint_unsigned_tbl (c0 int not null, c1 tinyint unsigned)");
+ stmt.executeUpdate("delete from tinyint_unsigned_tbl");
+
+ prepStmt = conn.prepareStatement(sql);
+
+ prepStmt.setInt(1, 1);
+ prepStmt.setObject(2, 0);
+ prepStmt.addBatch();
+
+ prepStmt.setInt(1, 2);
+ prepStmt.setObject(2, 255);
+ prepStmt.addBatch();
+
+ prepStmt.executeBatch();
+
+ rs = stmt.executeQuery("select c1 from tinyint_unsigned_tbl;");
+ Object[] result = new Object[2];
+ int i = 0;
+ while (rs.next()) {
+ result[i] = rs.getObject(1);
+ i++;
+ }
+ rs.close();
+ assertEquals("Rows one returned 0", 0, result[0]);
+ assertEquals("Rows two returned 255", 255, result[1]);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ assertNull(e.getMessage());
+ } finally {
+ stmt.close();
+ prepStmt.close();
+ conn.close();
+ }
+ }
+}
[3/3] incubator-trafodion git commit: Merge [TRAFODION-2385] PR 1098
JDBCT4 boolean, tinyint, largeint uns support
Posted by db...@apache.org.
Merge [TRAFODION-2385] PR 1098 JDBCT4 boolean, tinyint, largeint uns support
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/8fe0d62a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/8fe0d62a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/8fe0d62a
Branch: refs/heads/master
Commit: 8fe0d62ad0498f43655402db9562cecea5855724
Parents: 22b739e fee5a94
Author: Dave Birdsall <db...@apache.org>
Authored: Tue May 30 16:34:19 2017 +0000
Committer: Dave Birdsall <db...@apache.org>
Committed: Tue May 30 16:34:19 2017 +0000
----------------------------------------------------------------------
.../main/java/org/trafodion/jdbc/t4/Bytes.java | 5 +
.../trafodion/jdbc/t4/InterfaceStatement.java | 21 ++-
.../jdbc/t4/TrafT4PreparedStatement.java | 61 +++++++--
.../org/trafodion/jdbc/t4/TrafT4ResultSet.java | 35 ++++-
.../java/org/trafodion/jdbc/t4/Utility.java | 11 +-
.../org/trafodion/jdbc_test/TestBoolean.java | 85 ++++++++++++
.../org/trafodion/jdbc_test/TestLargeInt.java | 131 +++++++++++++++++++
.../org/trafodion/jdbc_test/TestTinyInt.java | 131 +++++++++++++++++++
8 files changed, 458 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
[2/3] incubator-trafodion git commit: change insert short to byte
when boolean
Posted by db...@apache.org.
change insert short to byte when boolean
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/fee5a941
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/fee5a941
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/fee5a941
Branch: refs/heads/master
Commit: fee5a941bb486a3b500666e9de040fb5a3b541e6
Parents: e32f6b9
Author: mashengchen <ma...@gmail.com>
Authored: Thu May 25 06:30:52 2017 +0000
Committer: mashengchen <ma...@gmail.com>
Committed: Thu May 25 06:30:52 2017 +0000
----------------------------------------------------------------------
.../src/main/java/org/trafodion/jdbc/t4/Bytes.java | 5 +++++
.../org/trafodion/jdbc/t4/InterfaceStatement.java | 2 +-
.../trafodion/jdbc/t4/TrafT4PreparedStatement.java | 17 ++++++++++++++---
.../org/trafodion/jdbc/t4/TrafT4ResultSet.java | 3 +++
4 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fee5a941/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Bytes.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Bytes.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Bytes.java
index 625bdff..a289bb3 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Bytes.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/Bytes.java
@@ -122,6 +122,11 @@ class Bytes {
return value;
}
+ static int insertByte(byte[] array, int offset, byte value) {
+ array[offset] = value;
+ return offset + 1;
+ }
+
static int insertShort(byte[] array, int offset, short value, boolean swap) {
if (swap) {
array[offset + 1] = (byte) ((value >>> 8) & 0xff);
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fee5a941/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 120f084..6ee93bf 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
@@ -686,7 +686,7 @@ class InterfaceStatement {
case InterfaceResultSet.SQLTYPECODE_BOOLEAN:
tmpbd = Utility.getBigDecimalValue(locale, paramValue);
- Bytes.insertShort(values, noNullValue, tmpbd.shortValue(), this.ic_.getByteSwap());
+ Bytes.insertByte(values, noNullValue, tmpbd.byteValue());
break;
// You will not get this type, since server internally converts it
// SMALLINT, INTERGER or LARGEINT
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fee5a941/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
index 04fa6aa..66323dc 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4PreparedStatement.java
@@ -720,11 +720,22 @@ public class TrafT4PreparedStatement extends TrafT4Statement implements java.sql
}
validateSetInvocation(parameterIndex);
inputDesc_[parameterIndex - 1].checkValidNumericConversion(connection_.getLocale());
- if (x) {
- addParamValue(parameterIndex, "1"); // true
+ int sqltype = inputDesc_[parameterIndex - 1].sqlDataType_;
+ Object valueObj = null;
+ if (sqltype == InterfaceResultSet.SQLTYPECODE_BOOLEAN) {
+ if (x) {
+ valueObj = 1;
+ } else {
+ valueObj = 0;
+ }
} else {
- addParamValue(parameterIndex, "0"); // false
+ if (x) {
+ valueObj = "1";
+ } else {
+ valueObj = "0";
+ }
}
+ addParamValue(parameterIndex, valueObj);
}
public void setByte(int parameterIndex, byte x) throws SQLException {
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fee5a941/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
index a3d1826..e5864c9 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4ResultSet.java
@@ -1832,6 +1832,9 @@ public class TrafT4ResultSet extends TrafT4Handle implements java.sql.ResultSet
case Types.CHAR:
+ if (sqltype == InterfaceResultSet.SQLTYPECODE_BOOLEAN) {
+ return String.valueOf(getBoolean(columnIndex));
+ }
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.BLOB: