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

Fix NULL support for primivite types in PgServer

上级 0295a962
......@@ -537,10 +537,16 @@ public class PgServerThread implements Runnable {
if (text) {
// plain text
switch (pgType) {
case PgServer.PG_TYPE_BOOL:
writeInt(1);
dataOut.writeByte(rs.getBoolean(column) ? 't' : 'f');
case PgServer.PG_TYPE_BOOL: {
boolean b = rs.getBoolean(column);
if (rs.wasNull()) {
writeInt(-1);
} else {
writeInt(1);
dataOut.writeByte(b ? 't' : 'f');
}
break;
}
default:
String s = rs.getString(column);
if (s == null) {
......@@ -554,26 +560,56 @@ public class PgServerThread implements Runnable {
} else {
// binary
switch (pgType) {
case PgServer.PG_TYPE_INT2:
writeInt(2);
writeShort(rs.getShort(column));
case PgServer.PG_TYPE_INT2: {
short s = rs.getShort(column);
if (rs.wasNull()) {
writeInt(-1);
} else {
writeInt(2);
writeShort(s);
}
break;
case PgServer.PG_TYPE_INT4:
writeInt(4);
writeInt(rs.getInt(column));
}
case PgServer.PG_TYPE_INT4: {
int i = rs.getInt(column);
if (rs.wasNull()) {
writeInt(-1);
} else {
writeInt(4);
writeInt(i);
}
break;
case PgServer.PG_TYPE_INT8:
writeInt(8);
dataOut.writeLong(rs.getLong(column));
}
case PgServer.PG_TYPE_INT8: {
long l = rs.getLong(column);
if (rs.wasNull()) {
writeInt(-1);
} else {
writeInt(8);
dataOut.writeLong(l);
}
break;
case PgServer.PG_TYPE_FLOAT4:
writeInt(4);
dataOut.writeFloat(rs.getFloat(column));
}
case PgServer.PG_TYPE_FLOAT4: {
float f = rs.getFloat(column);
if (rs.wasNull()) {
writeInt(-1);
} else {
writeInt(4);
dataOut.writeFloat(f);
}
break;
case PgServer.PG_TYPE_FLOAT8:
writeInt(8);
dataOut.writeDouble(rs.getDouble(column));
}
case PgServer.PG_TYPE_FLOAT8: {
double d = rs.getDouble(column);
if (rs.wasNull()) {
writeInt(-1);
} else {
writeInt(8);
dataOut.writeDouble(d);
}
break;
}
case PgServer.PG_TYPE_BYTEA: {
byte[] data = rs.getBytes(column);
if (data == null) {
......
......@@ -428,6 +428,10 @@ public class TestPgServer extends TestBase {
ps.setTime(12, Time.valueOf("20:11:15"));
ps.setTimestamp(13, Timestamp.valueOf("2001-10-30 14:16:10.111"));
ps.execute();
for (int i = 1; i <= 13; i++) {
ps.setNull(i, Types.NULL);
}
ps.execute();
ResultSet rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
......@@ -445,6 +449,11 @@ public class TestPgServer extends TestBase {
assertEquals(Date.valueOf("2015-01-31"), rs.getDate(11));
assertEquals(Time.valueOf("20:11:15"), rs.getTime(12));
assertEquals(Timestamp.valueOf("2001-10-30 14:16:10.111"), rs.getTimestamp(13));
assertTrue(rs.next());
for (int i = 1; i <= 13; i++) {
assertNull(rs.getObject(i));
}
assertFalse(rs.next());
conn.close();
} finally {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论