io.vertx.sqlclient.Row Java Examples
The following examples show how to use
io.vertx.sqlclient.Row.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DB2DataTypeTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testByteBufIntoVarchar(TestContext ctx) { byte[] expected = "hello world".getBytes(); connect(ctx.asyncAssertSuccess(conn -> { conn.preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)") .execute(Tuple.of(4, Buffer.buffer(expected)), ctx.asyncAssertSuccess(insertResult -> { conn.preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 4") .execute(ctx.asyncAssertSuccess(rows -> { ctx.assertEquals(1, rows.size()); Row row = rows.iterator().next(); ctx.assertEquals(4, row.getInteger(0)); ctx.assertTrue(Arrays.equals(expected, row.getBuffer(1).getBytes()), "Expecting " + Arrays.toString(expected) + " but got " + Arrays.toString(row.getBuffer(1).getBytes())); })); })); })); }
Example #2
Source File: CustomTypesSimpleCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testCustomType(TestContext ctx) { Async async = ctx.async(); String expected = "Anytown"; PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn .query("SELECT (address).city FROM \"CustomDataType\"").execute(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(2, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "city") .returns(Tuple::getValue, Row::getValue, expected) .returns(Tuple::getString, Row::getString, expected) .forRow(row); async.complete(); })); })); }
Example #3
Source File: RowMappers.java From vertx-jooq with MIT License | 6 votes |
public static Function<Row,generated.rx.reactive.regular.vertx.tables.pojos.Something> getSomethingMapper() { return row -> { generated.rx.reactive.regular.vertx.tables.pojos.Something pojo = new generated.rx.reactive.regular.vertx.tables.pojos.Something(); pojo.setSomeid(row.getInteger("someId")); pojo.setSomestring(row.getString("someString")); pojo.setSomehugenumber(row.getLong("someHugeNumber")); pojo.setSomesmallnumber(row.getShort("someSmallNumber")); pojo.setSomeregularnumber(row.getInteger("someRegularNumber")); pojo.setSomedouble(row.getDouble("someDouble")); pojo.setSomeenum(java.util.Arrays.stream(generated.rx.reactive.regular.vertx.enums.Someenum.values()).filter(td -> td.getLiteral().equals(row.getString("someEnum"))).findFirst().orElse(null)); pojo.setSomejsonobject(row.get(io.vertx.core.json.JsonObject.class,row.getColumnIndex("someJsonObject"))); pojo.setSomecustomjsonobject(generated.rx.reactive.regular.vertx.tables.converters.Converters.IO_GITHUB_JKLINGSPORN_VERTX_JOOQ_GENERATE_CONVERTER_SOMEJSONPOJOCONVERTER_INSTANCE.pgConverter().from(row.get(io.vertx.core.json.JsonObject.class,row.getColumnIndex("someCustomJsonObject")))); pojo.setSomejsonarray(row.get(io.vertx.core.json.JsonArray.class,row.getColumnIndex("someJsonArray"))); pojo.setSometimestamp(row.getLocalDateTime("someTimestamp")); return pojo; }; }
Example #4
Source File: MySQLUtilityCommandTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testChangeUser(TestContext ctx) { MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn.query("SELECT current_user()").execute(ctx.asyncAssertSuccess(res1 -> { Row row1 = res1.iterator().next(); String username = row1.getString(0); ctx.assertEquals("mysql", username.substring(0, username.lastIndexOf('@'))); MySQLAuthOptions changeUserOptions = new MySQLAuthOptions() .setUser("superuser") .setPassword("password") .setDatabase("emptyschema"); conn.changeUser(changeUserOptions, ctx.asyncAssertSuccess(v2 -> { conn.query("SELECT current_user();SELECT database();").execute(ctx.asyncAssertSuccess(res2 -> { ctx.assertEquals("superuser@%", res2.iterator().next().getString(0)); ctx.assertEquals("emptyschema", res2.next().iterator().next().getValue(0)); conn.close(); })); })); })); })); }
Example #5
Source File: DateTimeTypesSimpleCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testDate(TestContext ctx) { Async async = ctx.async(); PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn .query("SELECT '1981-05-30'::DATE \"LocalDate\"").execute(ctx.asyncAssertSuccess(result -> { LocalDate ld = LocalDate.parse("1981-05-30"); ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "LocalDate") .returns(Tuple::getValue, Row::getValue, ld) .returns(Tuple::getLocalDate, Row::getLocalDate, ld) .returns(Tuple::getTemporal, Row::getTemporal, ld) .forRow(row); async.complete(); })); })); }
Example #6
Source File: DateTimeTypesExtendedCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testEncodeOffsetDateTimeArray(TestContext ctx) { Async async = ctx.async(); PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn.prepare("UPDATE \"ArrayDataType\" SET \"OffsetDateTime\" = $1 WHERE \"id\" = $2 RETURNING \"OffsetDateTime\"", ctx.asyncAssertSuccess(p -> { final OffsetDateTime dt = OffsetDateTime.parse("2017-05-14T19:35:58.237666Z"); p.query().execute(Tuple.tuple() .addOffsetDateTimeArray(new OffsetDateTime[]{dt}) .addInteger(2) , ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "OffsetDateTime") .returns(Tuple::getValue, Row::getValue, new OffsetDateTime[]{dt}) .returns(Tuple::getOffsetTimeArray, Row::getOffsetTimeArray, new OffsetTime[]{dt.toOffsetTime()}) .returns(Tuple::getOffsetDateTimeArray, Row::getOffsetDateTimeArray, new OffsetDateTime[]{dt}) .forRow(result.iterator().next()); async.complete(); })); })); })); }
Example #7
Source File: SqlClientExamples.java From vertx-sql-client with Apache License 2.0 | 6 votes |
public void usingConnections03(SqlConnection connection) { connection.prepare("INSERT INTO USERS (id, name) VALUES ($1, $2)", ar1 -> { if (ar1.succeeded()) { PreparedStatement prepared = ar1.result(); // Create a query : bind parameters List<Tuple> batch = new ArrayList(); // Add commands to the createBatch batch.add(Tuple.of("julien", "Julien Viet")); batch.add(Tuple.of("emad", "Emad Alblueshi")); prepared.query().executeBatch(batch, res -> { if (res.succeeded()) { // Process rows RowSet<Row> rows = res.result(); } else { System.out.println("Batch failed " + res.cause()); } }); } }); }
Example #8
Source File: MySQLStoredProgramsTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testOutParameters(TestContext ctx) { MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn.query("DROP PROCEDURE IF EXISTS test_out_parameter;").execute(ctx.asyncAssertSuccess(cleanProcedure -> { conn.query("CREATE PROCEDURE test_out_parameter(OUT p1 VARCHAR(20))\n" + "BEGIN\n" + " SELECT 'hello,world!' INTO p1;\n" + "end;").execute(ctx.asyncAssertSuccess(createProcedure -> { conn.query("CALL test_out_parameter(@OUT);").execute(ctx.asyncAssertSuccess(callProcedure -> { conn.query("SELECT @OUT;").execute(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals("hello,world!", row.getValue(0)); ctx.assertEquals("hello,world!", row.getString(0)); conn.close(); })); })); })); })); })); }
Example #9
Source File: SpatialBinaryCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testEncodeMultiPoint(TestContext ctx) { List<Point> points = new ArrayList<>(); points.add(new Point(0, 0, 0)); points.add(new Point(0, 1, 1)); points.add(new Point(0, 2, 2)); MultiPoint multiPoint = new MultiPoint(0, points); testBinaryEncodeGeometry(ctx, multiPoint, result -> { Row row = result.iterator().next(); String text = row.getString(0); // a workaround for MySQL 5.6 boolean expected1 = "MULTIPOINT(0 0,1 1,2 2)".equals(text); boolean expected2 = "MULTIPOINT((0 0),(1 1),(2 2))".equals(text); ctx.assertTrue(expected1 || expected2); }); }
Example #10
Source File: EnumeratedTypesSimpleCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testEnum(TestContext ctx) { Async async = ctx.async(); PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn .query("SELECT \"currentMood\" FROM \"EnumDataType\" WHERE \"id\" = 5").execute(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "currentMood") .returns(Tuple::getValue, Row::getValue, "ok") .returns(Tuple::getString, Row::getString, "ok") .forRow(row); async.complete(); })); })); }
Example #11
Source File: RowStreamImpl.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Override public RowStream<Row> fetch(long amount) { if (amount < 0L) { throw new IllegalArgumentException("Invalid fetch amount " + amount); } synchronized (this) { demand += amount; if (demand < 0L) { demand = Long.MAX_VALUE; } if (cursor == null) { return this; } } checkPending(); return this; }
Example #12
Source File: PostgresClient.java From raml-module-builder with Apache License 2.0 | 6 votes |
void selectStream(AsyncResult<SQLConnection> conn, String sql, Tuple params, int chunkSize, Handler<AsyncResult<RowStream<Row>>> replyHandler) { try { if (conn.failed()) { replyHandler.handle(Future.failedFuture(conn.cause())); return; } final Transaction tx = conn.result().tx; tx.prepare(sql, res -> { if (res.failed()) { log.error(res.cause().getMessage(), res.cause()); replyHandler.handle(Future.failedFuture(res.cause())); return; } PreparedStatement pq = res.result(); RowStream<Row> rowStream = pq.createStream(chunkSize, params); replyHandler.handle(Future.succeededFuture(rowStream)); }); } catch (Exception e) { log.error("select stream sql: " + e.getMessage() + " - " + sql, e); replyHandler.handle(Future.failedFuture(e)); } }
Example #13
Source File: PgTemplateTestBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
protected <P, T, V> void testGet(TestContext ctx, String sqlType, Function<Row, T> rowMapper, Function<P, Map<String, Object>> paramsMapper, String paramName, P params, V expected, Function<T, V> extractor, String column) { Async async = ctx.async(); SqlTemplate<P, RowSet<T>> template = SqlTemplate .forQuery(connection, "SELECT #{" + paramName + "} :: " + sqlType + " \"" + column + "\"") .mapFrom(paramsMapper) .mapTo(rowMapper); template.execute(params, ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(expected, extractor.apply(result.iterator().next())); async.complete(); })); async.await(10000); }
Example #14
Source File: RowMappers.java From vertx-jooq with MIT License | 6 votes |
public static Function<Row,generated.rx.reactive.guice.vertx.tables.pojos.Something> getSomethingMapper() { return row -> { generated.rx.reactive.guice.vertx.tables.pojos.Something pojo = new generated.rx.reactive.guice.vertx.tables.pojos.Something(); pojo.setSomeid(row.getInteger("someId")); pojo.setSomestring(row.getString("someString")); pojo.setSomehugenumber(row.getLong("someHugeNumber")); pojo.setSomesmallnumber(row.getShort("someSmallNumber")); pojo.setSomeregularnumber(row.getInteger("someRegularNumber")); pojo.setSomedouble(row.getDouble("someDouble")); pojo.setSomeenum(java.util.Arrays.stream(generated.rx.reactive.guice.vertx.enums.Someenum.values()).filter(td -> td.getLiteral().equals(row.getString("someEnum"))).findFirst().orElse(null)); pojo.setSomejsonobject(row.get(io.vertx.core.json.JsonObject.class,row.getColumnIndex("someJsonObject"))); pojo.setSomecustomjsonobject(generated.rx.reactive.guice.vertx.tables.converters.Converters.IO_GITHUB_JKLINGSPORN_VERTX_JOOQ_GENERATE_CONVERTER_SOMEJSONPOJOCONVERTER_INSTANCE.pgConverter().from(row.get(io.vertx.core.json.JsonObject.class,row.getColumnIndex("someCustomJsonObject")))); pojo.setSomejsonarray(row.get(io.vertx.core.json.JsonArray.class,row.getColumnIndex("someJsonArray"))); pojo.setSometimestamp(row.getLocalDateTime("someTimestamp")); return pojo; }; }
Example #15
Source File: DateTimeTypesSimpleCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testTimestamp(TestContext ctx) { Async async = ctx.async(); PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn .query("SELECT '2017-05-14 19:35:58.237666'::TIMESTAMP \"LocalDateTime\"").execute(ctx.asyncAssertSuccess(result -> { LocalDateTime ldt = LocalDateTime.parse("2017-05-14T19:35:58.237666"); ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "LocalDateTime") .returns(Tuple::getValue, Row::getValue, ldt) .returns(Tuple::getLocalTime, Row::getLocalTime, ldt.toLocalTime()) .returns(Tuple::getLocalDate, Row::getLocalDate, ldt.toLocalDate()) .returns(Tuple::getLocalDateTime, Row::getLocalDateTime, ldt) .returns(Tuple::getTemporal, Row::getTemporal, ldt) .forRow(row); async.complete(); })); })); }
Example #16
Source File: MySQLStoredProgramsTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testInOutParameters(TestContext ctx) { MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn.query("DROP PROCEDURE IF EXISTS test_inout_parameter;").execute(ctx.asyncAssertSuccess(cleanProcedure -> { conn.query("CREATE PROCEDURE test_inout_parameter(INOUT p1 INT)\n" + "BEGIN\n" + " SET p1 = p1 + 12345;\n" + "end;").execute(ctx.asyncAssertSuccess(createProcedure -> { conn.query("SET @INOUT = 98765;\n" + "CALL test_inout_parameter(@INOUT);").execute(ctx.asyncAssertSuccess(callProcedure -> { conn.query("SELECT @INOUT;").execute(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(111110, row.getInteger(0)); conn.close(); })); })); })); })); })); }
Example #17
Source File: CharacterTypesExtendedCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testEncodeFixedChar(TestContext ctx) { Async async = ctx.async(); PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn.prepare("UPDATE \"CharacterDataType\" SET \"FixedChar\" = upper($1) WHERE \"id\" = $2 RETURNING \"FixedChar\"", ctx.asyncAssertSuccess(p -> { p.query().execute(Tuple.tuple() .addString("no") .addInteger(2), ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); String name = "NO "; ColumnChecker.checkColumn(0, "FixedChar") .returns(Tuple::getValue, Row::getValue, name) .returns(Tuple::getString, Row::getString, name) .forRow(row); async.complete(); })); })); })); }
Example #18
Source File: SpatialBinaryCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testEncodeMultiLineString(TestContext ctx) { List<Point> pointsOfFirstLineString = new ArrayList<>(); pointsOfFirstLineString.add(new Point(0, 1, 1)); pointsOfFirstLineString.add(new Point(0, 2, 2)); pointsOfFirstLineString.add(new Point(0, 3, 3)); LineString firstLineString = new LineString(0, pointsOfFirstLineString); List<Point> pointsOfSecondLineString = new ArrayList<>(); pointsOfSecondLineString.add(new Point(0, 4, 4)); pointsOfSecondLineString.add(new Point(0, 5, 5)); LineString secondLineString = new LineString(0, pointsOfSecondLineString); List<LineString> lineStrings = new ArrayList<>(); lineStrings.add(firstLineString); lineStrings.add(secondLineString); MultiLineString multiLineString = new MultiLineString(0, lineStrings); testBinaryEncodeGeometry(ctx, multiLineString, result -> { Row row = result.iterator().next(); String text = row.getString(0); ctx.assertEquals("MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5))", text); }); }
Example #19
Source File: NumericTypesExtendedCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testEncodeDoubleArray(TestContext ctx) { Async async = ctx.async(); PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn.prepare("UPDATE \"ArrayDataType\" SET \"Double\" = $1 WHERE \"id\" = $2 RETURNING \"Double\"", ctx.asyncAssertSuccess(p -> { p.query().execute(Tuple.tuple() .addDoubleArray(new Double[]{6.3}) .addInteger(2) , ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Double") .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new double[]{6.3})) .returns(Tuple::getShortArray, Row::getShortArray, ColumnChecker.toObjectArray(new short[]{(short)6.3})) .returns(Tuple::getIntegerArray, Row::getIntegerArray, ColumnChecker.toObjectArray(new int[]{(int)6.3})) .returns(Tuple::getLongArray, Row::getLongArray, ColumnChecker.toObjectArray(new long[]{(long)6.3})) .returns(Tuple::getFloatArray, Row::getFloatArray, ColumnChecker.toObjectArray(new float[]{(float)6.3})) .returns(Tuple::getDoubleArray, Row::getDoubleArray, ColumnChecker.toObjectArray(new double[]{6.3})) .forRow(result.iterator().next()); async.complete(); })); })); })); }
Example #20
Source File: MSSQLDataTypeTestBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
protected <T> void testPreparedQueryDecodeGeneric(TestContext ctx, String tableName, String columnName, String rowIdentifier, Consumer<Row> checker) { MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn .preparedQuery(String.format("SELECT %s FROM %s WHERE id = %s", columnName, tableName, rowIdentifier)) .execute(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); checker.accept(row); conn.close(); })); })); }
Example #21
Source File: SqlClientExamples.java From vertx-sql-client with Apache License 2.0 | 6 votes |
public void usingCursors01(SqlConnection connection) { connection.prepare("SELECT * FROM users WHERE age > ?", ar1 -> { if (ar1.succeeded()) { PreparedStatement pq = ar1.result(); // Create a cursor Cursor cursor = pq.cursor(Tuple.of(18)); // Read 50 rows cursor.read(50, ar2 -> { if (ar2.succeeded()) { RowSet<Row> rows = ar2.result(); // Check for more ? if (cursor.hasMore()) { // Repeat the process... } else { // No more rows - close the cursor cursor.close(); } } }); } }); }
Example #22
Source File: SpatialDataTypeCodecTestBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testDecodeGeometryCollection(TestContext ctx) { testDecodeGeometry(ctx, "SELECT ST_GeometryFromText('GEOMETRYCOLLECTION(Point(1 1),LineString(2 2, 3 3))', 0) AS test_geometry;", result -> { Row row = result.iterator().next(); GeometryCollection geometryCollection = row.get(GeometryCollection.class, 0); ctx.assertEquals(0L, geometryCollection.getSRID()); List<Geometry> geometries = geometryCollection.getGeometries(); ctx.assertEquals(2, geometries.size()); ctx.assertTrue(geometries.get(0) instanceof Point); Point firstGeometry = (Point) geometries.get(0); ctx.assertEquals(1d, firstGeometry.getX()); ctx.assertEquals(1d, firstGeometry.getY()); ctx.assertTrue(geometries.get(1) instanceof LineString); LineString secondGeometry = (LineString) geometries.get(1); List<Point> pointsOfSecondGeometry = secondGeometry.getPoints(); ctx.assertEquals(2, pointsOfSecondGeometry.size()); ctx.assertEquals(2d, pointsOfSecondGeometry.get(0).getX()); ctx.assertEquals(2d, pointsOfSecondGeometry.get(0).getY()); ctx.assertEquals(3d, pointsOfSecondGeometry.get(1).getY()); ctx.assertEquals(3d, pointsOfSecondGeometry.get(1).getY()); }); }
Example #23
Source File: PostgresClientTest.java From raml-module-builder with Apache License 2.0 | 6 votes |
private RowSet<Row> getMockTestPojoResultSet(int total) { List<String> columnNames = new ArrayList<String>(Arrays.asList(new String[] { "id", "foo", "bar", "biz", "baz" })); RowDesc rowDesc = new RowDesc(columnNames); List<Row> rows = new LinkedList<>(); for (int i = 0; i < total; i++) { Row row = new RowImpl(rowDesc); row.addUUID(UUID.randomUUID()); row.addString("foo " + i); row.addString("bar " + i); row.addDouble((double) i); row.addStringArray(new String[] { "This", "is", "a", "test" } ); rows.add(row); } return new LocalRowSet(total).withColumns(columnNames).withRows(rows); }
Example #24
Source File: PreparedStatementTestBase.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testStreamQueryError(TestContext ctx) { Async async = ctx.async(); PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> { conn.prepare("SELECT * FROM Fortune", ctx.asyncAssertSuccess(ps -> { RowStream<Row> stream = ps.createStream(4, Tuple.tuple()); stream.endHandler(v -> ctx.fail()); AtomicInteger rowCount = new AtomicInteger(); stream.exceptionHandler(err -> { ctx.assertEquals(4, rowCount.getAndIncrement()); async.complete(); }); stream.handler(tuple -> rowCount.incrementAndGet()); })); })); }
Example #25
Source File: EnumeratedTypesExtendedCodecTest.java From vertx-sql-client with Apache License 2.0 | 6 votes |
@Test public void testEncodeEnumArray(TestContext ctx) { Async async = ctx.async(); PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\"", ctx.asyncAssertSuccess(p -> { p.query().execute(Tuple.tuple() .addStringArray(new String[]{"unhappy"}) .addInteger(2) , ctx.asyncAssertSuccess(result -> { ColumnChecker.checkColumn(0, "Enum") .returns(Tuple::getValue, Row::getValue, new String[]{"unhappy"}) .returns(Tuple::getStringArray, Row::getStringArray, new String[]{"unhappy"}) .forRow(result.iterator().next()); async.complete(); })); })); })); }
Example #26
Source File: NumericDataTypeTest.java From vertx-sql-client with Apache License 2.0 | 5 votes |
@Test public void testBinaryEncodeCastShortToDecimal(TestContext ctx) { testBinaryDecode(ctx, "SELECT * FROM basicdatatype WHERE id = 1 AND test_decimal = ?", Tuple.of((short) 12345), result -> { ctx.assertEquals(1, result.size()); RowIterator<Row> iterator = result.iterator(); Row row = iterator.next(); ctx.assertEquals(1, row.getInteger("id")); ctx.assertEquals(Numeric.create(12345), row.getValue("test_decimal")); }); }
Example #27
Source File: MSSQLQueryNullableDataTypeTest.java From vertx-sql-client with Apache License 2.0 | 5 votes |
@Override protected void testDecodeValue(TestContext ctx, boolean isNull, String columnName, Consumer<Row> checker) { if (isNull) { testQueryDecodeGeneric(ctx, "nullable_datatype", columnName, "3", checker); } else { testQueryDecodeGeneric(ctx, "nullable_datatype", columnName, "1", checker); } }
Example #28
Source File: RowResultDecoder.java From vertx-sql-client with Apache License 2.0 | 5 votes |
private Row decodeMssqlRow(int len, ByteBuf in) { Row row = new MSSQLRowImpl(desc); for (int c = 0; c < len; c++) { Object decoded = null; ColumnData columnData = desc.columnDatas[c]; decoded = MSSQLDataTypeCodec.decode(columnData.dataType(), in); row.addValue(decoded); } return row; }
Example #29
Source File: MySQLTextDataTypeDecodeTest.java From vertx-sql-client with Apache License 2.0 | 5 votes |
@Test @Override public void testBoolean(TestContext ctx) { connector.connect(ctx.asyncAssertSuccess(conn -> { conn.query("SELECT test_boolean FROM basicdatatype WHERE id = 1").execute(ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); Row row = result.iterator().next(); ctx.assertEquals(true, row.getBoolean(0)); ctx.assertEquals(true, row.getBoolean("test_boolean")); ctx.assertEquals((byte) 1, row.getValue(0)); ctx.assertEquals((byte) 1, row.getValue("test_boolean")); })); })); }
Example #30
Source File: NumericTypesExtendedCodecTest.java From vertx-sql-client with Apache License 2.0 | 5 votes |
@Test public void testEncodeInt4(TestContext ctx) { Async async = ctx.async(); PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> { conn.prepare("UPDATE \"NumericDataType\" SET \"Integer\" = $1 WHERE \"id\" = $2 RETURNING \"Integer\"", ctx.asyncAssertSuccess(p -> { p.query().execute(Tuple.tuple() .addInteger(Integer.MIN_VALUE) .addInteger(2) , ctx.asyncAssertSuccess(result -> { ctx.assertEquals(1, result.size()); ctx.assertEquals(1, result.rowCount()); Row row = result.iterator().next(); ColumnChecker.checkColumn(0, "Integer") .returns(Tuple::getValue, Row::getValue, Integer.MIN_VALUE) .returns(Tuple::getShort, Row::getShort, (short) 0) .returns(Tuple::getInteger, Row::getInteger, Integer.MIN_VALUE) .returns(Tuple::getLong, Row::getLong, -2147483648L) .returns(Tuple::getFloat, Row::getFloat, -2147483648f) .returns(Tuple::getDouble, Row::getDouble, -2147483648d) .returns(Tuple::getBigDecimal, Row::getBigDecimal, new BigDecimal(-2147483648)) .returns(Numeric.class, Numeric.create(-2147483648)) .forRow(row); async.complete(); })); })); })); }