List:Commits« Previous MessageNext Message »
From:mmatthews Date:December 12 2005 7:39pm
Subject:Testing svn hook r4680 - branches/branch_3_1/connector-j/src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java
Log:
Fix for BUG#15677 - ResultSet.getShort() returns incorrect values when
column is of type TINYINT UNSIGNED and using server-side prepared statements. 

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java	2005-12-12 01:05:36
UTC (rev 4679)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java	2005-12-12 18:17:59
UTC (rev 4680)
@@ -2995,7 +2995,23 @@
 
 		switch (field.getMysqlType()) {
 		case MysqlDefs.FIELD_TYPE_TINY:
-			return (byte) ((byte[]) this.thisRow[columnIndex])[0];
+						
+			byte valueAsByte = ((byte[]) this.thisRow[columnIndex])[0];
+			
+			if (!field.isUnsigned() || valueAsByte >= 0) {
+				short valueAsShort = (short)(valueAsByte + (short)256);
+				
+				if (this.connection.getJdbcCompliantTruncation()) {
+					if (valueAsShort > Byte.MAX_VALUE) {
+						throwRangeException(String.valueOf(valueAsShort),
+								columnIndex + 1, Types.TINYINT);
+					}
+				}
+				
+				return (byte)valueAsShort;
+			}
+			
+			return valueAsByte;
 		case MysqlDefs.FIELD_TYPE_SHORT:
 		case MysqlDefs.FIELD_TYPE_YEAR:
 			int valueAsShort = getNativeShort(columnIndex + 1);
@@ -3753,17 +3769,17 @@
 
 			return (int) valueAsDouble;
 		case MysqlDefs.FIELD_TYPE_FLOAT:
-			valueAsDouble = getNativeFloat(columnIndex + 1);
+			float valueAsFloat = getNativeFloat(columnIndex + 1);
 
 			if (this.connection.getJdbcCompliantTruncation()) {
-				if (valueAsDouble < Integer.MIN_VALUE
-						|| valueAsDouble > Integer.MAX_VALUE) {
-					throwRangeException(String.valueOf(valueAsDouble),
+				if (valueAsFloat < Integer.MIN_VALUE
+						|| valueAsFloat > Integer.MAX_VALUE) {
+					throwRangeException(String.valueOf(valueAsFloat),
 							columnIndex + 1, Types.INTEGER);
 				}
 			}
 
-			return (int) valueAsDouble;
+			return (int) valueAsFloat;
 
 		default:
 
@@ -3873,17 +3889,17 @@
 
 			return (long) valueAsDouble;
 		case MysqlDefs.FIELD_TYPE_FLOAT:
-			valueAsDouble = getNativeFloat(columnIndex + 1);
+			float valueAsFloat = getNativeFloat(columnIndex + 1);
 
 			if (this.connection.getJdbcCompliantTruncation()) {
-				if (valueAsDouble < Long.MIN_VALUE
-						|| valueAsDouble > Long.MAX_VALUE) {
-					throwRangeException(String.valueOf(valueAsDouble),
+				if (valueAsFloat < Long.MIN_VALUE
+						|| valueAsFloat > Long.MAX_VALUE) {
+					throwRangeException(String.valueOf(valueAsFloat),
 							columnIndex + 1, Types.BIGINT);
 				}
 			}
 
-			return (long) valueAsDouble;
+			return (long) valueAsFloat;
 		default:
 
 			if (this.useUsageAdvisor) {

Thread
Testing svn hook r4680 - branches/branch_3_1/connector-j/src/com/mysql/jdbcmmatthews12 Dec