Unverified 提交 fd429df6 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #712 from katzyn/SimpleResultSet_UUID

Return properly encoded UUID from SimpleResultSet.getBytes()
...@@ -28,6 +28,8 @@ import java.sql.Types; ...@@ -28,6 +28,8 @@ import java.sql.Types;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.jdbc.JdbcResultSetBackwardsCompat; import org.h2.jdbc.JdbcResultSetBackwardsCompat;
import org.h2.message.DbException; import org.h2.message.DbException;
...@@ -35,6 +37,7 @@ import org.h2.util.JdbcUtils; ...@@ -35,6 +37,7 @@ import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.ValueUuid;
/** /**
* This class is a simple result set and meta data implementation. * This class is a simple result set and meta data implementation.
...@@ -530,6 +533,10 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData, ...@@ -530,6 +533,10 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
if (o == null || o instanceof byte[]) { if (o == null || o instanceof byte[]) {
return (byte[]) o; return (byte[]) o;
} }
if (o instanceof UUID) {
final UUID u = (UUID) o;
return ValueUuid.get(u.getMostSignificantBits(), u.getLeastSignificantBits()).getBytes();
}
return JdbcUtils.serialize(o, null); return JdbcUtils.serialize(o, null);
} }
......
...@@ -35,6 +35,8 @@ import java.sql.Types; ...@@ -35,6 +35,8 @@ import java.sql.Types;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.UUID;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
import org.h2.store.FileLister; import org.h2.store.FileLister;
...@@ -56,6 +58,7 @@ import org.h2.tools.SimpleResultSet; ...@@ -56,6 +58,7 @@ import org.h2.tools.SimpleResultSet;
import org.h2.tools.SimpleResultSet.SimpleArray; import org.h2.tools.SimpleResultSet.SimpleArray;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.Task; import org.h2.util.Task;
import org.h2.value.ValueUuid;
/** /**
* Tests the database tools. * Tests the database tools.
...@@ -457,6 +460,13 @@ public class TestTools extends TestBase { ...@@ -457,6 +460,13 @@ public class TestTools extends TestBase {
assertFalse(rs.isClosed()); assertFalse(rs.isClosed());
rs.close(); rs.close();
assertTrue(rs.isClosed()); assertTrue(rs.isClosed());
rs = new SimpleResultSet();
rs.addColumn("TEST", Types.BINARY, 0, 0);
UUID uuid = UUID.randomUUID();
rs.addRow(uuid);
rs.next();
assertEquals(uuid, rs.getObject(1));
assertEquals(uuid, ValueUuid.get(rs.getBytes(1)).getObject());
} }
private void testJdbcDriverUtils() { private void testJdbcDriverUtils() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论