More robust duplicate row detection.

This commit is contained in:
Michael Bayne
2026-01-27 11:45:10 -08:00
parent 12581ac5de
commit 4827bb48a5
2 changed files with 4 additions and 3 deletions
@@ -23,7 +23,7 @@ public class MySQLLiaison extends BaseLiaison
public boolean isDuplicateRowException (SQLException sqe) public boolean isDuplicateRowException (SQLException sqe)
{ {
String msg = sqe.getMessage(); String msg = sqe.getMessage();
return (msg != null && msg.indexOf("Duplicate entry") != -1); return (sqe.getErrorCode() == 1062) || (msg != null && msg.indexOf("Duplicate entry") != -1);
} }
@Override // from DatabaseLiaison @Override // from DatabaseLiaison
@@ -21,8 +21,9 @@ public class PostgreSQLLiaison extends BaseLiaison
// from DatabaseLiaison // from DatabaseLiaison
public boolean isDuplicateRowException (SQLException sqe) public boolean isDuplicateRowException (SQLException sqe)
{ {
String msg = sqe.getMessage(); // PostgreSQL duplicate key error code is 23505
return (msg != null && msg.indexOf("duplicate key") != -1); String state = sqe.getSQLState(), msg = sqe.getMessage();
return ("23505".equals(state)) || (msg != null && msg.indexOf("duplicate key") != -1);
} }
// from DatabaseLiaison // from DatabaseLiaison