提交 f945dbb6 authored 作者: Thomas Mueller's avatar Thomas Mueller

For an invalid value exception, the parameter name and value was switched in some cases.

上级 49ae2b23
......@@ -2287,7 +2287,7 @@ public class Parser {
}
int index = currentValue.getInt() - 1;
if (index < 0 || index >= Constants.MAX_PARAMETER_INDEX) {
throw DbException.getInvalidValueException("" + index, "Parameter Index");
throw DbException.getInvalidValueException("parameter index", index);
}
if (indexedParameterList.size() <= index) {
indexedParameterList.ensureCapacity(index + 1);
......@@ -2544,7 +2544,7 @@ public class Parser {
private int getPositiveInt() {
int v = getInt();
if (v < 0) {
throw DbException.getInvalidValueException("" + v, "positive integer");
throw DbException.getInvalidValueException("positive integer", v);
}
return v;
}
......
......@@ -70,7 +70,7 @@ public class AlterSequence extends SchemaCommand {
if (increment != null) {
long incrementValue = increment.optimize(session).getValue(session).getLong();
if (incrementValue == 0) {
throw DbException.get(ErrorCode.INVALID_VALUE_2, "0", "INCREMENT");
throw DbException.getInvalidValueException("INCREMENT", 0);
}
sequence.setIncrement(incrementValue);
}
......
......@@ -386,7 +386,7 @@ public class Select extends Query {
ArrayList<Column> sortColumns = New.arrayList();
for (int idx : sort.getIndexes()) {
if (idx < 0 || idx >= expressions.size()) {
throw DbException.getInvalidValueException("" + (idx + 1), "ORDER BY");
throw DbException.getInvalidValueException("ORDER BY", idx + 1);
}
Expression expr = expressions.get(idx);
expr = expr.getNonAliasExpression();
......
......@@ -72,7 +72,7 @@ public class Set extends Prepared {
session.getUser().checkAdmin();
int value = getIntValue();
if (value < 0 || value > 2) {
throw DbException.getInvalidValueException("" + getIntValue(), "ALLOW_LITERALS");
throw DbException.getInvalidValueException("ALLOW_LITERALS", getIntValue());
}
database.setAllowLiterals(value);
addOrUpdateSetting(name, null, value);
......@@ -181,7 +181,7 @@ public class Set extends Prepared {
database.setExclusiveSession(session, true);
break;
default:
throw DbException.getInvalidValueException("" + value, "EXCLUSIVE");
throw DbException.getInvalidValueException("EXCLUSIVE", value);
}
break;
}
......@@ -201,7 +201,7 @@ public class Set extends Prepared {
case SetTypes.LOG: {
int value = getIntValue();
if (value < 0 || value > 2) {
throw DbException.getInvalidValueException("" + getIntValue(), "LOG");
throw DbException.getInvalidValueException("LOG", getIntValue());
}
if (value == 0) {
session.getUser().checkAdmin();
......@@ -211,7 +211,7 @@ public class Set extends Prepared {
}
case SetTypes.MAX_LENGTH_INPLACE_LOB: {
if (getIntValue() < 0) {
throw DbException.getInvalidValueException("" + getIntValue(), "MAX_LENGTH_INPLACE_LOB");
throw DbException.getInvalidValueException("MAX_LENGTH_INPLACE_LOB", getIntValue());
}
session.getUser().checkAdmin();
database.setMaxLengthInplaceLob(getIntValue());
......@@ -231,7 +231,7 @@ public class Set extends Prepared {
}
case SetTypes.MAX_MEMORY_UNDO: {
if (getIntValue() < 0) {
throw DbException.getInvalidValueException("" + getIntValue(), "MAX_MEMORY_UNDO");
throw DbException.getInvalidValueException("MAX_MEMORY_UNDO", getIntValue());
}
session.getUser().checkAdmin();
database.setMaxMemoryUndo(getIntValue());
......@@ -282,7 +282,7 @@ public class Set extends Prepared {
session.getUser().checkAdmin();
int value = getIntValue();
if (value < 0 || value > 1) {
throw DbException.getInvalidValueException("" + getIntValue(), "REFERENTIAL_INTEGRITY");
throw DbException.getInvalidValueException("REFERENTIAL_INTEGRITY", getIntValue());
}
database.setReferentialIntegrity(value == 1);
break;
......@@ -323,7 +323,7 @@ public class Set extends Prepared {
}
case SetTypes.THROTTLE: {
if (getIntValue() < 0) {
throw DbException.getInvalidValueException("" + getIntValue(), "THROTTLE");
throw DbException.getInvalidValueException("THROTTLE", getIntValue());
}
session.setThrottle(getIntValue());
break;
......@@ -331,7 +331,7 @@ public class Set extends Prepared {
case SetTypes.UNDO_LOG: {
int value = getIntValue();
if (value < 0 || value > 1) {
throw DbException.getInvalidValueException("" + getIntValue(), "UNDO_LOG");
throw DbException.getInvalidValueException("UNDO_LOG", getIntValue());
}
session.setUndoLogEnabled(value == 1);
break;
......
......@@ -66,7 +66,7 @@ public class ConnectionInfo implements Cloneable {
public ConnectionInfo(String u, Properties info) {
this.originalURL = u;
if (!u.startsWith(Constants.START_URL)) {
throw DbException.getInvalidValueException(u, "url");
throw DbException.getInvalidValueException("url", u);
}
this.url = u;
readProperties(info);
......
......@@ -1797,7 +1797,7 @@ public class Database implements DataHandler {
case Constants.LOCK_MODE_TABLE_GC:
break;
default:
throw DbException.getInvalidValueException("lock mode", "" + lockMode);
throw DbException.getInvalidValueException("lock mode", lockMode);
}
this.lockMode = lockMode;
}
......
......@@ -251,12 +251,12 @@ public class JdbcArray extends TraceObject implements Array {
private Object[] get(long index, int count) {
Object[] array = get();
if (count < 0 || count > array.length) {
throw DbException.getInvalidValueException("" + count, "count (1.."
+ array.length + ")");
throw DbException.getInvalidValueException("count (1.."
+ array.length + ")", count);
}
if (index < 1 || index > array.length) {
throw DbException.getInvalidValueException("" + index, "index (1.."
+ array.length + ")");
throw DbException.getInvalidValueException("index (1.."
+ array.length + ")", index);
}
Object[] subset = new Object[count];
System.arraycopy(array, (int) (index - 1), subset, 0, count);
......
......@@ -1485,7 +1485,7 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
private void checkIndexBounds(int parameterIndex) throws SQLException {
checkClosed();
if (parameterIndex < 1 || parameterIndex > maxOutParameters) {
throw DbException.getInvalidValueException("" + parameterIndex, "parameterIndex");
throw DbException.getInvalidValueException("parameterIndex", parameterIndex);
}
}
......@@ -1513,7 +1513,7 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
try {
checkIndexBounds(parameterIndex);
if (!outParameters.get(parameterIndex - 1)) {
throw DbException.getInvalidValueException("" + parameterIndex, "parameterIndex");
throw DbException.getInvalidValueException("parameterIndex", parameterIndex);
}
} catch (Exception e) {
throw logAndConvert(e);
......@@ -1534,7 +1534,7 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
Integer index = namedParameters.get(parameterName);
if (index == null) {
throw DbException.getInvalidValueException(parameterName, "parameterName");
throw DbException.getInvalidValueException("parameterName", parameterName);
}
return index;
} catch (Exception e) {
......
......@@ -629,7 +629,7 @@ public class JdbcConnection extends TraceObject implements Connection {
lockMode = Constants.LOCK_MODE_TABLE;
break;
default:
throw DbException.getInvalidValueException("" + level, "level");
throw DbException.getInvalidValueException("level", level);
}
commit();
setLockMode = prepareCommand("SET LOCK_MODE ?", setLockMode);
......@@ -1142,7 +1142,7 @@ public class JdbcConnection extends TraceObject implements Connection {
*/
String translateSQL(String sql, boolean escapeProcessing) {
if (sql == null) {
throw DbException.getInvalidValueException(sql, "SQL");
throw DbException.getInvalidValueException("SQL", sql);
}
if (!escapeProcessing) {
return sql;
......@@ -1275,14 +1275,14 @@ public class JdbcConnection extends TraceObject implements Connection {
case ResultSet.TYPE_SCROLL_SENSITIVE:
break;
default:
throw DbException.getInvalidValueException("" + resultSetType, "resultSetType");
throw DbException.getInvalidValueException("resultSetType", resultSetType);
}
switch (resultSetConcurrency) {
case ResultSet.CONCUR_READ_ONLY:
case ResultSet.CONCUR_UPDATABLE:
break;
default:
throw DbException.getInvalidValueException("" + resultSetConcurrency, "resultSetConcurrency");
throw DbException.getInvalidValueException("resultSetConcurrency", resultSetConcurrency);
}
}
......@@ -1292,7 +1292,7 @@ public class JdbcConnection extends TraceObject implements Connection {
//## Java 1.4 begin ##
if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT
&& resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
throw DbException.getInvalidValueException("" + resultSetHoldability, "resultSetHoldability");
throw DbException.getInvalidValueException("resultSetHoldability", resultSetHoldability);
}
//## Java 1.4 end ##
}
......
......@@ -205,7 +205,7 @@ implements ParameterMetaData
private ParameterInterface getParameter(int param) throws SQLException {
checkClosed();
if (param < 1 || param > paramCount) {
throw DbException.getInvalidValueException("" + param, "param");
throw DbException.getInvalidValueException("param", param);
}
return parameters.get(param - 1);
}
......
......@@ -1256,7 +1256,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
parameterIndex--;
ArrayList< ? extends ParameterInterface> parameters = command.getParameters();
if (parameterIndex < 0 || parameterIndex >= parameters.size()) {
throw DbException.getInvalidValueException("" + (parameterIndex + 1), "parameterIndex");
throw DbException.getInvalidValueException("parameterIndex", parameterIndex + 1);
}
ParameterInterface param = parameters.get(parameterIndex);
// can only delete old temp files if they are not in the batch
......
......@@ -709,7 +709,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
debugCode("getBigDecimal(" + StringUtils.quoteJavaString(columnLabel)+", "+scale+");");
}
if (scale < 0) {
throw DbException.getInvalidValueException("" + scale, "scale");
throw DbException.getInvalidValueException("scale", scale);
}
BigDecimal bd = get(columnLabel).getBigDecimal();
return bd == null ? null : MathUtils.setScale(bd, scale);
......@@ -734,7 +734,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
debugCode("getBigDecimal(" + columnIndex + ", " + scale + ");");
}
if (scale < 0) {
throw DbException.getInvalidValueException("" + scale, "scale");
throw DbException.getInvalidValueException("scale", scale);
}
BigDecimal bd = get(columnIndex).getBigDecimal();
return bd == null ? null : MathUtils.setScale(bd, scale);
......@@ -2377,14 +2377,13 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
try {
debugCodeCall("setFetchSize", rows);
checkClosed();
if (rows < 0) {
throw DbException.getInvalidValueException("" + rows, "rows");
throw DbException.getInvalidValueException("rows", rows);
} else if (rows > 0) {
if (stat != null) {
int maxRows = stat.getMaxRows();
if (maxRows > 0 && rows > maxRows) {
throw DbException.getInvalidValueException("" + rows, "rows");
throw DbException.getInvalidValueException("rows", rows);
}
}
} else {
......@@ -2914,7 +2913,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
private void checkColumnIndex(int columnIndex) throws SQLException {
checkClosed();
if (columnIndex < 1 || columnIndex > columnCount) {
throw DbException.getInvalidValueException("" + columnIndex, "columnIndex");
throw DbException.getInvalidValueException("columnIndex", columnIndex);
}
}
......
......@@ -425,7 +425,7 @@ public class JdbcResultSetMetaData extends TraceObject implements ResultSetMetaD
private void checkColumnIndex(int columnIndex) throws SQLException {
checkClosed();
if (columnIndex < 1 || columnIndex > columnCount) {
throw DbException.getInvalidValueException("" + columnIndex, "columnIndex");
throw DbException.getInvalidValueException("columnIndex", columnIndex);
}
}
......
......@@ -378,7 +378,7 @@ public class JdbcStatement extends TraceObject implements Statement {
debugCodeCall("setMaxRows", maxRows);
checkClosed();
if (maxRows < 0) {
throw DbException.getInvalidValueException("" + maxRows, "maxRows");
throw DbException.getInvalidValueException("maxRows", maxRows);
}
this.maxRows = maxRows;
} catch (Exception e) {
......@@ -402,7 +402,7 @@ public class JdbcStatement extends TraceObject implements Statement {
debugCodeCall("setFetchSize", rows);
checkClosed();
if (rows < 0 || (rows > 0 && maxRows > 0 && rows > maxRows)) {
throw DbException.getInvalidValueException("" + rows, "rows");
throw DbException.getInvalidValueException("rows", rows);
}
if (rows == 0) {
rows = SysProperties.SERVER_RESULT_SET_FETCH_SIZE;
......@@ -570,7 +570,7 @@ public class JdbcStatement extends TraceObject implements Statement {
debugCodeCall("setQueryTimeout", seconds);
checkClosed();
if (seconds < 0) {
throw DbException.getInvalidValueException("" + seconds, "seconds");
throw DbException.getInvalidValueException("seconds", seconds);
}
conn.setQueryTimeout(seconds);
} catch (Exception e) {
......@@ -695,7 +695,7 @@ public class JdbcStatement extends TraceObject implements Statement {
// nothing to do
break;
default:
throw DbException.getInvalidValueException("" + current, "current");
throw DbException.getInvalidValueException("current", current);
}
return false;
} catch (Exception e) {
......
......@@ -205,12 +205,12 @@ public class DbException extends RuntimeException {
/**
* Gets a SQL exception meaning this value is invalid.
*
* @param value the value passed
* @param param the name of the parameter
* @param value the value passed
* @return the IllegalArgumentException object
*/
public static DbException getInvalidValueException(String value, String param) {
return get(ErrorCode.INVALID_VALUE_2, value, param);
public static DbException getInvalidValueException(String param, Object value) {
return get(ErrorCode.INVALID_VALUE_2, value == null ? "null" : value.toString(), param);
}
/**
......
......@@ -6,7 +6,6 @@
*/
package org.h2.schema;
import org.h2.constant.ErrorCode;
import org.h2.engine.DbObject;
import org.h2.engine.Session;
import org.h2.message.DbException;
......@@ -50,7 +49,7 @@ public class Sequence extends SchemaObjectBase {
public void setIncrement(long inc) {
if (inc == 0) {
throw DbException.get(ErrorCode.INVALID_VALUE_2, "0", "INCREMENT");
throw DbException.getInvalidValueException("INCREMENT", 0);
}
this.increment = inc;
}
......
......@@ -79,7 +79,7 @@ public class CipherFactory {
if ("SHA256".equalsIgnoreCase(algorithm)) {
return new SHA256();
}
throw DbException.getInvalidValueException(algorithm, "algorithm");
throw DbException.getInvalidValueException("algorithm", algorithm);
}
/**
......
......@@ -1619,7 +1619,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
private void checkColumnIndex(int columnIndex) throws SQLException {
if (columnIndex < 0 || columnIndex >= columns.size()) {
throw DbException.getInvalidValueException("" + columnIndex, "columnIndex").getSQLException();
throw DbException.getInvalidValueException("columnIndex", columnIndex).getSQLException();
}
}
......
......@@ -68,7 +68,7 @@ public class CacheLRU implements Cache {
if (CacheLRU.TYPE_NAME.equals(cacheType)) {
cache = new CacheLRU(writer, cacheSize);
} else {
throw DbException.getInvalidValueException(cacheType, "CACHE_TYPE");
throw DbException.getInvalidValueException("CACHE_TYPE", cacheType);
}
if (secondLevel != null) {
cache = new CacheSecondLevel(cache, secondLevel);
......
......@@ -253,10 +253,8 @@ public class MathUtils {
* @return the scaled value
*/
public static BigDecimal setScale(BigDecimal bd, int scale) {
if (scale > BIG_DECIMAL_SCALE_MAX) {
throw DbException.getInvalidValueException("" + scale, "scale");
} else if (scale < -BIG_DECIMAL_SCALE_MAX) {
throw DbException.getInvalidValueException("" + scale, "scale");
if (scale > BIG_DECIMAL_SCALE_MAX || scale < -BIG_DECIMAL_SCALE_MAX) {
throw DbException.getInvalidValueException("scale", scale);
}
return bd.setScale(scale, BigDecimal.ROUND_HALF_UP);
}
......
......@@ -151,7 +151,7 @@ public class ValueTimestamp extends Value {
public Value convertScale(boolean onlyToSmallerScale, int targetScale) {
if (targetScale < 0 || targetScale > DEFAULT_SCALE) {
// TODO convertScale for Timestamps: may throw an exception?
throw DbException.getInvalidValueException("" + targetScale, "scale");
throw DbException.getInvalidValueException("scale", targetScale);
}
int nanos = value.getNanos();
BigDecimal bd = BigDecimal.valueOf(nanos);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论