You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
SQLiteDialect#isUniqueConstraintViolated does not recognize SQLite primary key unique constraint violations
Expected behavior
UniqueConstraintException is thrown
Actual behavior
SQLExecutionException is thrown
To Reproduce
Steps to reproduce the behavior:
Use SQLite
Insert an entry with unique key twice
Exception not catched
Fix
The current way to check is by comparing the message of the exception like below
public boolean isUniqueConstraintViolated(SQLException sqlException) {
if (sqlException == null) {
throw new DomaNullPointerException("sqlException");
}
SQLException cause = getCauseSQLException(sqlException);
String message = cause.getMessage();
return message != null
&& message.startsWith("[SQLITE_CONSTRAINT]")
&& message.contains(" unique)");
}
But this will never work because the exception looks like this
[SQLITE_CONSTRAINT_PRIMARYKEY] A PRIMARY KEY constraint failed (UNIQUE constraint failed: <property>)
I suggest to change the body of the method to something like this
@Override
public boolean isUniqueConstraintViolated(@NonNull final SQLException sqlException) {
final var cause = getCauseSQLException(sqlException);
final var message = cause.getMessage();
return message != null
&& message.startsWith("[SQLITE_CONSTRAINT_PRIMARYKEY] A PRIMARY KEY constraint failed (UNIQUE constraint failed:");
}
The text was updated successfully, but these errors were encountered:
Describe the bug
SQLiteDialect#isUniqueConstraintViolated does not recognize SQLite primary key unique constraint violations
Expected behavior
UniqueConstraintException is thrown
Actual behavior
SQLExecutionException is thrown
To Reproduce
Steps to reproduce the behavior:
Fix
The current way to check is by comparing the message of the exception like below
But this will never work because the exception looks like this
[SQLITE_CONSTRAINT_PRIMARYKEY] A PRIMARY KEY constraint failed (UNIQUE constraint failed: <property>)
I suggest to change the body of the method to something like this
The text was updated successfully, but these errors were encountered: