Search in sources :

Example 66 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class LinkedIndex method remove.

@Override
public void remove(Session session, Row row) {
    ArrayList<Value> params = New.arrayList();
    StatementBuilder buff = new StatementBuilder("DELETE FROM ");
    buff.append(targetTableName).append(" WHERE ");
    for (int i = 0; i < row.getColumnCount(); i++) {
        buff.appendExceptFirst("AND ");
        Column col = table.getColumn(i);
        buff.append(col.getSQL());
        Value v = row.getValue(i);
        if (isNull(v)) {
            buff.append(" IS NULL ");
        } else {
            buff.append('=');
            addParameter(buff, col);
            params.add(v);
            buff.append(' ');
        }
    }
    String sql = buff.toString();
    try {
        PreparedStatement prep = link.execute(sql, params, false);
        int count = prep.executeUpdate();
        link.reusePreparedStatement(prep, sql);
        rowCount -= count;
    } catch (Exception e) {
        throw TableLink.wrapException(sql, e);
    }
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) StatementBuilder(org.h2.util.StatementBuilder) Value(org.h2.value.Value) PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException)

Example 67 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class IndexCondition method compareTypeToString.

private static String compareTypeToString(int i) {
    StatementBuilder s = new StatementBuilder();
    if ((i & EQUALITY) == EQUALITY) {
        s.appendExceptFirst("&");
        s.append("EQUALITY");
    }
    if ((i & START) == START) {
        s.appendExceptFirst("&");
        s.append("START");
    }
    if ((i & END) == END) {
        s.appendExceptFirst("&");
        s.append("END");
    }
    if ((i & ALWAYS_FALSE) == ALWAYS_FALSE) {
        s.appendExceptFirst("&");
        s.append("ALWAYS_FALSE");
    }
    if ((i & SPATIAL_INTERSECTS) == SPATIAL_INTERSECTS) {
        s.appendExceptFirst("&");
        s.append("SPATIAL_INTERSECTS");
    }
    return s.toString();
}
Also used : StatementBuilder(org.h2.util.StatementBuilder)

Example 68 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class ValueArray method getSQL.

@Override
public String getSQL() {
    StatementBuilder buff = new StatementBuilder("(");
    for (Value v : values) {
        buff.appendExceptFirst(", ");
        buff.append(v.getSQL());
    }
    if (values.length == 1) {
        buff.append(',');
    }
    return buff.append(')').toString();
}
Also used : StatementBuilder(org.h2.util.StatementBuilder)

Example 69 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class ValueArray method getTraceSQL.

@Override
public String getTraceSQL() {
    StatementBuilder buff = new StatementBuilder("(");
    for (Value v : values) {
        buff.appendExceptFirst(", ");
        buff.append(v == null ? "null" : v.getTraceSQL());
    }
    return buff.append(')').toString();
}
Also used : StatementBuilder(org.h2.util.StatementBuilder)

Example 70 with StatementBuilder

use of org.h2.util.StatementBuilder in project h2database by h2database.

the class TriggerObject method getTypeNameList.

public String getTypeNameList() {
    StatementBuilder buff = new StatementBuilder();
    if ((typeMask & Trigger.INSERT) != 0) {
        buff.appendExceptFirst(", ");
        buff.append("INSERT");
    }
    if ((typeMask & Trigger.UPDATE) != 0) {
        buff.appendExceptFirst(", ");
        buff.append("UPDATE");
    }
    if ((typeMask & Trigger.DELETE) != 0) {
        buff.appendExceptFirst(", ");
        buff.append("DELETE");
    }
    if ((typeMask & Trigger.SELECT) != 0) {
        buff.appendExceptFirst(", ");
        buff.append("SELECT");
    }
    if (onRollback) {
        buff.appendExceptFirst(", ");
        buff.append("ROLLBACK");
    }
    return buff.toString();
}
Also used : StatementBuilder(org.h2.util.StatementBuilder)

Aggregations

StatementBuilder (org.h2.util.StatementBuilder)82 Value (org.h2.value.Value)16 Column (org.h2.table.Column)15 IndexColumn (org.h2.table.IndexColumn)11 PreparedStatement (java.sql.PreparedStatement)9 Expression (org.h2.expression.Expression)9 ValueString (org.h2.value.ValueString)7 Index (org.h2.index.Index)6 DbException (org.h2.message.DbException)6 ResultSet (java.sql.ResultSet)5 Row (org.h2.result.Row)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Constraint (org.h2.constraint.Constraint)3 Database (org.h2.engine.Database)3 ExpressionColumn (org.h2.expression.ExpressionColumn)3 HashMap (java.util.HashMap)2 SelectOrderBy (org.h2.command.dml.SelectOrderBy)2 ResultInterface (org.h2.result.ResultInterface)2 SearchRow (org.h2.result.SearchRow)2