Skip to content

Commit 491505e

Browse files
committed
Partial support of SSVARIANTTYPE (#1314)
Fixes #1312 Partial implementation of SSVARIANTTYPE decoding, just enough to support querying metadata about integer MSSQL sequences. Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent ddfd0a8 commit 491505e

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/DataType.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,30 @@ public Object decodeValue(ByteBuf byteBuf, TypeInfo typeInfo) {
968968
return result;
969969
}
970970
},
971-
SSVARIANT(0x62);
971+
SSVARIANT(0x62) {
972+
@Override
973+
public TypeInfo decodeTypeInfo(ByteBuf byteBuf) {
974+
byteBuf.skipBytes(4);
975+
return new TypeInfo().maxLength(8009);
976+
}
977+
978+
@Override
979+
public Object decodeValue(ByteBuf byteBuf, TypeInfo typeInfo) {
980+
int length = byteBuf.readIntLE();
981+
if (length == 0) return null;
982+
DataType actualType = DataType.forId(byteBuf.readUnsignedByte());
983+
switch (actualType) {
984+
case INT1:
985+
case INT2:
986+
case INT4:
987+
case INT8:
988+
byteBuf.skipBytes(1); // prop bytes
989+
return actualType.decodeValue(byteBuf, null);
990+
default:
991+
throw new UnsupportedOperationException("Unsupported variant type: " + actualType);
992+
}
993+
}
994+
};
972995

973996
public final int id;
974997

vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
package io.vertx.mssqlclient;
1313

14+
import io.vertx.core.CompositeFuture;
15+
import io.vertx.core.Future;
1416
import io.vertx.core.Vertx;
1517
import io.vertx.ext.unit.Async;
1618
import io.vertx.ext.unit.TestContext;
@@ -30,8 +32,10 @@
3032
import java.time.LocalDateTime;
3133
import java.time.temporal.ChronoUnit;
3234
import java.util.ArrayList;
35+
import java.util.Arrays;
3336
import java.util.Collections;
3437
import java.util.List;
38+
import java.util.stream.Stream;
3539

3640
import static org.hamcrest.CoreMatchers.instanceOf;
3741
import static org.hamcrest.CoreMatchers.is;
@@ -178,4 +182,25 @@ public void testExecuteStoredProcedure(TestContext ctx) {
178182
});
179183
}));
180184
}
185+
186+
@Test
187+
public void testQuerySequences(TestContext ctx) {
188+
Future[] futures = Stream.of("tinyint", "smallint", "int", "bigint")
189+
.flatMap(type -> Stream.of(
190+
String.format("DROP SEQUENCE IF EXISTS seq_%s", type),
191+
String.format("CREATE SEQUENCE seq_%s AS %s", type, type)
192+
))
193+
.map(sql -> connection.query(sql).execute())
194+
.toArray(Future[]::new);
195+
CompositeFuture.all(Arrays.asList(futures)).onComplete(ctx.asyncAssertSuccess(cf -> {
196+
connection
197+
.query("SELECT * FROM INFORMATION_SCHEMA.SEQUENCES WHERE SEQUENCE_NAME LIKE 'seq_%'")
198+
.execute()
199+
.onComplete(ctx.asyncAssertSuccess(rows -> {
200+
for (Row row : rows) {
201+
ctx.assertEquals(row.getString("SEQUENCE_NAME"), "seq_" + row.getString("DECLARED_DATA_TYPE"));
202+
}
203+
}));
204+
}));
205+
}
181206
}

vertx-mssql-client/src/test/resources/init.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,6 @@ VALUES (1, 32767, 2147483647, 9223372036854775807, 123.456, 1.234567, 'HELLO,WOR
307307
INSERT INTO collector_test
308308
VALUES (2, 32767, 2147483647, 9223372036854775807, 123.456, 1.234567, 'hello,world');
309309

310+
GO
311+
310312
-- TCK usage --

0 commit comments

Comments
 (0)