Unverified 提交 6be41dec authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1311 from katzyn/misc

Fix minor issues with ResultSet.getObject(..., Class) and WITH TIES
......@@ -703,7 +703,8 @@ public abstract class Query extends Prepared {
if (offsetExpr != null) {
buff.append("\nOFFSET ").append(StringUtils.unEnclose(offsetExpr.getSQL())).append(" ROWS");
}
buff.append("\nFETCH NEXT ").append(StringUtils.unEnclose(limitExpr.getSQL())).append(" ROWS WITH TIES");
buff.append("\nFETCH NEXT ").append(StringUtils.unEnclose(limitExpr.getSQL()))
.append(" ROWS WITH TIES");
} else {
buff.append("\nLIMIT ").append(StringUtils.unEnclose(limitExpr.getSQL()));
if (offsetExpr != null) {
......
......@@ -3928,9 +3928,9 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
return type.cast(value == ValueNull.INSTANCE
? null : new JdbcSQLXML(conn, value, JdbcLob.State.WITH_VALUE, id));
} else if (type == TimestampWithTimeZone.class) {
return type.cast(value.getObject());
return type.cast(value.convertTo(Value.TIMESTAMP_TZ).getObject());
} else if (DataType.isGeometryClass(type)) {
return type.cast(value.getObject());
return type.cast(value.convertTo(Value.GEOMETRY).getObject());
} else if (type == LocalDateTimeUtils.LOCAL_DATE) {
return type.cast(LocalDateTimeUtils.valueToLocalDate(value));
} else if (type == LocalDateTimeUtils.LOCAL_TIME) {
......
......@@ -405,15 +405,8 @@ public class LocalResult implements ResultInterface, ResultTarget {
}
int to = offset + limit;
if (withTies && sort != null) {
int[] indexes = sort.getQueryColumnIndexes();
Value[] expected = rows.get(to - 1);
loop: while (to < rows.size()) {
Value[] current = rows.get(to);
for (int idx : indexes) {
if (!expected[idx].equals(current[idx])) {
break loop;
}
}
while (to < rows.size() && sort.compare(expected, rows.get(to)) == 0) {
to++;
rowCount++;
}
......@@ -446,14 +439,8 @@ public class LocalResult implements ResultInterface, ResultTarget {
}
}
if (withTies && sort != null && row != null) {
int[] indexes = sort.getQueryColumnIndexes();
Value[] expected = row;
loop: while ((row = temp.next()) != null) {
for (int idx : indexes) {
if (!expected[idx].equals(row[idx])) {
break loop;
}
}
while ((row = temp.next()) != null && sort.compare(expected, row) == 0) {
rows.add(row);
rowCount++;
if (rows.size() > maxMemoryRows) {
......
......@@ -149,6 +149,13 @@ public class TestSpatial extends TestDb {
new Coordinate(2, 2),
new Coordinate(1, 1) });
assertTrue(polygon.equals(rs.getObject(2)));
rs.close();
rs = stat.executeQuery("select id, cast(polygon as varchar) from test");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals("POLYGON ((1 1, 1 2, 2 2, 1 1))", rs.getObject(2));
assertTrue(polygon.equals(rs.getObject(2, Geometry.class)));
rs.close();
rs = stat.executeQuery("select * from test where polygon = " +
"'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
......
......@@ -131,3 +131,20 @@ EXPLAIN SELECT * FROM TEST ORDER BY A, B OFFSET 3 ROWS FETCH NEXT 1 ROW WITH TIE
DROP TABLE TEST;
> ok
CREATE TABLE TEST(A NUMERIC, B NUMERIC);
> ok
INSERT INTO TEST VALUES (0, 1), (0.0, 2), (0, 3), (1, 4);
> update count: 4
SELECT A, B FROM TEST ORDER BY A FETCH FIRST 1 ROW WITH TIES;
> A B
> --- -
> 0 1
> 0 3
> 0.0 2
> rows: 3
DROP TABLE TEST;
> ok
......@@ -69,7 +69,8 @@ public class TestTimeStampWithTimeZone extends TestDb {
assertEquals(1, ts.getMonth());
assertEquals(1, ts.getDay());
assertEquals(15, ts.getTimeZoneOffsetMins());
assertEquals(new TimestampWithTimeZone(1008673L, 43200000000000L, (short) 15), ts);
TimestampWithTimeZone firstExpected = new TimestampWithTimeZone(1008673L, 43200000000000L, (short) 15);
assertEquals(firstExpected, ts);
if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("1970-01-01T12:00+00:15", rs.getObject(1,
LocalDateTimeUtils.OFFSET_DATE_TIME).toString());
......@@ -125,6 +126,11 @@ public class TestTimeStampWithTimeZone extends TestDb {
assertEquals(2014, columnType);
rs.close();
rs = stat.executeQuery("select cast(t1 as varchar) from test");
assertTrue(rs.next());
assertEquals(firstExpected, rs.getObject(1, TimestampWithTimeZone.class));
stat.close();
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论