Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add where property to PGSQLExceptionInfo #559

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
/**
* Driver specific interface for exceptions that carry extended error
* information reported by the server.
*
*
* @author kdubb
*
*
*/
public interface PGSQLExceptionInfo {

Expand Down Expand Up @@ -61,4 +61,7 @@ public interface PGSQLExceptionInfo {

void setDetail(String details);

String getWhere();

void setWhere(String where);
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public static SQLException makeSQLException(String messagePrefix, Notice notice)
e.setDatatype(notice.getDatatype());
e.setConstraint(notice.getConstraint());
e.setDetail(notice.getDetail());
e.setWhere(notice.getWhere());

return (SQLException) e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class PGSQLIntegrityConstraintViolationException extends SQLIntegrityCons
private String datatype;
private String constraint;
private String detail;
private String where;

public PGSQLIntegrityConstraintViolationException() {
super();
Expand Down Expand Up @@ -135,4 +136,13 @@ public void setDetail(String details) {
this.detail = details;
}

@Override
public String getWhere() {
return where;
}

@Override
public void setWhere(String where) {
this.where = where;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class PGSQLSimpleException extends SQLException implements PGSQLException
private String datatype;
private String constraint;
private String detail;
private String where;

public PGSQLSimpleException() {
super();
Expand Down Expand Up @@ -137,4 +138,13 @@ public void setDetail(String details) {
this.detail = details;
}

@Override
public String getWhere() {
return where;
}

@Override
public void setWhere(String where) {
this.where = where;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public void before() throws Exception {
TestUtil.createTable(con, "testerr", "id int not null, val testdom not null");

stmt.execute("ALTER TABLE testerr ADD CONSTRAINT testerr_pk PRIMARY KEY (id)");

stmt.execute("""
CREATE OR REPLACE FUNCTION testfun() RETURNS VOID AS $$
BEGIN
raise exception 'test exception';
END;
$$ LANGUAGE PLPGSQL;
""");
stmt.close();
}

Expand All @@ -82,6 +90,7 @@ public void after() throws Exception {

Statement stmt = con.createStatement();
stmt.execute("DROP DOMAIN testdom");
stmt.execute("DROP FUNCTION testfun()");
stmt.close();

TestUtil.closeDB(con);
Expand Down Expand Up @@ -161,4 +170,22 @@ public void testDatatype() throws Exception {
stmt.close();
}

@Test
public void testWhere() throws Exception {
if (!(con.unwrap(PGConnection.class)).isServerMinimumVersion(9, 3))
return;

Statement stmt = con.createStatement();

try {
stmt.executeUpdate("select testfun()");
fail("Should have thrown a constraint violation.");
}
catch (SQLException e) {
PGSQLExceptionInfo sqle = (PGSQLExceptionInfo) e;
assertEquals("PL/pgSQL function testfun() line 3 at RAISE", sqle.getWhere());
}

stmt.close();
}
}