diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserException.java b/jOOQ/src/main/java/org/jooq/impl/ParserException.java index 21c58b1008..86bcb6292e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserException.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserException.java @@ -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; } } \ No newline at end of file diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index 718c4924ba..6e1fc0964b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -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() {