[CONJ-957] Multi insert should return multi generated keys Created: 2022-04-11  Updated: 2022-04-25  Resolved: 2022-04-25

Status: Closed
Project: MariaDB Connector/J
Component/s: documentation
Affects Version/s: 3.0.4
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Lennart Fricke Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to CONJ-735 Multi insert should return multi gene... Closed

 Description   

The following test fails (same for prepared statements):

  @Test
  public void executeGeneratedMulti() throws SQLException {
    Statement stmt = sharedConn.createStatement();
    assertFalse(
        stmt.execute(
            "INSERT INTO executeGenerated(t2) values (100), (200)", Statement.RETURN_GENERATED_KEYS));
    ResultSet rs = stmt.getGeneratedKeys();
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertTrue(rs.next());
    assertEquals(2, rs.getInt(1));
    assertFalse(rs.next());
  }

I would expect it to succeed.

As in CONJ-735, CONJ-706 it seems that returning generated keys for multiple values is implemented in the driver as the database server only reports on the first inserted id. So one could argue that the behavior is ok, then I think it would be great to have this documented.



 Comments   
Comment by Diego Dupin [ 2022-04-25 ]

new documentation added : https://mariadb.com/kb/en/about-mariadb-connector-j/#generated-keys-limitation
multi-insert generated key cannot be implemented, but as indicated this can be achieved with INSERT...RETURNING command, returning a standard resultset

Generated at Thu Feb 08 03:19:33 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.