Skip to content

Commit 74c74cd

Browse files
committed
Fix DB2 conversions for decimal and long integer values (#1308)
See #1303 Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent 634100d commit 74c74cd

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

vertx-db2-client/src/main/java/io/vertx/db2client/impl/drda/ClientTypes.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.time.LocalDate;
2323
import java.time.LocalDateTime;
2424
import java.time.LocalTime;
25-
import java.util.Arrays;
2625
import java.util.UUID;
2726

2827
import io.netty.buffer.ByteBuf;
@@ -287,7 +286,14 @@ public static boolean canConvert(Object value, int toType) {
287286
clazz == Double.class ||
288287
clazz == float.class ||
289288
clazz == Float.class ||
290-
clazz == BigDecimal.class;
289+
clazz == int.class ||
290+
clazz == Integer.class ||
291+
clazz == long.class ||
292+
clazz == Long.class ||
293+
clazz == short.class ||
294+
clazz == Short.class ||
295+
clazz == BigDecimal.class ||
296+
clazz == BigInteger.class;
291297
case ClientTypes.BIT:
292298
case ClientTypes.BOOLEAN:
293299
case ClientTypes.SMALLINT:

vertx-db2-client/src/main/java/io/vertx/db2client/impl/drda/DRDAQueryRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public DRDAQueryRequest(ByteBuf buffer, ConnectionMetaData metadata) {
5959
public static boolean isQuery(String sql) {
6060
if (sql != null) {
6161
String trimmedLower = sql.trim().toLowerCase();
62-
62+
6363
//Remove any comments at the start
64-
while (trimmedLower.startsWith("/*")) {
64+
while (trimmedLower.startsWith("/*")) {
6565
int count = 1;
6666
int position = trimmedLower.indexOf("/*")+2;
6767
while (count != 0) {
@@ -76,7 +76,7 @@ else if ((trimmedLower.indexOf("*/",position) > 0 && trimmedLower.indexOf("/*",p
7676
}
7777
else { //Only possible if there are no more /* or */ in which case the whole string is a comment
7878
throw new IllegalArgumentException("SQLState.NO_TOKENS_IN_SQL_TEXT");
79-
}
79+
}
8080
}
8181
trimmedLower = trimmedLower.substring(position).trim();
8282
}
@@ -787,7 +787,7 @@ private void buildFDODTA(int[][] protocolTypesAndLengths, Object[] inputs) {
787787
}
788788
break;
789789
case DRDAConstants.DRDA_TYPE_NINTEGER8:
790-
buffer.writeLong(((Long) inputs[i]).longValue());
790+
buffer.writeLong(((Number) inputs[i]).longValue());
791791
break;
792792
case DRDAConstants.DRDA_TYPE_NROWID:
793793
RowId rowId = (RowId) inputs[i];
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.vertx.db2client;
2+
3+
import io.vertx.ext.unit.TestContext;
4+
import io.vertx.ext.unit.junit.VertxUnitRunner;
5+
import io.vertx.sqlclient.Row;
6+
import io.vertx.sqlclient.Tuple;
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
@RunWith(VertxUnitRunner.class)
11+
public class DB2QueriesTest extends DB2TestBase {
12+
13+
@Test
14+
public void testRowNumber(TestContext ctx) {
15+
connect(ctx.asyncAssertSuccess(conn -> {
16+
conn.preparedQuery("SELECT * FROM (" +
17+
"SELECT id, message, row_number() OVER (ORDER BY id) rn FROM immutable" +
18+
") r_0_ WHERE r_0_.rn <= ? + ? AND r_0_.rn > ? ORDER BY r_0_.rn").execute(Tuple.of(1, 1, 1))
19+
.onComplete(ctx.asyncAssertSuccess(rows -> {
20+
ctx.assertEquals(1, rows.size());
21+
ctx.assertEquals(2, rows.iterator().next().getInteger("rn"));
22+
conn.close();
23+
}));
24+
}));
25+
}
26+
}

0 commit comments

Comments
 (0)