Skip to content

Commit 1049e12

Browse files
committed
WIP - managed to get bytes out from query result
1 parent 7308490 commit 1049e12

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgConnectionImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ public Future<SqlResult<Buffer>> copyToBytes(String sql) {
145145
new QueryResultBuilder<>(factory, promise);
146146

147147
CopyOutCommand cmd = new CopyOutCommand(sql, resultHandler);
148-
return this.schedule(promise.context(), cmd);
148+
this.schedule(promise.context(), cmd).onComplete(resultHandler);
149+
return promise.future();
149150
}
150151

151152
@Override

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import java.util.stream.Collector;
1111

12-
public class CopyOutCommand extends CommandBase<SqlResult<Buffer>> {
12+
public class CopyOutCommand extends CommandBase<Boolean> {
1313
private final String sql;
1414
private final Collector<ByteBuf, Buffer, Buffer> collector;
1515
private final QueryResultBuilder<Buffer, SqlResultImpl<Buffer>, SqlResult<Buffer>> resultHandler;

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutCommandCodec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io.vertx.sqlclient.SqlResult;
66
import io.vertx.sqlclient.impl.SqlResultImpl;
77

8-
class CopyOutCommandCodec extends PgCommandCodec<SqlResult<Buffer>, CopyOutCommand> {
8+
class CopyOutCommandCodec extends PgCommandCodec<Boolean, CopyOutCommand> {
99
CopyOutDataDecoder decoder;
1010

1111
CopyOutCommandCodec(CopyOutCommand cmd) {
@@ -15,7 +15,7 @@ class CopyOutCommandCodec extends PgCommandCodec<SqlResult<Buffer>, CopyOutComma
1515

1616
@Override
1717
public void handleCommandComplete(int updated) {
18-
this.result = new SqlResultImpl<Buffer>(Buffer.buffer("abc"));
18+
this.result = false;
1919
Buffer result;
2020
Throwable failure;
2121
int size;

vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionCopyTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package io.vertx.pgclient;
22

3+
import io.vertx.core.buffer.Buffer;
34
import io.vertx.ext.unit.Async;
45
import io.vertx.ext.unit.TestContext;
56
import org.junit.Test;
67

8+
import java.util.Collections;
9+
import java.util.List;
10+
711
public class PgConnectionCopyTest extends PgConnectionTestBase {
812
public PgConnectionCopyTest() {
913
connector = (handler) -> PgConnection.connect(vertx, options).onComplete(ar -> {
@@ -41,7 +45,24 @@ public void testCopyToCsvBytes(TestContext ctx) {
4145
PgConnection pgConn = (PgConnection) conn;
4246
pgConn.copyToBytes("COPY Test TO STDOUT (FORMAT csv)")
4347
.onComplete(ctx.asyncAssertSuccess(result -> {
44-
result.value().getBytes();
48+
ctx.assertNull(result.columnDescriptors());
49+
ctx.assertEquals(10, result.rowCount());
50+
ctx.assertEquals(10, result.size());
51+
ctx.assertEquals(
52+
Buffer.buffer(
53+
"Whatever-0\n" +
54+
"Whatever-1\n" +
55+
"Whatever-2\n" +
56+
"Whatever-3\n" +
57+
"Whatever-4\n" +
58+
"Whatever-5\n" +
59+
"Whatever-6\n" +
60+
"Whatever-7\n" +
61+
"Whatever-8\n" +
62+
"Whatever-9\n"
63+
),
64+
result.value()
65+
);
4566
async.complete();
4667
}));
4768
});

0 commit comments

Comments
 (0)