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