提交 e93d2685 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Send row value as ARRAY and INTERVAL as VARCHAR to old clients

上级 76e61e71
...@@ -322,27 +322,32 @@ public class Transfer { ...@@ -322,27 +322,32 @@ public class Transfer {
*/ */
public void writeValue(Value v) throws IOException { public void writeValue(Value v) throws IOException {
int type = v.getType(); int type = v.getType();
writeInt(type);
switch (type) { switch (type) {
case Value.NULL: case Value.NULL:
writeInt(Value.NULL);
break; break;
case Value.BYTES: case Value.BYTES:
case Value.JAVA_OBJECT: case Value.JAVA_OBJECT:
writeInt(type);
writeBytes(v.getBytesNoCopy()); writeBytes(v.getBytesNoCopy());
break; break;
case Value.UUID: { case Value.UUID: {
writeInt(Value.UUID);
ValueUuid uuid = (ValueUuid) v; ValueUuid uuid = (ValueUuid) v;
writeLong(uuid.getHigh()); writeLong(uuid.getHigh());
writeLong(uuid.getLow()); writeLong(uuid.getLow());
break; break;
} }
case Value.BOOLEAN: case Value.BOOLEAN:
writeInt(Value.BOOLEAN);
writeBoolean(v.getBoolean()); writeBoolean(v.getBoolean());
break; break;
case Value.BYTE: case Value.BYTE:
writeInt(Value.BYTE);
writeByte(v.getByte()); writeByte(v.getByte());
break; break;
case Value.TIME: case Value.TIME:
writeInt(Value.TIME);
if (version >= Constants.TCP_PROTOCOL_VERSION_9) { if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
writeLong(((ValueTime) v).getNanos()); writeLong(((ValueTime) v).getNanos());
} else { } else {
...@@ -350,6 +355,7 @@ public class Transfer { ...@@ -350,6 +355,7 @@ public class Transfer {
} }
break; break;
case Value.DATE: case Value.DATE:
writeInt(Value.DATE);
if (version >= Constants.TCP_PROTOCOL_VERSION_9) { if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
writeLong(((ValueDate) v).getDateValue()); writeLong(((ValueDate) v).getDateValue());
} else { } else {
...@@ -357,6 +363,7 @@ public class Transfer { ...@@ -357,6 +363,7 @@ public class Transfer {
} }
break; break;
case Value.TIMESTAMP: { case Value.TIMESTAMP: {
writeInt(Value.TIMESTAMP);
if (version >= Constants.TCP_PROTOCOL_VERSION_9) { if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
ValueTimestamp ts = (ValueTimestamp) v; ValueTimestamp ts = (ValueTimestamp) v;
writeLong(ts.getDateValue()); writeLong(ts.getDateValue());
...@@ -369,6 +376,7 @@ public class Transfer { ...@@ -369,6 +376,7 @@ public class Transfer {
break; break;
} }
case Value.TIMESTAMP_TZ: { case Value.TIMESTAMP_TZ: {
writeInt(Value.TIMESTAMP_TZ);
ValueTimestampTimeZone ts = (ValueTimestampTimeZone) v; ValueTimestampTimeZone ts = (ValueTimestampTimeZone) v;
writeLong(ts.getDateValue()); writeLong(ts.getDateValue());
writeLong(ts.getTimeNanos()); writeLong(ts.getTimeNanos());
...@@ -376,29 +384,37 @@ public class Transfer { ...@@ -376,29 +384,37 @@ public class Transfer {
break; break;
} }
case Value.DECIMAL: case Value.DECIMAL:
writeInt(Value.DECIMAL);
writeString(v.getString()); writeString(v.getString());
break; break;
case Value.DOUBLE: case Value.DOUBLE:
writeInt(Value.DOUBLE);
writeDouble(v.getDouble()); writeDouble(v.getDouble());
break; break;
case Value.FLOAT: case Value.FLOAT:
writeInt(Value.FLOAT);
writeFloat(v.getFloat()); writeFloat(v.getFloat());
break; break;
case Value.INT: case Value.INT:
writeInt(Value.INT);
writeInt(v.getInt()); writeInt(v.getInt());
break; break;
case Value.LONG: case Value.LONG:
writeInt(Value.LONG);
writeLong(v.getLong()); writeLong(v.getLong());
break; break;
case Value.SHORT: case Value.SHORT:
writeInt(Value.SHORT);
writeInt(v.getShort()); writeInt(v.getShort());
break; break;
case Value.STRING: case Value.STRING:
case Value.STRING_IGNORECASE: case Value.STRING_IGNORECASE:
case Value.STRING_FIXED: case Value.STRING_FIXED:
writeInt(type);
writeString(v.getString()); writeString(v.getString());
break; break;
case Value.BLOB: { case Value.BLOB: {
writeInt(Value.BLOB);
if (version >= Constants.TCP_PROTOCOL_VERSION_11) { if (version >= Constants.TCP_PROTOCOL_VERSION_11) {
if (v instanceof ValueLobDb) { if (v instanceof ValueLobDb) {
ValueLobDb lob = (ValueLobDb) v; ValueLobDb lob = (ValueLobDb) v;
...@@ -429,6 +445,7 @@ public class Transfer { ...@@ -429,6 +445,7 @@ public class Transfer {
break; break;
} }
case Value.CLOB: { case Value.CLOB: {
writeInt(Value.CLOB);
if (version >= Constants.TCP_PROTOCOL_VERSION_11) { if (version >= Constants.TCP_PROTOCOL_VERSION_11) {
if (v instanceof ValueLobDb) { if (v instanceof ValueLobDb) {
ValueLobDb lob = (ValueLobDb) v; ValueLobDb lob = (ValueLobDb) v;
...@@ -456,6 +473,7 @@ public class Transfer { ...@@ -456,6 +473,7 @@ public class Transfer {
break; break;
} }
case Value.ARRAY: { case Value.ARRAY: {
writeInt(Value.ARRAY);
ValueArray va = (ValueArray) v; ValueArray va = (ValueArray) v;
Value[] list = va.getList(); Value[] list = va.getList();
int len = list.length; int len = list.length;
...@@ -472,6 +490,7 @@ public class Transfer { ...@@ -472,6 +490,7 @@ public class Transfer {
break; break;
} }
case Value.ROW: { case Value.ROW: {
writeInt(version >= Constants.TCP_PROTOCOL_VERSION_18 ? Value.ROW : Value.ARRAY);
ValueRow va = (ValueRow) v; ValueRow va = (ValueRow) v;
Value[] list = va.getList(); Value[] list = va.getList();
int len = list.length; int len = list.length;
...@@ -482,11 +501,13 @@ public class Transfer { ...@@ -482,11 +501,13 @@ public class Transfer {
break; break;
} }
case Value.ENUM: { case Value.ENUM: {
writeInt(Value.ENUM);
writeInt(v.getInt()); writeInt(v.getInt());
writeString(v.getString()); writeString(v.getString());
break; break;
} }
case Value.RESULT_SET: { case Value.RESULT_SET: {
writeInt(Value.RESULT_SET);
ResultInterface result = ((ValueResultSet) v).getResult(); ResultInterface result = ((ValueResultSet) v).getResult();
int columnCount = result.getVisibleColumnCount(); int columnCount = result.getVisibleColumnCount();
writeInt(columnCount); writeInt(columnCount);
...@@ -516,6 +537,7 @@ public class Transfer { ...@@ -516,6 +537,7 @@ public class Transfer {
break; break;
} }
case Value.GEOMETRY: case Value.GEOMETRY:
writeInt(Value.GEOMETRY);
if (version >= Constants.TCP_PROTOCOL_VERSION_14) { if (version >= Constants.TCP_PROTOCOL_VERSION_14) {
writeBytes(v.getBytesNoCopy()); writeBytes(v.getBytesNoCopy());
} else { } else {
...@@ -526,12 +548,17 @@ public class Transfer { ...@@ -526,12 +548,17 @@ public class Transfer {
case Value.INTERVAL_MONTH: case Value.INTERVAL_MONTH:
case Value.INTERVAL_DAY: case Value.INTERVAL_DAY:
case Value.INTERVAL_HOUR: case Value.INTERVAL_HOUR:
case Value.INTERVAL_MINUTE: { case Value.INTERVAL_MINUTE:
if (version >= Constants.TCP_PROTOCOL_VERSION_18) {
writeInt(type);
ValueInterval interval = (ValueInterval) v; ValueInterval interval = (ValueInterval) v;
writeBoolean(interval.isNegative()); writeBoolean(interval.isNegative());
writeLong(interval.getLeading()); writeLong(interval.getLeading());
break; } else {
writeInt(Value.STRING);
writeString(v.getString());
} }
break;
case Value.INTERVAL_SECOND: case Value.INTERVAL_SECOND:
case Value.INTERVAL_YEAR_TO_MONTH: case Value.INTERVAL_YEAR_TO_MONTH:
case Value.INTERVAL_DAY_TO_HOUR: case Value.INTERVAL_DAY_TO_HOUR:
...@@ -539,15 +566,21 @@ public class Transfer { ...@@ -539,15 +566,21 @@ public class Transfer {
case Value.INTERVAL_DAY_TO_SECOND: case Value.INTERVAL_DAY_TO_SECOND:
case Value.INTERVAL_HOUR_TO_MINUTE: case Value.INTERVAL_HOUR_TO_MINUTE:
case Value.INTERVAL_HOUR_TO_SECOND: case Value.INTERVAL_HOUR_TO_SECOND:
case Value.INTERVAL_MINUTE_TO_SECOND: { case Value.INTERVAL_MINUTE_TO_SECOND:
if (version >= Constants.TCP_PROTOCOL_VERSION_18) {
writeInt(type);
ValueInterval interval = (ValueInterval) v; ValueInterval interval = (ValueInterval) v;
writeBoolean(interval.isNegative()); writeBoolean(interval.isNegative());
writeLong(interval.getLeading()); writeLong(interval.getLeading());
writeLong(interval.getRemaining()); writeLong(interval.getRemaining());
break; } else {
writeInt(Value.STRING);
writeString(v.getString());
} }
break;
default: default:
if (JdbcUtils.customDataTypesHandler != null) { if (JdbcUtils.customDataTypesHandler != null) {
writeInt(type);
writeBytes(v.getBytesNoCopy()); writeBytes(v.getBytesNoCopy());
break; break;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论