[CONJ-113] Vendor code is not properly propagated to parent BatchUpdateException for executeBatch() Created: 2014-09-12  Updated: 2014-09-23  Resolved: 2014-09-23

Status: Closed
Project: MariaDB Connector/J
Component/s: None
Affects Version/s: 1.1.7
Fix Version/s: 1.1.8

Type: Bug Priority: Minor
Reporter: Lennart Schedin Assignee: Massimo Siani (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Attachments: Java Source File VendorCodeExeceptionTest.java    

 Description   

How to reproduce:
Run the attached VendorCodeExeceptionTest.java and especially the method testNoSuchTableBatchUpdate()
Pseudo code:

  1. Think out a good table name
  2. Don’t create a table (drop it to make sure it does not exist)
  3. Create a PreparedStatement to insert data in the non-existing table
  4. Add a batch to PreparedStatement
  5. Execute the batch

Actual:

java.lang.AssertionError: expected:<1146> but was:<0>
	at org.mariadb.jdbc.VendorCodeExeceptionTest.testNoSuchTableBatchUpdate(VendorCodeExeceptionTest.java:78)

The vendor code is 0. In other words it is not set.

Expected:
The vendor code should be propagated up to the parent exception to make it easier for the program (and perhaps also to be more compatible with Mysql JDBC).

Compare with the test case testNoSuchTable(). In this case the error could should be 1146 as described at http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html

Analysis and suggested fix:
The bug is in MySQLPreparedStatement.executeBatch() and the catch clause. Every parameter except the vendorCode is passed to the constructor of BatchUpdateException. My suggestion is to add the vendorCode as a parameter.

Feel free to add my test class to the MariaDB source code.



 Comments   
Comment by Lennart Schedin [ 2014-09-15 ]

The method MySQLStatement.executeBatch() probably also needs to be fixed.

Comment by Massimo Siani (Inactive) [ 2014-09-15 ]

Can be found here
https://code.launchpad.net/~massimo-siani/mariadb-java-client/CONJ-113

Comment by Lennart Schedin [ 2014-09-16 ]

The fix looked fine! I also searched in the source code for other places where this might be missing (I searched for the usage of constructors SQLException (and subclasses) that does not set the vendor code). I could only find the two places that now has been fixed.

The JUnit tests looked a bit duplicated? Does the same tests need to be both in PreparedStatementTest.java and StatementTest.java?

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