Fix issue with cast exception from sql_variant (#1320)
Showing 2 of 3 files from the diff.
Other files ignored by Codecov
@@ -3922,41 +3922,32 @@
Loading
3922 | 3922 | TDSType baseType = TDSType.valueOf(intbaseType); |
|
3923 | 3923 | switch (baseType) { |
|
3924 | 3924 | case INT8: |
|
3925 | - | jdbcType = JDBCType.BIGINT; |
|
3926 | 3925 | convertedValue = DDC.convertLongToObject(tdsReader.readLong(), jdbcType, baseSSType, |
|
3927 | 3926 | streamGetterArgs.streamType); |
|
3928 | 3927 | break; |
|
3929 | 3928 | ||
3930 | 3929 | case INT4: |
|
3931 | - | jdbcType = JDBCType.INTEGER; |
|
3932 | 3930 | convertedValue = DDC.convertIntegerToObject(tdsReader.readInt(), valueLength, jdbcType, |
|
3933 | 3931 | streamGetterArgs.streamType); |
|
3934 | 3932 | break; |
|
3935 | 3933 | ||
3936 | 3934 | case INT2: |
|
3937 | - | jdbcType = JDBCType.SMALLINT; |
|
3938 | 3935 | convertedValue = DDC.convertIntegerToObject(tdsReader.readShort(), valueLength, jdbcType, |
|
3939 | 3936 | streamGetterArgs.streamType); |
|
3940 | 3937 | break; |
|
3941 | 3938 | ||
3942 | 3939 | case INT1: |
|
3943 | - | jdbcType = JDBCType.TINYINT; |
|
3944 | 3940 | convertedValue = DDC.convertIntegerToObject(tdsReader.readUnsignedByte(), valueLength, jdbcType, |
|
3945 | 3941 | streamGetterArgs.streamType); |
|
3946 | 3942 | break; |
|
3947 | 3943 | ||
3948 | 3944 | case DECIMALN: |
|
3949 | 3945 | case NUMERICN: |
|
3950 | - | if (TDSType.DECIMALN == baseType) |
|
3951 | - | jdbcType = JDBCType.DECIMAL; |
|
3952 | - | else if (TDSType.NUMERICN == baseType) |
|
3953 | - | jdbcType = JDBCType.NUMERIC; |
|
3954 | 3946 | if (cbPropsActual != sqlVariantProbBytes.DECIMALN.getIntValue()) { // Numeric and decimal have the same |
|
3955 | 3947 | // probbytes value |
|
3956 | 3948 | MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidProbbytes")); |
|
3957 | 3949 | throw new SQLServerException(form.format(new Object[] {baseType}), null, 0, null); |
|
3958 | 3950 | } |
|
3959 | - | jdbcType = JDBCType.DECIMAL; |
|
3960 | 3951 | precision = tdsReader.readUnsignedByte(); |
|
3961 | 3952 | scale = tdsReader.readUnsignedByte(); |
|
3962 | 3953 | typeInfo.setScale(scale); // typeInfo needs to be updated. typeInfo is usually set when reading |
@@ -3969,17 +3960,14 @@
Loading
3969 | 3960 | break; |
|
3970 | 3961 | ||
3971 | 3962 | case FLOAT4: |
|
3972 | - | jdbcType = JDBCType.REAL; |
|
3973 | 3963 | convertedValue = tdsReader.readReal(expectedValueLength, jdbcType, streamGetterArgs.streamType); |
|
3974 | 3964 | break; |
|
3975 | 3965 | ||
3976 | 3966 | case FLOAT8: |
|
3977 | - | jdbcType = JDBCType.FLOAT; |
|
3978 | 3967 | convertedValue = tdsReader.readFloat(expectedValueLength, jdbcType, streamGetterArgs.streamType); |
|
3979 | 3968 | break; |
|
3980 | 3969 | ||
3981 | 3970 | case MONEY4: |
|
3982 | - | jdbcType = JDBCType.SMALLMONEY; |
|
3983 | 3971 | precision = Long.toString(Long.MAX_VALUE).length(); |
|
3984 | 3972 | typeInfo.setPrecision(precision); |
|
3985 | 3973 | scale = 4; |
@@ -3991,7 +3979,6 @@
Loading
3991 | 3979 | break; |
|
3992 | 3980 | ||
3993 | 3981 | case MONEY8: |
|
3994 | - | jdbcType = JDBCType.MONEY; |
|
3995 | 3982 | precision = Long.toString(Long.MAX_VALUE).length(); |
|
3996 | 3983 | scale = 4; |
|
3997 | 3984 | typeInfo.setPrecision(precision); |
@@ -4004,32 +3991,8 @@
Loading
4004 | 3991 | ||
4005 | 3992 | case BIT1: |
|
4006 | 3993 | case BITN: |
|
4007 | - | jdbcType = JDBCType.BIT; |
|
4008 | - | switch (expectedValueLength) { |
|
4009 | - | case 8: |
|
4010 | - | convertedValue = DDC.convertLongToObject(tdsReader.readLong(), jdbcType, baseSSType, |
|
4011 | - | streamGetterArgs.streamType); |
|
4012 | - | break; |
|
4013 | - | ||
4014 | - | case 4: |
|
4015 | - | convertedValue = DDC.convertIntegerToObject(tdsReader.readInt(), expectedValueLength, jdbcType, |
|
4016 | - | streamGetterArgs.streamType); |
|
4017 | - | break; |
|
4018 | - | ||
4019 | - | case 2: |
|
4020 | - | convertedValue = DDC.convertIntegerToObject(tdsReader.readShort(), expectedValueLength, |
|
4021 | - | jdbcType, streamGetterArgs.streamType); |
|
4022 | - | break; |
|
4023 | - | ||
4024 | - | case 1: |
|
4025 | - | convertedValue = DDC.convertIntegerToObject(tdsReader.readUnsignedByte(), expectedValueLength, |
|
4026 | - | jdbcType, streamGetterArgs.streamType); |
|
4027 | - | break; |
|
4028 | - | ||
4029 | - | default: |
|
4030 | - | assert false : "Unexpected valueLength" + expectedValueLength; |
|
4031 | - | break; |
|
4032 | - | } |
|
3994 | + | convertedValue = DDC.convertIntegerToObject(tdsReader.readUnsignedByte(), expectedValueLength, |
|
3995 | + | jdbcType, streamGetterArgs.streamType); |
|
4033 | 3996 | break; |
|
4034 | 3997 | ||
4035 | 3998 | case BIGVARCHAR: |
@@ -4038,10 +4001,6 @@
Loading
4038 | 4001 | MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidProbbytes")); |
|
4039 | 4002 | throw new SQLServerException(form.format(new Object[] {baseType}), null, 0, null); |
|
4040 | 4003 | } |
|
4041 | - | if (TDSType.BIGVARCHAR == baseType) |
|
4042 | - | jdbcType = JDBCType.VARCHAR; |
|
4043 | - | else if (TDSType.BIGCHAR == baseType) |
|
4044 | - | jdbcType = JDBCType.CHAR; |
|
4045 | 4004 | collation = tdsReader.readCollation(); |
|
4046 | 4005 | typeInfo.setSQLCollation(collation); |
|
4047 | 4006 | maxLength = tdsReader.readUnsignedShort(); |
@@ -4063,10 +4022,6 @@
Loading
4063 | 4022 | MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidProbbytes")); |
|
4064 | 4023 | throw new SQLServerException(form.format(new Object[] {baseType}), null, 0, null); |
|
4065 | 4024 | } |
|
4066 | - | if (TDSType.NCHAR == baseType) |
|
4067 | - | jdbcType = JDBCType.NCHAR; |
|
4068 | - | else if (TDSType.NVARCHAR == baseType) |
|
4069 | - | jdbcType = JDBCType.NVARCHAR; |
|
4070 | 4025 | collation = tdsReader.readCollation(); |
|
4071 | 4026 | typeInfo.setSQLCollation(collation); |
|
4072 | 4027 | maxLength = tdsReader.readUnsignedShort(); |
@@ -72,6 +72,17 @@
Loading
72 | 72 | return (float) intValue; |
|
73 | 73 | case BINARY: |
|
74 | 74 | return convertIntToBytes(intValue, valueLength); |
|
75 | + | case SQL_VARIANT: |
|
76 | + | // return short or bit if the underlying datatype of sql_variant is tinyint, smallint or bit |
|
77 | + | // otherwise, return integer |
|
78 | + | // Longer datatypes such as double and float are handled by convertLongToObject instead. |
|
79 | + | if (valueLength == 1) { |
|
80 | + | return 0 != intValue; |
|
81 | + | } else if (valueLength == 3 || valueLength == 4) { |
|
82 | + | return (short) intValue; |
|
83 | + | } else { |
|
84 | + | return intValue; |
|
85 | + | } |
|
75 | 86 | default: |
|
76 | 87 | return Integer.toString(intValue); |
|
77 | 88 | } |
@@ -93,6 +104,7 @@
Loading
93 | 104 | static final Object convertLongToObject(long longVal, JDBCType jdbcType, SSType baseSSType, StreamType streamType) { |
|
94 | 105 | switch (jdbcType) { |
|
95 | 106 | case BIGINT: |
|
107 | + | case SQL_VARIANT: |
|
96 | 108 | return longVal; |
|
97 | 109 | case INTEGER: |
|
98 | 110 | return (int) longVal; |
@@ -209,6 +221,7 @@
Loading
209 | 221 | static final Object convertFloatToObject(float floatVal, JDBCType jdbcType, StreamType streamType) { |
|
210 | 222 | switch (jdbcType) { |
|
211 | 223 | case REAL: |
|
224 | + | case SQL_VARIANT: |
|
212 | 225 | return floatVal; |
|
213 | 226 | case INTEGER: |
|
214 | 227 | return (int) floatVal; |
@@ -266,6 +279,7 @@
Loading
266 | 279 | switch (jdbcType) { |
|
267 | 280 | case FLOAT: |
|
268 | 281 | case DOUBLE: |
|
282 | + | case SQL_VARIANT: |
|
269 | 283 | return doubleVal; |
|
270 | 284 | case REAL: |
|
271 | 285 | return (Double.valueOf(doubleVal)).floatValue(); |
@@ -341,6 +355,7 @@
Loading
341 | 355 | case NUMERIC: |
|
342 | 356 | case MONEY: |
|
343 | 357 | case SMALLMONEY: |
|
358 | + | case SQL_VARIANT: |
|
344 | 359 | return bigDecimalVal; |
|
345 | 360 | case FLOAT: |
|
346 | 361 | case DOUBLE: |
Files | Complexity | Coverage |
---|---|---|
src/main/java | 44.41% | 58.40% |
Project Totals (133 files) | 44.41% | 58.40% |
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.