Skip to content

Commit

Permalink
#259 Replace incorrect SQLSTATEs
Browse files Browse the repository at this point in the history
Also some message cleanup
  • Loading branch information
mrotteveel committed Jun 4, 2023
1 parent dc33314 commit 7c36520
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 85 deletions.
17 changes: 17 additions & 0 deletions src/docs/asciidoc/release_notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,23 @@ there is no replacement
there is no replacement
** `LOGGER_IMPLEMENTATION_PROP`;
there is no replacement
* `SQLStateConstants`
** `SQL_STATE_INVALID_CONN_ATTR` (`01S00`) -- it was unused;
there is no replacement
** `SQL_STATE_INVALID_COLUMN` (`HY002`);
replaced by `SQL_STATE_INVALID_DESC_FIELD_ID` (`HY091`)
** `SQL_STATE_INVALID_ARG_VALUE` (`HY009`);
used with wrong meaning, replaced by multiple other constants (`SQL_STATE_INVALID_USE_NULL` (`HY009`, same value), `SQL_STATE_ATT_CANNOT_SET_NOW` (`HY011`) , `SQL_STATE_INVALID_ATTR_VALUE` (`HY024`), `SQL_STATE_INVALID_STRING_LENGTH` (`HY090`))
** `SQL_STATE_INVALID_TRANSACTION_STATE` (`25S01`) -- it was unused;
there is no replacement
** `SQL_STATE_TRANSACTION_ACTIVE` (`25S02`) -- it was unused;
there is no replacement
** `SQL_STATE_TRANSACTION_ROLLED_BACK` (`25S03`) -- it was unused;
there is no replacement
** `SQL_STATE_CONNECTION_FAILURE_IN_TX` (`08007`) -- it was unused;
there is no replacement
** `SQL_STATE_COMM_LINK_FAILURE` (`08S01`) -- it was unused;
there is no replacement

[#removal-of-deprecated-classes-packages-and-methods]
=== Removal of deprecated classes, packages and methods
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/firebirdsql/ds/StatementHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
return isClosed();
}
if (isClosed() && !method.equals(STATEMENT_CLOSE)) {
throw new FBSQLException("Statement already closed", SQLStateConstants.SQL_STATE_INVALID_STATEMENT_ID);
throw new FBSQLException("Statement is already closed", SQLStateConstants.SQL_STATE_INVALID_STATEMENT_ID);
}

try {
Expand Down
18 changes: 9 additions & 9 deletions src/main/org/firebirdsql/jdbc/FBBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ FbBlob openBlob() throws SQLException {
try (LockCloseable ignored = withLock()) {
checkClosed();
if (isNew) {
throw new FBSQLException("No Blob ID is available in new Blob object.");
throw new FBSQLException("No Blob ID is available in new Blob object");
}
return gdsHelper.openBlob(blobId, config);
}
Expand Down Expand Up @@ -307,7 +307,7 @@ public long length() throws SQLException {
*/
long interpretLength(byte[] info, int position) throws SQLException {
if (info[position] != ISCConstants.isc_info_blob_total_length)
throw new FBSQLException("Length is not available.");
throw new FBSQLException("Length is not available");

int dataLength = VaxEncoding.iscVaxInteger(info, position + 1, 2);
return VaxEncoding.iscVaxLong(info, position + 3, dataLength);
Expand Down Expand Up @@ -339,8 +339,8 @@ public byte[] getBytes(long pos, int length) throws SQLException {
throw new FBSQLException("Blob position should be >= 1");

if (pos > Integer.MAX_VALUE)
throw new FBSQLException("Blob position is limited to 2^31 - 1 due to isc_seek_blob limitations.",
SQLStateConstants.SQL_STATE_INVALID_ARG_VALUE);
throw new FBSQLException("Blob position is limited to 2^31 - 1 due to isc_seek_blob limitations",
SQLStateConstants.SQL_STATE_INVALID_STRING_LENGTH);

try (LockCloseable ignored = withLock()) {
blobListener.executionStarted(this);
Expand Down Expand Up @@ -412,21 +412,21 @@ public OutputStream setBinaryStream(long pos) throws SQLException {
blobListener.executionStarted(this);

if (blobOut != null)
throw new FBSQLException("OutputStream already open. Only one blob output stream can be open at a time.");
throw new FBSQLException("OutputStream already open. Only one blob output stream can be open at a time");

if (pos < 1)
throw new FBSQLException("You can't start before the beginning of the blob",
SQLStateConstants.SQL_STATE_INVALID_ARG_VALUE);
SQLStateConstants.SQL_STATE_INVALID_STRING_LENGTH);

if (isNew && pos > 1)
throw new FBSQLException("Previous value was null, you must start at position 1",
SQLStateConstants.SQL_STATE_INVALID_ARG_VALUE);
SQLStateConstants.SQL_STATE_INVALID_STRING_LENGTH);

blobOut = new FBBlobOutputStream(this);
if (pos > 1) {
//copy pos bytes from input to output
//implement this later
throw new FBDriverNotCapableException("Offset start positions are not yet supported.");
throw new FBDriverNotCapableException("Offset start positions are not yet supported");
}

return blobOut;
Expand All @@ -442,7 +442,7 @@ public OutputStream setBinaryStream(long pos) throws SQLException {
public long getBlobId() throws SQLException {
try (LockCloseable ignored = withLock()) {
if (isNew)
throw new FBSQLException("No Blob ID is available in new Blob object.");
throw new FBSQLException("No Blob ID is available in new Blob object");

return blobId;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/firebirdsql/jdbc/FBCachedBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public long length() throws SQLException {
public byte[] getBytes(long pos, int length) throws SQLException {
if (pos < 1) {
throw new SQLException("Expected value of pos > 0, got " + pos,
SQLStateConstants.SQL_STATE_INVALID_ARG_VALUE);
SQLStateConstants.SQL_STATE_INVALID_STRING_LENGTH);
}
if (length < 0) {
throw new SQLException("Expected value of length >= 0, got " + length,
SQLStateConstants.SQL_STATE_INVALID_ARG_VALUE);
SQLStateConstants.SQL_STATE_INVALID_STRING_LENGTH);
}
checkClosed();
if (blobData == null) return null;
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/firebirdsql/jdbc/FBCallableStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public int executeUpdate() throws SQLException {
* throw exception if we want to pass the test suite
*
* if (internalExecute(true)) throw new FBSQLException(
* "Update statement returned results.");
* "Update statement returned result set");
*/

boolean hasResults = internalExecute(!isSelectableProcedure());
Expand Down Expand Up @@ -1091,7 +1091,7 @@ public ResultSet getGeneratedKeys() throws SQLException {
*/
protected void assertHasData(ResultSet rs) throws SQLException {
if (rs == null) {
throw new SQLException("Current statement has no data to return.",
throw new SQLException("Current statement has no data to return",
SQLStateConstants.SQL_STATE_NO_RESULT_SET);
}
// check if we have a row, and try to move to the first position.
Expand All @@ -1103,7 +1103,7 @@ protected void assertHasData(ResultSet rs) throws SQLException {

// check if we still have no row and throw an exception in this case.
if (rs.getRow() == 0) {
throw new SQLException("Current statement has no data to return.",
throw new SQLException("Current statement has no data to return",
SQLStateConstants.SQL_STATE_NO_RESULT_SET);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/firebirdsql/jdbc/FBClob.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ public OutputStream setAsciiStream(long pos) throws SQLException {
public Writer setCharacterStream(long pos) throws SQLException {
if (pos < 1) {
throw new SQLNonTransientException("You can't start before the beginning of the blob",
SQLStateConstants.SQL_STATE_INVALID_ARG_VALUE);
SQLStateConstants.SQL_STATE_INVALID_STRING_LENGTH);
}
if (pos > 1) {
throw new FBDriverNotCapableException("Offset start positions are not supported.");
throw new FBDriverNotCapableException("Offset start positions are not supported");
}
return wrappedBlob.config().createWriter(
wrappedBlob.setBinaryStream(1));
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/firebirdsql/jdbc/FBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public boolean isClosed() {
@Override
public boolean isValid(int timeout) throws SQLException {
if (timeout < 0) {
throw new SQLException("Timeout should be >= 0", SQLStateConstants.SQL_STATE_INVALID_ARG_VALUE);
throw new SQLException("Timeout should be >= 0", SQLStateConstants.SQL_STATE_INVALID_ATTR_VALUE);
}
if (isLockedByCurrentThread()) {
// Trying to async check validity will not work (this shouldn't normally happen, except maybe when Jaybird
Expand Down
9 changes: 5 additions & 4 deletions src/main/org/firebirdsql/jdbc/FBPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class FBPreparedStatement extends FBStatement implements FirebirdPrepared

public static final String METHOD_NOT_SUPPORTED =
"This method is only supported on Statement and not supported on PreparedStatement and CallableStatement";
private static final String UNICODE_STREAM_NOT_SUPPORTED = "Unicode stream not supported.";
private static final String UNICODE_STREAM_NOT_SUPPORTED = "Unicode stream not supported";

private final boolean metaDataQuery;

Expand Down Expand Up @@ -197,7 +197,7 @@ public int executeUpdate() throws SQLException {
notifyStatementStarted();
try {
if (internalExecute(isExecuteProcedureStatement) && !isGeneratedKeyQuery()) {
throw new FBSQLException("Update statement returned results.");
throw new FBSQLException("Update statement returned result set");
}
return getUpdateCountMinZero();
} finally {
Expand Down Expand Up @@ -353,7 +353,8 @@ protected FieldDescriptor getParameterDescriptor(int columnIndex) {
protected FBField getField(int columnIndex) throws SQLException {
checkValidity();
if (columnIndex > fields.length) {
throw new SQLException("Invalid column index: " + columnIndex, SQLStateConstants.SQL_STATE_INVALID_COLUMN);
throw new SQLException("Invalid column index: " + columnIndex,
SQLStateConstants.SQL_STATE_INVALID_DESC_FIELD_ID);
}

return fields[columnIndex - 1];
Expand Down Expand Up @@ -538,7 +539,7 @@ ResultSet executeMetaDataQuery() throws SQLException {
boolean hasResultSet = internalExecute(isExecuteProcedureStatement);

if (!hasResultSet)
throw new FBSQLException("No result set is available.");
throw new FBSQLException("No result set is available");

return getResultSet(true);
}
Expand Down
17 changes: 9 additions & 8 deletions src/main/org/firebirdsql/jdbc/FBProcedureCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ public int mapOutParamIndexToPosition(int index, boolean compatibilityMode) thro
if (compatibilityMode) {
return index;
} else {
throw new FBSQLException("Specified parameter does not exist.", SQLStateConstants.SQL_STATE_INVALID_COLUMN);
throw new FBSQLException("Specified parameter does not exist",
SQLStateConstants.SQL_STATE_INVALID_DESC_FIELD_ID);
}
}

Expand Down Expand Up @@ -299,8 +300,8 @@ public void registerOutParam(int index, int type) throws SQLException {
}

if (param == null || param == NullParam.NULL_PARAM) {
throw new SQLException("Cannot find parameter with the specified position.",
SQLStateConstants.SQL_STATE_INVALID_COLUMN);
throw new SQLException("Cannot find parameter with the specified position",
SQLStateConstants.SQL_STATE_INVALID_DESC_FIELD_ID);
}

param.setType(type);
Expand Down Expand Up @@ -361,7 +362,7 @@ public void checkParameters() throws SQLException {
&& outputParams.size() > 0
&& outputParams.get(param.getPosition()) == null)
throw new FBSQLException("Value of parameter " + param.getIndex() + " not set and "
+ "it was not registered as output parameter.",
+ "it was not registered as output parameter",
SQLStateConstants.SQL_STATE_WRONG_PARAM_NUM);
}
}
Expand Down Expand Up @@ -405,18 +406,18 @@ private NullParam() {

@Override
public void setValue(Object value) throws SQLException {
throw new FBSQLException("You cannot set value of a non-existing parameter.",
SQLStateConstants.SQL_STATE_INVALID_ARG_VALUE);
throw new FBSQLException("You cannot set value of a non-existing parameter",
SQLStateConstants.SQL_STATE_ATT_CANNOT_SET_NOW);
}

@Override
public void setIndex(int index) {
throw new UnsupportedOperationException("You cannot set index of a non-existing parameter.");
throw new UnsupportedOperationException("You cannot set index of a non-existing parameter");
}

@Override
public void setType(int type) {
throw new UnsupportedOperationException("You cannot set type of a non-existing parameter.");
throw new UnsupportedOperationException("You cannot set type of a non-existing parameter");
}
}
}
21 changes: 12 additions & 9 deletions src/main/org/firebirdsql/jdbc/FBResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
@SuppressWarnings("RedundantThrows")
public class FBResultSet implements ResultSet, FirebirdResultSet, FBObjectListener.FetcherListener {

private static final String UNICODE_STREAM_NOT_SUPPORTED = "Unicode stream not supported.";
private static final String UNICODE_STREAM_NOT_SUPPORTED = "Unicode stream not supported";

private final FBStatement fbStatement;
private FBFetcher fbFetcher;
Expand Down Expand Up @@ -451,10 +451,10 @@ void close(boolean notifyListener, CompletionReason completionReason) throws SQL
@Override
public boolean wasNull() throws SQLException {
if (!wasNullValid) {
throw new SQLException("Look at a column before testing null.");
throw new SQLException("Get a column before testing null");
}
if (row == null) {
throw new SQLException("No row available for wasNull.");
throw new SQLException("No row available for wasNull");
}
return wasNull;
}
Expand Down Expand Up @@ -616,7 +616,8 @@ public FBField getField(int columnIndex, boolean checkRowPosition) throws SQLExc
}

if (columnIndex > rowDescriptor.getCount()) {
throw new SQLException("Invalid column index: " + columnIndex, SQLStateConstants.SQL_STATE_INVALID_COLUMN);
throw new SQLException("Invalid column index: " + columnIndex,
SQLStateConstants.SQL_STATE_INVALID_DESC_FIELD_ID);
}

if (rowUpdater != null) {
Expand All @@ -641,7 +642,8 @@ public FBField getField(String columnName) throws SQLException {
}

if (columnName == null) {
throw new SQLException("Column identifier must be not null.", SQLStateConstants.SQL_STATE_INVALID_COLUMN);
throw new SQLException("Column identifier must be not null",
SQLStateConstants.SQL_STATE_INVALID_DESC_FIELD_ID);
}

Integer fieldNum = colNames.get(columnName);
Expand Down Expand Up @@ -830,7 +832,8 @@ public Object getObject(String columnName) throws SQLException {
@Override
public int findColumn(String columnName) throws SQLException {
if (columnName == null || columnName.equals("")) {
throw new SQLException("Empty string does not identify column.", SQLStateConstants.SQL_STATE_INVALID_COLUMN);
throw new SQLException("Empty string does not identify a column",
SQLStateConstants.SQL_STATE_INVALID_DESC_FIELD_ID);
}
if (columnName.startsWith("\"") && columnName.endsWith("\"")) {
columnName = columnName.substring(1, columnName.length() - 1);
Expand Down Expand Up @@ -864,8 +867,8 @@ public int findColumn(String columnName) throws SQLException {
return findColumn("DB_KEY");
}

throw new SQLException("Column name " + columnName + " not found in result set.",
SQLStateConstants.SQL_STATE_INVALID_COLUMN);
throw new SQLException("Column name " + columnName + " not found in result set",
SQLStateConstants.SQL_STATE_INVALID_DESC_FIELD_ID);
}

@Override
Expand Down Expand Up @@ -1001,7 +1004,7 @@ public int getFetchDirection() throws SQLException {
public void setFetchSize(int rows) throws SQLException {
checkOpen();
if (rows < 0) {
throw new SQLException("Can't set negative fetch size.", SQLStateConstants.SQL_STATE_INVALID_ARG_VALUE);
throw new SQLException("Can't set negative fetch size", SQLStateConstants.SQL_STATE_INVALID_ATTR_VALUE);
}
fbFetcher.setFetchSize(rows);
}
Expand Down

0 comments on commit 7c36520

Please sign in to comment.