AccountPatchReview : fix mariadb status matching
mariadb is currently using SQLException.getSQLState() (as used by
getSQLStateInt()) which returns the ANSI SQLSTATE value, not the
MariaDB/mysql error code [1].
The result is that the duplicate key detection doesn't work when using
the mariadb connector. If you have already reviewed a file (or click
"reviewed" in the file chooser) and then open it again you get a 500
error and a long backtrace including something like
Caused by: java.sql.SQLIntegrityConstraintViolationException:
(conn=13) Duplicate entry '3-1-1000001-file-3.txt' for key 'PRIMARY'
We could either continue using getSQLState() and change this to
"23000" (which covers all these values) or do as MySQL connector does
and use the vendor-specific getErrorCode() call. I've taken the later
approach here.
[1] https://mariadb.com/kb/en/mariadb-error-codes/
Change-Id: I5762118ceb5628171b991a80fe701d160ab0d959
diff --git a/java/com/google/gerrit/server/schema/MariaDBAccountPatchReviewStore.java b/java/com/google/gerrit/server/schema/MariaDBAccountPatchReviewStore.java
index b0a3370..5073af1 100644
--- a/java/com/google/gerrit/server/schema/MariaDBAccountPatchReviewStore.java
+++ b/java/com/google/gerrit/server/schema/MariaDBAccountPatchReviewStore.java
@@ -37,7 +37,7 @@
@Override
public StorageException convertError(String op, SQLException err) {
- switch (getSQLStateInt(err)) {
+ switch (err.getErrorCode()) {
case 1022: // ER_DUP_KEY
case 1062: // ER_DUP_ENTRY
case 1169: // ER_DUP_UNIQUE;