Search in sources :

Example 26 with Update

use of org.h2.command.dml.Update in project h2database by h2database.

the class AlterTableRenameColumn method update.

@Override
public int update() {
    session.commit(true);
    Database db = session.getDatabase();
    Table table = getSchema().findTableOrView(session, tableName);
    if (table == null) {
        if (ifTableExists) {
            return 0;
        }
        throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableName);
    }
    Column column = table.getColumn(oldName);
    session.getUser().checkRight(table, Right.ALL);
    table.checkSupportAlter();
    // we need to update CHECK constraint
    // since it might reference the name of the column
    Expression newCheckExpr = column.getCheckConstraint(session, newName);
    table.renameColumn(column, newName);
    column.removeCheckConstraint();
    column.addCheckConstraint(session, newCheckExpr);
    table.setModified();
    db.updateMeta(session, table);
    for (DbObject child : table.getChildren()) {
        if (child.getCreateSQL() != null) {
            db.updateMeta(session, child);
        }
    }
    return 0;
}
Also used : Table(org.h2.table.Table) Column(org.h2.table.Column) Expression(org.h2.expression.Expression) DbObject(org.h2.engine.DbObject) Database(org.h2.engine.Database)

Example 27 with Update

use of org.h2.command.dml.Update in project h2database by h2database.

the class CreateFunctionAlias method update.

@Override
public int update() {
    session.commit(true);
    session.getUser().checkAdmin();
    Database db = session.getDatabase();
    if (getSchema().findFunction(aliasName) != null) {
        if (!ifNotExists) {
            throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, aliasName);
        }
    } else {
        int id = getObjectId();
        FunctionAlias functionAlias;
        if (javaClassMethod != null) {
            functionAlias = FunctionAlias.newInstance(getSchema(), id, aliasName, javaClassMethod, force, bufferResultSetToLocalTemp);
        } else {
            functionAlias = FunctionAlias.newInstanceFromSource(getSchema(), id, aliasName, source, force, bufferResultSetToLocalTemp);
        }
        functionAlias.setDeterministic(deterministic);
        db.addSchemaObject(session, functionAlias);
    }
    return 0;
}
Also used : FunctionAlias(org.h2.engine.FunctionAlias) Database(org.h2.engine.Database)

Example 28 with Update

use of org.h2.command.dml.Update in project h2database by h2database.

the class CreateLinkedTable method update.

@Override
public int update() {
    session.commit(true);
    Database db = session.getDatabase();
    session.getUser().checkAdmin();
    if (getSchema().resolveTableOrView(session, tableName) != null) {
        if (ifNotExists) {
            return 0;
        }
        throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, tableName);
    }
    int id = getObjectId();
    TableLink table = getSchema().createTableLink(id, tableName, driver, url, user, password, originalSchema, originalTable, emitUpdates, force);
    table.setTemporary(temporary);
    table.setGlobalTemporary(globalTemporary);
    table.setComment(comment);
    table.setReadOnly(readOnly);
    if (temporary && !globalTemporary) {
        session.addLocalTempTable(table);
    } else {
        db.addSchemaObject(session, table);
    }
    return 0;
}
Also used : Database(org.h2.engine.Database) TableLink(org.h2.table.TableLink)

Example 29 with Update

use of org.h2.command.dml.Update in project h2database by h2database.

the class AlterView method update.

@Override
public int update() {
    session.commit(true);
    if (view == null && ifExists) {
        return 0;
    }
    session.getUser().checkRight(view, Right.ALL);
    DbException e = view.recompile(session, false, true);
    if (e != null) {
        throw e;
    }
    return 0;
}
Also used : DbException(org.h2.message.DbException)

Example 30 with Update

use of org.h2.command.dml.Update in project h2database by h2database.

the class ExecuteProcedure method update.

@Override
public int update() {
    setParameters();
    Prepared prepared = procedure.getPrepared();
    return prepared.update();
}
Also used : Prepared(org.h2.command.Prepared)

Aggregations

SQLException (java.sql.SQLException)44 DbException (org.h2.message.DbException)40 Database (org.h2.engine.Database)39 Connection (java.sql.Connection)37 PreparedStatement (java.sql.PreparedStatement)35 Value (org.h2.value.Value)34 ResultSet (java.sql.ResultSet)32 Statement (java.sql.Statement)31 Column (org.h2.table.Column)30 Table (org.h2.table.Table)23 JdbcConnection (org.h2.jdbc.JdbcConnection)22 Expression (org.h2.expression.Expression)19 StatementBuilder (org.h2.util.StatementBuilder)14 ValueExpression (org.h2.expression.ValueExpression)13 ValueString (org.h2.value.ValueString)13 ArrayList (java.util.ArrayList)10 Constraint (org.h2.constraint.Constraint)10 Index (org.h2.index.Index)10 IndexColumn (org.h2.table.IndexColumn)10 Task (org.h2.util.Task)10