[#7069] Add ParserException.sql(), position(), line(), column()

This commit is contained in:
lukaseder 2018-01-29 12:30:56 +01:00
parent 98e2b3a527
commit 32d695ef77
2 changed files with 65 additions and 2 deletions

View File

@ -54,7 +54,11 @@ public final class ParserException extends DataAccessException {
/**
* Generated UID
*/
private static final long serialVersionUID = -724913199583039157L;
private static final long serialVersionUID = -724913199583039157L;
private final String sql;
private int position;
private int line;
private int column;
public ParserException(String sql) {
this(sql, null);
@ -70,5 +74,59 @@ public final class ParserException extends DataAccessException {
public ParserException(String sql, String message, SQLStateSubclass state, Throwable cause) {
super(state + ": " + (message == null ? "" : message + ": ") + sql, cause);
this.sql = sql;
}
/**
* The zero-based position within the SQL string at which an exception was thrown, if applicable.
*/
public final int position() {
return position;
}
/**
* Set the {@link #position()}.
*/
public final ParserException position(int p) {
this.position = p;
return this;
}
/**
* The one-based line number within the SQL string at which an exception was thrown, if applicable.
*/
public final int line() {
return line;
}
/**
* Set the {@link #line()}.
*/
public final ParserException line(int l) {
this.line = l;
return this;
}
/**
* The one-based column number within the SQL string at which an exception was thrown, if applicable.
*/
public final int column() {
return column;
}
/**
* Set the {@link #column()}.
*/
public final ParserException column(int c) {
this.column = c;
return this;
}
/**
* The SQL string that caused the exception.
*/
public final String sql() {
return sql;
}
}

View File

@ -7044,7 +7044,12 @@ final class ParserImpl implements Parser {
}
ParserException unexpectedToken() {
return new ParserException(mark());
return init(new ParserException(mark()));
}
ParserException init(ParserException e) {
int[] line = line();
return e.position(position).line(line[0]).column(line[1]);
}
Object nextBinding() {