提交 62c5f801 authored 作者: Thomas Mueller's avatar Thomas Mueller

Use runtime exceptions internally.

上级 43cc9eae
......@@ -18,7 +18,12 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>When doing an index lookup, decimal values with the same value but different scale
<ul><li>The file system abstraction no longer throws SQL exceptions.
</li><li>DatabaseEventListener.diskSpaceIsLow has changed.
</li><li>The CompressTool no longer throw as SQL exceptions. Instead, it throws runtime exceptions.
</li><li>SimpleResultSet.addColumn and addRow now can throw a IllegalStateException
instead of a SQLException.
</li><li>When doing an index lookup, decimal values with the same value but different scale
(for example 0.00 and 0.0) where not considered equal in version 1.2.128.
Now they are (unlike BigDecimal.equals()).
</li><li>The BNF parser now uses the visitor pattern.
......
......@@ -14,7 +14,7 @@ import java.util.Properties;
import org.h2.engine.Constants;
import org.h2.jdbc.JdbcConnection;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.message.TraceSystem;
/**
......@@ -57,7 +57,7 @@ public class Driver implements java.sql.Driver {
}
return new JdbcConnection(url, info);
} catch (Exception e) {
throw Message.convert(e);
throw DbException.toSQLException(e);
}
}
......
......@@ -24,10 +24,9 @@ public interface AggregateFunction {
void init(Connection conn) throws SQLException;
/**
* This method must return the SQL type of the method,
* given the SQL type of the input data.
* The method should check here if the number of parameters passed is correct,
* and if not it should throw an exception.
* This method must return the SQL type of the method, given the SQL type of
* the input data. The method should check here if the number of parameters
* passed is correct, and if not it should throw an exception.
*
* @param inputTypes the SQL type of the parameters
* @return the SQL type of the result
......@@ -49,4 +48,5 @@ public interface AggregateFunction {
* @return the aggregated value
*/
Object getResult() throws SQLException;
}
}
\ No newline at end of file
......@@ -61,17 +61,11 @@ public interface DatabaseEventListener extends EventListener {
void opened();
/**
* This method is called if the disk space is very low.
* One strategy is to inform the user and wait for it to clean up disk space.
* Another strategy is to send an email to the administrator in this method and
* then throw a SQLException. The database should not be accessed from
* within this method (even to close it).
*
* @param stillAvailable the estimated space that is still available, in bytes
* (if known)
* @throws SQLException if the operation should be canceled
* This method is called if the disk space is very low. One strategy is to
* inform the user and wait for it to clean up disk space. The database
* should not be accessed from within this method (even to close it).
*/
void diskSpaceIsLow(long stillAvailable) throws SQLException;
void diskSpaceIsLow();
/**
* This method is called if an exception occurred.
......
......@@ -13,7 +13,7 @@ import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.ParameterInterface;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.message.TraceObject;
import org.h2.result.ResultInterface;
......@@ -85,7 +85,7 @@ public abstract class Command implements CommandInterface {
*
* @return an empty result set
*/
public abstract ResultInterface queryMeta() throws SQLException;
public abstract ResultInterface queryMeta();
/**
* Execute an updating statement, if this is possible.
......@@ -93,8 +93,8 @@ public abstract class Command implements CommandInterface {
* @return the update count
* @throws SQLException if the command is not an updating statement
*/
public int update() throws SQLException {
throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_QUERY);
public int update() {
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_QUERY);
}
/**
......@@ -104,11 +104,11 @@ public abstract class Command implements CommandInterface {
* @return the local result set
* @throws SQLException if the command is not a query
*/
public ResultInterface query(int maxrows) throws SQLException {
throw Message.getSQLException(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY);
public ResultInterface query(int maxrows) {
throw DbException.get(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY);
}
public final ResultInterface getMetaData() throws SQLException {
public final ResultInterface getMetaData() {
return queryMeta();
}
......@@ -120,7 +120,7 @@ public abstract class Command implements CommandInterface {
* @param scrollable if the result set must be scrollable (ignored)
* @return the result set
*/
public ResultInterface executeQuery(int maxrows, boolean scrollable) throws SQLException {
public ResultInterface executeQuery(int maxrows, boolean scrollable) {
startTime = System.currentTimeMillis();
Database database = session.getDatabase();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
......@@ -130,10 +130,9 @@ public abstract class Command implements CommandInterface {
database.checkPowerOff();
session.setCurrentCommand(this, startTime);
return query(maxrows);
} catch (Exception e) {
SQLException s = Message.convert(e, sql);
database.exceptionThrown(s, sql);
throw s;
} catch (DbException e) {
database.exceptionThrown(e.getSQLException(), sql);
throw e;
} finally {
stop();
}
......@@ -152,14 +151,14 @@ public abstract class Command implements CommandInterface {
*
* @throws SQLException if the statement has been canceled
*/
public void checkCanceled() throws SQLException {
public void checkCanceled() {
if (cancel) {
cancel = false;
throw Message.getSQLException(ErrorCode.STATEMENT_WAS_CANCELED);
throw DbException.get(ErrorCode.STATEMENT_WAS_CANCELED);
}
}
private void stop() throws SQLException {
private void stop() {
session.closeTemporaryResults();
session.setCurrentCommand(null, 0);
if (!isTransactional()) {
......@@ -182,7 +181,7 @@ public abstract class Command implements CommandInterface {
}
}
public int executeUpdate() throws SQLException {
public int executeUpdate() {
long start = startTime = System.currentTimeMillis();
Database database = session.getDatabase();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
......@@ -197,11 +196,11 @@ public abstract class Command implements CommandInterface {
database.checkPowerOff();
try {
return update();
} catch (SQLException e) {
} catch (DbException e) {
if (e.getErrorCode() == ErrorCode.CONCURRENT_UPDATE_1) {
long now = System.currentTimeMillis();
if (now - start > session.getLockTimeout()) {
throw Message.getSQLException(ErrorCode.LOCK_TIMEOUT_1, e, "");
throw DbException.get(ErrorCode.LOCK_TIMEOUT_1, e.getCause(), "");
}
try {
if (sync == database) {
......@@ -215,19 +214,18 @@ public abstract class Command implements CommandInterface {
continue;
}
throw e;
} catch (Exception e) {
throw Message.convert(e);
} catch (Throwable e) {
throw Message.convertThrowable(e);
throw DbException.convert(e);
}
}
} catch (SQLException e) {
Message.addSQL(e, sql);
database.exceptionThrown(e, sql);
} catch (DbException e) {
e = e.addSQL(sql);
SQLException s = e.getSQLException();
database.exceptionThrown(s, sql);
database.checkPowerOff();
if (e.getErrorCode() == ErrorCode.DEADLOCK_1) {
if (s.getErrorCode() == ErrorCode.DEADLOCK_1) {
session.rollback();
} else if (e.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
} else if (s.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
// there is a serious problem:
// the transaction may be applied partially
// in this case we need to panic:
......
......@@ -6,7 +6,6 @@
*/
package org.h2.command;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.expression.Parameter;
import org.h2.expression.ParameterInterface;
......@@ -39,7 +38,7 @@ public class CommandContainer extends Command {
return prepared.isQuery();
}
private void recompileIfRequired() throws SQLException {
private void recompileIfRequired() {
if (prepared.needRecompile()) {
// TODO test with 'always recompile'
prepared.setModificationMetaId(0);
......@@ -63,7 +62,7 @@ public class CommandContainer extends Command {
}
}
public int update() throws SQLException {
public int update() {
recompileIfRequired();
// TODO query time: should keep lock time separate from running time
start();
......@@ -73,7 +72,7 @@ public class CommandContainer extends Command {
return updateCount;
}
public ResultInterface query(int maxrows) throws SQLException {
public ResultInterface query(int maxrows) {
recompileIfRequired();
// TODO query time: should keep lock time separate from running time
start();
......@@ -87,7 +86,7 @@ public class CommandContainer extends Command {
return prepared.isReadOnly();
}
public ResultInterface queryMeta() throws SQLException {
public ResultInterface queryMeta() {
return prepared.queryMeta();
}
......
......@@ -6,7 +6,6 @@
*/
package org.h2.command;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.expression.ParameterInterface;
import org.h2.result.ResultInterface;
......@@ -37,14 +36,14 @@ public interface CommandInterface {
* @param scrollable if the result set must be scrollable
* @return the result
*/
ResultInterface executeQuery(int maxRows, boolean scrollable) throws SQLException;
ResultInterface executeQuery(int maxRows, boolean scrollable);
/**
* Execute the statement
*
* @return the update count
*/
int executeUpdate() throws SQLException;
int executeUpdate();
/**
* Close the statement.
......@@ -61,5 +60,5 @@ public interface CommandInterface {
*
* @return the empty result
*/
ResultInterface getMetaData() throws SQLException;
ResultInterface getMetaData();
}
......@@ -6,7 +6,6 @@
*/
package org.h2.command;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.expression.ParameterInterface;
import org.h2.result.ResultInterface;
......@@ -29,7 +28,7 @@ public class CommandList extends Command {
return command.getParameters();
}
private void executeRemaining() throws SQLException {
private void executeRemaining() {
Command remainingCommand = session.prepareLocal(remaining);
if (remainingCommand.isQuery()) {
remainingCommand.query(0);
......@@ -38,13 +37,13 @@ public class CommandList extends Command {
}
}
public int update() throws SQLException {
public int update() {
int updateCount = command.executeUpdate();
executeRemaining();
return updateCount;
}
public ResultInterface query(int maxrows) throws SQLException {
public ResultInterface query(int maxrows) {
ResultInterface result = command.query(maxrows);
executeRemaining();
return result;
......@@ -62,7 +61,7 @@ public class CommandList extends Command {
return false;
}
public ResultInterface queryMeta() throws SQLException {
public ResultInterface queryMeta() {
return command.queryMeta();
}
......
......@@ -7,13 +7,13 @@
package org.h2.command;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.SessionRemote;
import org.h2.expression.ParameterInterface;
import org.h2.expression.ParameterRemote;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.message.TraceObject;
import org.h2.result.ResultInterface;
......@@ -40,7 +40,7 @@ public class CommandRemote implements CommandInterface {
private int paramCount;
private int created;
public CommandRemote(SessionRemote session, ArrayList<Transfer> transferList, String sql, int fetchSize) throws SQLException {
public CommandRemote(SessionRemote session, ArrayList<Transfer> transferList, String sql, int fetchSize) {
this.transferList = transferList;
trace = session.getTrace();
this.sql = sql;
......@@ -53,7 +53,7 @@ public class CommandRemote implements CommandInterface {
created = session.getLastReconnect();
}
private void prepare(SessionRemote s, boolean createParams) throws SQLException {
private void prepare(SessionRemote s, boolean createParams) {
id = s.getNextId();
paramCount = 0;
boolean readParams = s.getClientVersion() >= Constants.TCP_PROTOCOL_VERSION;
......@@ -67,7 +67,7 @@ public class CommandRemote implements CommandInterface {
s.traceOperation("SESSION_PREPARE", id);
transfer.writeInt(SessionRemote.SESSION_PREPARE).writeInt(id).writeString(sql);
}
s.done(transfer);
s.convert(transfer);
isQuery = transfer.readBoolean();
readonly = transfer.readBoolean();
paramCount = transfer.readInt();
......@@ -97,7 +97,7 @@ public class CommandRemote implements CommandInterface {
return parameters;
}
private void prepareIfRequired() throws SQLException {
private void prepareIfRequired() {
if (session.getLastReconnect() != created) {
// in this case we need to prepare again in every case
id = Integer.MIN_VALUE;
......@@ -109,7 +109,7 @@ public class CommandRemote implements CommandInterface {
}
}
public ResultInterface getMetaData() throws SQLException {
public ResultInterface getMetaData() {
synchronized (session) {
if (!isQuery) {
return null;
......@@ -122,7 +122,7 @@ public class CommandRemote implements CommandInterface {
try {
session.traceOperation("COMMAND_GET_META_DATA", id);
transfer.writeInt(SessionRemote.COMMAND_GET_META_DATA).writeInt(id).writeInt(objectId);
session.done(transfer);
session.convert(transfer);
int columnCount = transfer.readInt();
result = new ResultRemote(session, transfer, objectId, columnCount, Integer.MAX_VALUE);
break;
......@@ -135,7 +135,7 @@ public class CommandRemote implements CommandInterface {
}
}
public ResultInterface executeQuery(int maxRows, boolean scrollable) throws SQLException {
public ResultInterface executeQuery(int maxRows, boolean scrollable) {
checkParameters();
synchronized (session) {
int objectId = session.getNextId();
......@@ -155,7 +155,7 @@ public class CommandRemote implements CommandInterface {
}
transfer.writeInt(fetch);
sendParameters(transfer);
session.done(transfer);
session.convert(transfer);
int columnCount = transfer.readInt();
if (result != null) {
result.close();
......@@ -175,7 +175,7 @@ public class CommandRemote implements CommandInterface {
}
}
public int executeUpdate() throws SQLException {
public int executeUpdate() {
checkParameters();
synchronized (session) {
int updateCount = 0;
......@@ -187,7 +187,7 @@ public class CommandRemote implements CommandInterface {
session.traceOperation("COMMAND_EXECUTE_UPDATE", id);
transfer.writeInt(SessionRemote.COMMAND_EXECUTE_UPDATE).writeInt(id);
sendParameters(transfer);
session.done(transfer);
session.convert(transfer);
updateCount = transfer.readInt();
autoCommit = transfer.readBoolean();
} catch (IOException e) {
......@@ -201,13 +201,13 @@ public class CommandRemote implements CommandInterface {
}
}
private void checkParameters() throws SQLException {
private void checkParameters() {
for (ParameterInterface p : parameters) {
p.checkSet();
}
}
private void sendParameters(Transfer transfer) throws IOException, SQLException {
private void sendParameters(Transfer transfer) throws IOException {
int len = parameters.size();
transfer.writeInt(len);
for (ParameterInterface p : parameters) {
......@@ -237,7 +237,7 @@ public class CommandRemote implements CommandInterface {
v.close();
}
}
} catch (SQLException e) {
} catch (DbException e) {
trace.error("close", e);
}
parameters.clear();
......
......@@ -6,7 +6,6 @@
*/
package org.h2.command;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
......@@ -14,8 +13,7 @@ import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.expression.Parameter;
import org.h2.jdbc.JdbcSQLException;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.result.ResultInterface;
import org.h2.util.StatementBuilder;
import org.h2.value.Value;
......@@ -81,7 +79,7 @@ public abstract class Prepared {
*
* @return the result set
*/
public abstract ResultInterface queryMeta() throws SQLException;
public abstract ResultInterface queryMeta();
/**
* Check if this command is read only.
......@@ -97,10 +95,10 @@ public abstract class Prepared {
*
* @return true if it must
*/
public boolean needRecompile() throws SQLException {
public boolean needRecompile() {
Database db = session.getDatabase();
if (db == null) {
throw Message.getSQLException(ErrorCode.CONNECTION_BROKEN_1, "database closed");
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1, "database closed");
}
// parser: currently, compiling every create/drop/... twice
// because needRecompile return true even for the first execution
......@@ -149,7 +147,7 @@ public abstract class Prepared {
*
* @throws SQLException if any parameter has not been set
*/
protected void checkParameters() throws SQLException {
protected void checkParameters() {
for (int i = 0; parameters != null && i < parameters.size(); i++) {
Parameter param = parameters.get(i);
param.checkSet();
......@@ -179,7 +177,7 @@ public abstract class Prepared {
*
* @throws SQLException
*/
public void prepare() throws SQLException {
public void prepare() {
// nothing to do
}
......@@ -189,8 +187,8 @@ public abstract class Prepared {
* @return the update count
* @throws SQLException if it is a query
*/
public int update() throws SQLException {
throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_QUERY);
public int update() {
throw DbException.get(ErrorCode.METHOD_NOT_ALLOWED_FOR_QUERY);
}
/**
......@@ -200,8 +198,8 @@ public abstract class Prepared {
* @return the result set
* @throws SQLException if it is not a query
*/
public ResultInterface query(int maxrows) throws SQLException {
throw Message.getSQLException(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY);
public ResultInterface query(int maxrows) {
throw DbException.get(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY);
}
/**
......@@ -263,7 +261,7 @@ public abstract class Prepared {
*
* @throws SQLException if it was canceled
*/
public void checkCanceled() throws SQLException {
public void checkCanceled() {
session.checkCanceled();
Command c = command != null ? command : session.getCurrentCommand();
if (c != null) {
......@@ -297,7 +295,7 @@ public abstract class Prepared {
* @param startTime when the statement was started
* @param count the update count
*/
void trace(long startTime, int count) throws SQLException {
void trace(long startTime, int count) {
if (session.getTrace().isInfoEnabled()) {
long time = System.currentTimeMillis() - startTime;
String params;
......@@ -332,7 +330,7 @@ public abstract class Prepared {
*
* @param rowNumber the row number
*/
protected void setCurrentRowNumber(int rowNumber) throws SQLException {
protected void setCurrentRowNumber(int rowNumber) {
if ((++rowScanCount & 127) == 0) {
checkCanceled();
}
......@@ -394,26 +392,22 @@ public abstract class Prepared {
/**
* Set the SQL statement of the exception to the given row.
*
* @param ex the exception
* @param e the exception
* @param rowId the row number
* @param values the values of the row
* @return the exception
*/
protected SQLException setRow(SQLException ex, int rowId, String values) {
if (ex instanceof JdbcSQLException) {
JdbcSQLException e = (JdbcSQLException) ex;
StringBuilder buff = new StringBuilder();
if (sqlStatement != null) {
buff.append(sqlStatement);
}
buff.append(" -- ");
if (rowId > 0) {
buff.append("row #").append(rowId + 1).append(' ');
}
buff.append('(').append(values).append(')');
e.setSQL(buff.toString());
protected DbException setRow(DbException e, int rowId, String values) {
StringBuilder buff = new StringBuilder();
if (sqlStatement != null) {
buff.append(sqlStatement);
}
buff.append(" -- ");
if (rowId > 0) {
buff.append("row #").append(rowId + 1).append(' ');
}
return ex;
buff.append('(').append(values).append(')');
return e.addSQL(buff.toString());
}
}
......@@ -6,13 +6,12 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.index.Index;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
/**
......@@ -36,12 +35,12 @@ public class AlterIndexRename extends DefineCommand {
newIndexName = name;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
Schema schema = oldIndex.getSchema();
if (schema.findIndex(session, newIndexName) != null || newIndexName.equals(oldIndex.getName())) {
throw Message.getSQLException(ErrorCode.INDEX_ALREADY_EXISTS_1, newIndexName);
throw DbException.get(ErrorCode.INDEX_ALREADY_EXISTS_1, newIndexName);
}
session.getUser().checkRight(oldIndex.getTable(), Right.ALL);
db.renameSchemaObject(session, oldIndex, newIndexName);
......
......@@ -6,7 +6,6 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import org.h2.constant.ErrorCode;
......@@ -21,7 +20,7 @@ import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.index.Index;
import org.h2.index.IndexType;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.Column;
import org.h2.table.IndexColumn;
......@@ -83,7 +82,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
return constraintName;
}
public int update() throws SQLException {
public int update() {
try {
return tryUpdate();
} finally {
......@@ -96,7 +95,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
*
* @return the update count
*/
public int tryUpdate() throws SQLException {
public int tryUpdate() {
session.commit(true);
Database db = session.getDatabase();
Table table = getSchema().getTableOrView(session, tableName);
......@@ -104,7 +103,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
if (ifNotExists) {
return 0;
}
throw Message.getSQLException(ErrorCode.CONSTRAINT_ALREADY_EXISTS_1, constraintName);
throw DbException.get(ErrorCode.CONSTRAINT_ALREADY_EXISTS_1, constraintName);
}
session.getUser().checkRight(table, Right.ALL);
table.lock(session, true, true);
......@@ -117,7 +116,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint c = constraints.get(i);
if (Constraint.PRIMARY_KEY.equals(c.getConstraintType())) {
throw Message.getSQLException(ErrorCode.SECOND_PRIMARY_KEY);
throw DbException.get(ErrorCode.SECOND_PRIMARY_KEY);
}
}
if (index != null) {
......@@ -125,11 +124,11 @@ public class AlterTableAddConstraint extends SchemaCommand {
// we don't test ascending / descending
IndexColumn[] pkCols = index.getIndexColumns();
if (pkCols.length != indexColumns.length) {
throw Message.getSQLException(ErrorCode.SECOND_PRIMARY_KEY);
throw DbException.get(ErrorCode.SECOND_PRIMARY_KEY);
}
for (int i = 0; i < pkCols.length; i++) {
if (pkCols[i].column != indexColumns[i].column) {
throw Message.getSQLException(ErrorCode.SECOND_PRIMARY_KEY);
throw DbException.get(ErrorCode.SECOND_PRIMARY_KEY);
}
}
}
......@@ -210,7 +209,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
IndexColumn.mapColumns(refIndexColumns, refTable);
}
if (refIndexColumns.length != indexColumns.length) {
throw Message.getSQLException(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
}
boolean isRefOwner = false;
if (refIndex != null && refIndex.getTable() == refTable) {
......@@ -244,7 +243,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
break;
}
default:
throw Message.throwInternalError("type=" + type);
throw DbException.throwInternalError("type=" + type);
}
// parent relationship is already set with addConstraint
constraint.setComment(comment);
......@@ -257,7 +256,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
return 0;
}
private Index createIndex(Table t, IndexColumn[] cols, boolean unique) throws SQLException {
private Index createIndex(Table t, IndexColumn[] cols, boolean unique) {
int indexId = getObjectId();
IndexType indexType;
if (unique) {
......
......@@ -6,7 +6,6 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.h2.command.Parser;
......@@ -21,7 +20,7 @@ import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.index.Index;
import org.h2.index.IndexType;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.result.ResultInterface;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
......@@ -106,7 +105,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
this.addBefore = before;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
session.getUser().checkRight(table, Right.ALL);
......@@ -161,7 +160,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
case DROP: {
if (table.getColumns().length == 1) {
throw Message.getSQLException(ErrorCode.CANNOT_DROP_LAST_COLUMN, oldColumn.getSQL());
throw DbException.get(ErrorCode.CANNOT_DROP_LAST_COLUMN, oldColumn.getSQL());
}
table.checkColumnIsNotReferenced(oldColumn);
dropSingleColumnIndexes();
......@@ -175,12 +174,12 @@ public class AlterTableAlterColumn extends SchemaCommand {
break;
}
default:
Message.throwInternalError("type=" + type);
DbException.throwInternalError("type=" + type);
}
return 0;
}
private void convertAutoIncrementColumn(Column c) throws SQLException {
private void convertAutoIncrementColumn(Column c) {
if (c.isAutoIncrement()) {
if (c.isPrimaryKey()) {
c.setOriginalSQL("IDENTITY");
......@@ -191,7 +190,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void removeSequence(Sequence sequence) throws SQLException {
private void removeSequence(Sequence sequence) {
if (sequence != null) {
table.removeSequence(session, sequence);
sequence.setBelongsToTable(false);
......@@ -200,9 +199,9 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void copyData() throws SQLException {
private void copyData() {
if (table.isTemporary()) {
throw Message.getUnsupportedException("TEMP TABLE");
throw DbException.getUnsupportedException("TEMP TABLE");
}
Database db = session.getDatabase();
String tempName = db.getTempTableName(session);
......@@ -212,9 +211,9 @@ public class AlterTableAlterColumn extends SchemaCommand {
List<String> views;
try {
views = checkViews(table, newTable);
} catch (SQLException e) {
} catch (DbException e) {
execute("DROP TABLE " + newTable.getName(), true);
throw Message.getSQLException(ErrorCode.VIEW_IS_INVALID_2, e, getSQL(), e.getMessage());
throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, e, getSQL(), e.getMessage());
}
String tableName = table.getName();
execute("DROP TABLE " + table.getSQL(), true);
......@@ -247,7 +246,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private TableData cloneTableStructure(Column[] columns, Database db, String tempName, ArrayList<Column> newColumns) throws SQLException {
private TableData cloneTableStructure(Column[] columns, Database db, String tempName, ArrayList<Column> newColumns) {
for (Column col : columns) {
newColumns.add(col.getClone());
}
......@@ -331,7 +330,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
if (child instanceof TableView) {
continue;
} else if (child.getType() == DbObject.TABLE_OR_VIEW) {
Message.throwInternalError();
DbException.throwInternalError();
}
String quotedName = Parser.quoteIdentifier(tempName + "_" + child.getName());
String sql = null;
......@@ -373,7 +372,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
*
* @param the list of SQL statements to re-create views that depend on this table
*/
private List<String> checkViews(SchemaObject sourceTable, SchemaObject newTable) throws SQLException {
private List<String> checkViews(SchemaObject sourceTable, SchemaObject newTable) {
List<String> viewSql = new ArrayList<String>();
String sourceTableName = sourceTable.getName();
String newTableName = newTable.getName();
......@@ -402,7 +401,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
* @param recreate the list of SQL statements to re-create views that depend
* on this table
*/
private void checkViewsAreValid(DbObject tableOrView, List<String> recreate) throws SQLException {
private void checkViewsAreValid(DbObject tableOrView, List<String> recreate) {
for (DbObject view : tableOrView.getChildren()) {
if (view instanceof TableView) {
String sql = ((TableView) view).getQuery();
......@@ -417,7 +416,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void execute(String sql, boolean ddl) throws SQLException {
private void execute(String sql, boolean ddl) {
Prepared command = session.prepare(sql);
command.update();
if (ddl) {
......@@ -425,7 +424,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void dropSingleColumnIndexes() throws SQLException {
private void dropSingleColumnIndexes() {
Database db = session.getDatabase();
ArrayList<Index> indexes = table.getIndexes();
for (int i = 0; i < indexes.size(); i++) {
......@@ -440,7 +439,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
if (cols.length == 1) {
dropIndex = true;
} else {
throw Message.getSQLException(ErrorCode.COLUMN_IS_PART_OF_INDEX_1, index.getSQL());
throw DbException.get(ErrorCode.COLUMN_IS_PART_OF_INDEX_1, index.getSQL());
}
}
}
......@@ -452,25 +451,25 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
private void checkNullable() throws SQLException {
private void checkNullable() {
for (Index index : table.getIndexes()) {
if (index.getColumnIndex(oldColumn) < 0) {
continue;
}
IndexType indexType = index.getIndexType();
if (indexType.isPrimaryKey() || indexType.isHash()) {
throw Message.getSQLException(ErrorCode.COLUMN_IS_PART_OF_INDEX_1, index.getSQL());
throw DbException.get(ErrorCode.COLUMN_IS_PART_OF_INDEX_1, index.getSQL());
}
}
}
private void checkNoNullValues() throws SQLException {
private void checkNoNullValues() {
String sql = "SELECT COUNT(*) FROM " + table.getSQL() + " WHERE " + oldColumn.getSQL() + " IS NULL";
Prepared command = session.prepare(sql);
ResultInterface result = command.query(0);
result.next();
if (result.currentRow()[0].getInt() > 0) {
throw Message.getSQLException(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, oldColumn.getSQL());
throw DbException.get(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, oldColumn.getSQL());
}
}
......
......@@ -6,13 +6,11 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
/**
......@@ -33,12 +31,12 @@ public class AlterTableDropConstraint extends SchemaCommand {
constraintName = string;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Constraint constraint = getSchema().findConstraint(session, constraintName);
if (constraint == null) {
if (!ifExists) {
throw Message.getSQLException(ErrorCode.CONSTRAINT_NOT_FOUND_1, constraintName);
throw DbException.get(ErrorCode.CONSTRAINT_NOT_FOUND_1, constraintName);
}
} else {
session.getUser().checkRight(constraint.getTable(), Right.ALL);
......
......@@ -6,13 +6,11 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.Table;
......@@ -37,15 +35,15 @@ public class AlterTableRename extends SchemaCommand {
newTableName = name;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
if (getSchema().findTableOrView(session, newTableName) != null || newTableName.equals(oldTable.getName())) {
throw Message.getSQLException(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, newTableName);
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, newTableName);
}
session.getUser().checkRight(oldTable, Right.ALL);
if (oldTable.isTemporary()) {
throw Message.getUnsupportedException("TEMP TABLE");
throw DbException.getUnsupportedException("TEMP TABLE");
}
db.renameSchemaObject(session, oldTable, newTableName);
return 0;
......
......@@ -6,7 +6,6 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Right;
......@@ -40,7 +39,7 @@ public class AlterTableRenameColumn extends DefineCommand {
this.newName = newName;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
session.getUser().checkRight(table, Right.ALL);
......
......@@ -6,14 +6,12 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.engine.User;
import org.h2.expression.Expression;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.security.SHA256;
import org.h2.util.Utils;
......@@ -80,15 +78,15 @@ public class AlterUser extends DefineCommand {
this.password = password;
}
private char[] getCharArray(Expression e) throws SQLException {
private char[] getCharArray(Expression e) {
return e.optimize(session).getValue(session).getString().toCharArray();
}
private byte[] getByteArray(Expression e) throws SQLException {
private byte[] getByteArray(Expression e) {
return Utils.convertStringToBytes(e.optimize(session).getValue(session).getString());
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
switch (type) {
......@@ -109,7 +107,7 @@ public class AlterUser extends DefineCommand {
case RENAME:
session.getUser().checkAdmin();
if (db.findUser(newName) != null || newName.equals(user.getName())) {
throw Message.getSQLException(ErrorCode.USER_ALREADY_EXISTS_1, newName);
throw DbException.get(ErrorCode.USER_ALREADY_EXISTS_1, newName);
}
db.renameDatabaseObject(session, user, newName);
break;
......@@ -121,7 +119,7 @@ public class AlterUser extends DefineCommand {
user.setAdmin(admin);
break;
default:
Message.throwInternalError("type=" + type);
DbException.throwInternalError("type=" + type);
}
db.update(session, user);
return 0;
......
......@@ -6,8 +6,6 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.table.TableView;
......@@ -28,7 +26,7 @@ public class AlterView extends DefineCommand {
this.view = view;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
session.getUser().checkRight(view, Right.ALL);
view.recompile(session);
......
......@@ -6,7 +6,6 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.command.Prepared;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -32,7 +31,7 @@ public class Analyze extends DefineCommand {
super(session);
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
session.getUser().checkAdmin();
......
......@@ -6,13 +6,11 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.engine.UserAggregate;
import org.h2.message.Message;
import org.h2.message.DbException;
/**
* This class represents the statement
......@@ -29,13 +27,13 @@ public class CreateAggregate extends DefineCommand {
super(session);
}
public int update() throws SQLException {
public int update() {
session.commit(true);
session.getUser().checkAdmin();
Database db = session.getDatabase();
if (db.findAggregate(name) != null || db.findFunctionAlias(name) != null) {
if (!ifNotExists) {
throw Message.getSQLException(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name);
throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name);
}
} else {
int id = getObjectId();
......
......@@ -6,13 +6,11 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Constant;
import org.h2.schema.Schema;
import org.h2.value.Value;
......@@ -35,7 +33,7 @@ public class CreateConstant extends SchemaCommand {
this.ifNotExists = ifNotExists;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
session.getUser().checkAdmin();
Database db = session.getDatabase();
......@@ -43,7 +41,7 @@ public class CreateConstant extends SchemaCommand {
if (ifNotExists) {
return 0;
}
throw Message.getSQLException(ErrorCode.CONSTANT_ALREADY_EXISTS_1, constantName);
throw DbException.get(ErrorCode.CONSTANT_ALREADY_EXISTS_1, constantName);
}
int id = getObjectId();
Constant constant = new Constant(getSchema(), id, constantName);
......
......@@ -6,13 +6,11 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.FunctionAlias;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.message.DbException;
/**
* This class represents the statement
......@@ -31,13 +29,13 @@ public class CreateFunctionAlias extends DefineCommand {
super(session);
}
public int update() throws SQLException {
public int update() {
session.commit(true);
session.getUser().checkAdmin();
Database db = session.getDatabase();
if (db.findFunctionAlias(aliasName) != null) {
if (!ifNotExists) {
throw Message.getSQLException(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, aliasName);
throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, aliasName);
}
} else {
int id = getObjectId();
......
......@@ -6,15 +6,13 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.index.IndexType;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.IndexColumn;
import org.h2.table.Table;
......@@ -52,7 +50,7 @@ public class CreateIndex extends SchemaCommand {
this.indexColumns = columns;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
boolean persistent = db.isPersistent();
......@@ -74,12 +72,12 @@ public class CreateIndex extends SchemaCommand {
if (ifNotExists) {
return 0;
}
throw Message.getSQLException(ErrorCode.INDEX_ALREADY_EXISTS_1, indexName);
throw DbException.get(ErrorCode.INDEX_ALREADY_EXISTS_1, indexName);
}
IndexType indexType;
if (primaryKey) {
if (table.findPrimaryKey() != null) {
throw Message.getSQLException(ErrorCode.SECOND_PRIMARY_KEY);
throw DbException.get(ErrorCode.SECOND_PRIMARY_KEY);
}
indexType = IndexType.createPrimaryKey(persistent, hash);
} else if (unique) {
......
......@@ -6,12 +6,10 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.TableLink;
......@@ -63,7 +61,7 @@ public class CreateLinkedTable extends SchemaCommand {
this.ifNotExists = ifNotExists;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
session.getUser().checkAdmin();
......@@ -71,7 +69,7 @@ public class CreateLinkedTable extends SchemaCommand {
if (ifNotExists) {
return 0;
}
throw Message.getSQLException(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1,
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1,
tableName);
}
int id = getObjectId();
......
......@@ -6,13 +6,11 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Role;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.message.DbException;
/**
* This class represents the statement
......@@ -35,18 +33,18 @@ public class CreateRole extends DefineCommand {
this.roleName = name;
}
public int update() throws SQLException {
public int update() {
session.getUser().checkAdmin();
session.commit(true);
Database db = session.getDatabase();
if (db.findUser(roleName) != null) {
throw Message.getSQLException(ErrorCode.USER_ALREADY_EXISTS_1, roleName);
throw DbException.get(ErrorCode.USER_ALREADY_EXISTS_1, roleName);
}
if (db.findRole(roleName) != null) {
if (ifNotExists) {
return 0;
}
throw Message.getSQLException(ErrorCode.ROLE_ALREADY_EXISTS_1, roleName);
throw DbException.get(ErrorCode.ROLE_ALREADY_EXISTS_1, roleName);
}
int id = getObjectId();
Role role = new Role(db, id, roleName, false);
......
......@@ -6,13 +6,11 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.engine.User;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
/**
......@@ -33,7 +31,7 @@ public class CreateSchema extends DefineCommand {
this.ifNotExists = ifNotExists;
}
public int update() throws SQLException {
public int update() {
session.getUser().checkAdmin();
session.commit(true);
Database db = session.getDatabase();
......@@ -43,7 +41,7 @@ public class CreateSchema extends DefineCommand {
if (ifNotExists) {
return 0;
}
throw Message.getSQLException(ErrorCode.SCHEMA_ALREADY_EXISTS_1, schemaName);
throw DbException.get(ErrorCode.SCHEMA_ALREADY_EXISTS_1, schemaName);
}
int id = getObjectId();
Schema schema = new Schema(db, id, schemaName, user, false);
......
......@@ -6,13 +6,11 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.Sequence;
......@@ -41,14 +39,14 @@ public class CreateSequence extends SchemaCommand {
this.ifNotExists = ifNotExists;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
if (getSchema().findSequence(sequenceName) != null) {
if (ifNotExists) {
return 0;
}
throw Message.getSQLException(ErrorCode.SEQUENCE_ALREADY_EXISTS_1, sequenceName);
throw DbException.get(ErrorCode.SEQUENCE_ALREADY_EXISTS_1, sequenceName);
}
int id = getObjectId();
Sequence sequence = new Sequence(getSchema(), id, sequenceName, belongsToTable);
......@@ -59,7 +57,7 @@ public class CreateSequence extends SchemaCommand {
return 0;
}
private long getLong(Expression expr, long defaultValue) throws SQLException {
private long getLong(Expression expr, long defaultValue) {
if (expr == null) {
return defaultValue;
}
......
......@@ -6,7 +6,6 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.command.Prepared;
import org.h2.command.dml.Insert;
......@@ -15,7 +14,7 @@ import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.Sequence;
import org.h2.table.Column;
......@@ -74,7 +73,7 @@ public class CreateTable extends SchemaCommand {
*
* @param command the statement to add
*/
public void addConstraintCommand(Prepared command) throws SQLException {
public void addConstraintCommand(Prepared command) {
if (command instanceof CreateIndex) {
constraintCommands.add(command);
} else {
......@@ -95,7 +94,7 @@ public class CreateTable extends SchemaCommand {
this.ifNotExists = ifNotExists;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
if (!db.isPersistent()) {
......@@ -105,14 +104,14 @@ public class CreateTable extends SchemaCommand {
if (ifNotExists) {
return 0;
}
throw Message.getSQLException(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, data.tableName);
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, data.tableName);
}
if (asQuery != null) {
asQuery.prepare();
if (data.columns.size() == 0) {
generateColumnsFromQuery();
} else if (data.columns.size() != asQuery.getColumnCount()) {
throw Message.getSQLException(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
}
}
if (pkColumns != null) {
......@@ -177,7 +176,7 @@ public class CreateTable extends SchemaCommand {
session.setUndoLogEnabled(old);
}
}
} catch (SQLException e) {
} catch (DbException e) {
db.checkPowerOff();
db.removeSchemaObject(session, table);
throw e;
......@@ -215,14 +214,14 @@ public class CreateTable extends SchemaCommand {
* @param columns the primary key columns
* @return true if the same primary key columns where already set
*/
private boolean setPrimaryKeyColumns(IndexColumn[] columns) throws SQLException {
private boolean setPrimaryKeyColumns(IndexColumn[] columns) {
if (pkColumns != null) {
if (columns.length != pkColumns.length) {
throw Message.getSQLException(ErrorCode.SECOND_PRIMARY_KEY);
throw DbException.get(ErrorCode.SECOND_PRIMARY_KEY);
}
for (int i = 0; i < columns.length; i++) {
if (!columns[i].columnName.equals(pkColumns[i].columnName)) {
throw Message.getSQLException(ErrorCode.SECOND_PRIMARY_KEY);
throw DbException.get(ErrorCode.SECOND_PRIMARY_KEY);
}
}
return true;
......
......@@ -6,12 +6,10 @@
*/
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.TriggerObject;
import org.h2.table.Table;
......@@ -80,14 +78,14 @@ public class CreateTrigger extends SchemaCommand {
this.ifNotExists = ifNotExists;
}
public int update() throws SQLException {
public int update() {
session.commit(true);
Database db = session.getDatabase();
if (getSchema().findTrigger(triggerName) != null) {
if (ifNotExists) {
return 0;
}
throw Message.getSQLException(ErrorCode.TRIGGER_ALREADY_EXISTS_1, triggerName);
throw DbException.get(ErrorCode.TRIGGER_ALREADY_EXISTS_1, triggerName);
}
int id = getObjectId();
Table table = getSchema().getTableOrView(session, tableName);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论