Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLConnection batchWithParameters took parameters from the previous #177

Open
SHiL0NG opened this issue Dec 30, 2019 · 0 comments
Open

SQLConnection batchWithParameters took parameters from the previous #177

SHiL0NG opened this issue Dec 30, 2019 · 0 comments

Comments

@SHiL0NG
Copy link

SHiL0NG commented Dec 30, 2019

Version

  • vert.x core: 3.6.3
  • vert.x jdbc-client: 3.6.3
  • jdbc driver: org.h2.Driver
  • RDBMS: H2

General info

  • What is your jdbc driver: org.h2.Driver
  • What is your RDBMS server: localhost
  • What is your connection string (no user/passwords please!): jdbc:h2:mem:test_categories;TRACE_LEVEL_FILE=2;DATABASE_TO_UPPER=FALSE;

Context

In my unit test class, I created a helper method to insert multiple Tickets:

 private Future<List<Integer>> batchInsertTickets(SQLClient client, JsonArray... tickets) {
        Stream.of(tickets).forEach(t -> LOG.info("Inserting ticket: {}", t));
        String sql = "INSERT INTO tickets(id, fleetId, groupId, assignedTo) VALUES (?, ?, ?, ?)";
        Future<List<Integer>> f = Future.future();
        client.getConnection(getConn -> {
            if (getConn.failed()) {
                f.fail(getConn.cause());
                return;
            }
            SQLConnection conn = getConn.result();

            conn.batchWithParams(sql, Arrays.asList(tickets), ar -> {
                if (ar.succeeded()) {
                    LOG.info("Insert tickets OK {}", ar.result());
                    f.complete(ar.result());
                } else {
                    LOG.info("Insert tickets KO {}", ar.cause().getMessage());
                    f.fail(ar.cause());
                }
                conn.close();
            });
        });
        return f;
    }

There there is a method to create a Ticket as a JsonArray

private JsonArray createTestTicket(String id, String fleetId, int groupId, String assignedTo) {
        JsonArray r = new JsonArray().add(id).add(fleetId).add(groupId);
        if (assignedTo == null) {
            return r;
        }
        return r.add(assignedTo);
}

And in the end, I did a batch insert with

batchInsertTickets(client,
                            createTestTicket("t1", F0001, 1, "user2"),
                            createTestTicket("t2", F0001, 2, null),
                            createTestTicket("t3", F0001, 12, null),
                            createTestTicket("t4", F0001, 3, null),
                            createTestTicket("t12", F0001, 12, "user1"),
                            createTestTicket("t5", F0001, 3, null))
                            .setHandler(insertTickets -> {
                                if (insertTickets.failed()) {
                                    context.fail("fail to insert tickets");
                                    return;
                                }
                               // query into database and get all tickets 
});

After I query into the database and get all the tickets, I got

[{"id":"t1","groupId":1,"assignedTo":"user2"}, 
{"id":"t2","groupId":2,"assignedTo":"user2"}, 
{"id":"t3","groupId":12,"assignedTo":"user2"}, 
{"id":"t4","groupId":3,"assignedTo":"user2"},
{"id":"t12","groupId":12,"assignedTo":"user1"}, 
{"id":"t5","groupId":3,"assignedTo":"user1"}]

Instead of having userId null for tickets t2, t3, t4, t5, they seem to keep the assignedTo information from previous parameters. In other words they should instead be

[{"id":"t1","groupId":1,"assignedTo":"user2"}, 
{"id":"t2","groupId":2,"assignedTo":"null"}, 
{"id":"t3","groupId":12,"assignedTo":"null"}, 
{"id":"t4","groupId":3,"assignedTo":"null"},
{"id":"t12","groupId":12,"assignedTo":"user1"}, 
{"id":"t5","groupId":3,"assignedTo":"null"}]

Hope I have made my issue clear.

Thanks!

Do you have a reproducer?

  • Link to github project/gist

Steps to reproduce

  1. ...
  2. ...
  3. ...
  4. ...

Extra

  • Anything that can be relevant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant