use of de.neemann.digital.hdl.model2.expression.Expression in project h2database by h2database.
the class Parser method parseReplace.
/**
* MySQL compatibility. REPLACE is similar to MERGE.
*/
private Replace parseReplace() {
Replace command = new Replace(session);
currentPrepared = command;
read("INTO");
Table table = readTableOrView();
command.setTable(table);
if (readIf("(")) {
if (isSelect()) {
command.setQuery(parseSelect());
read(")");
return command;
}
Column[] columns = parseColumnList(table);
command.setColumns(columns);
}
if (readIf("VALUES")) {
do {
ArrayList<Expression> values = New.arrayList();
read("(");
if (!readIf(")")) {
do {
if (readIf("DEFAULT")) {
values.add(null);
} else {
values.add(readExpression());
}
} while (readIfMore(false));
}
command.addRow(values.toArray(new Expression[0]));
} while (readIf(","));
} else {
command.setQuery(parseSelect());
}
return command;
}
use of de.neemann.digital.hdl.model2.expression.Expression in project h2database by h2database.
the class Parser method parseDelete.
private Delete parseDelete() {
Delete command = new Delete(session);
Expression limit = null;
if (readIf("TOP")) {
limit = readTerm().optimize(session);
}
currentPrepared = command;
int start = lastParseIndex;
if (!readIf("FROM") && database.getMode().getEnum() == ModeEnum.MySQL) {
readIdentifierWithSchema();
read("FROM");
}
TableFilter filter = readSimpleTableFilter(0, null);
command.setTableFilter(filter);
parseDeleteGivenTable(command, limit, start);
return command;
}
use of de.neemann.digital.hdl.model2.expression.Expression in project h2database by h2database.
the class Parser method parseInsert.
private Insert parseInsert() {
Insert command = new Insert(session);
currentPrepared = command;
if (database.getMode().onDuplicateKeyUpdate && readIf("IGNORE")) {
command.setIgnore(true);
}
read("INTO");
Table table = readTableOrView();
command.setTable(table);
Insert returnedCommand = parseInsertGivenTable(command, table);
if (returnedCommand != null) {
return returnedCommand;
}
if (database.getMode().onDuplicateKeyUpdate) {
if (readIf("ON")) {
read("DUPLICATE");
read("KEY");
read("UPDATE");
do {
String columnName = readColumnIdentifier();
if (readIf(".")) {
String schemaOrTableName = columnName;
String tableOrColumnName = readColumnIdentifier();
if (readIf(".")) {
if (!table.getSchema().getName().equals(schemaOrTableName)) {
throw DbException.get(ErrorCode.SCHEMA_NAME_MUST_MATCH);
}
columnName = readColumnIdentifier();
} else {
columnName = tableOrColumnName;
tableOrColumnName = schemaOrTableName;
}
if (!table.getName().equals(tableOrColumnName)) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableOrColumnName);
}
}
Column column = table.getColumn(columnName);
read("=");
Expression expression;
if (readIf("DEFAULT")) {
expression = ValueExpression.getDefault();
} else {
expression = readExpression();
}
command.addAssignmentForDuplicate(column, expression);
} while (readIf(","));
}
}
if (database.getMode().isolationLevelInSelectOrInsertStatement) {
parseIsolationClause();
}
return command;
}
use of de.neemann.digital.hdl.model2.expression.Expression in project h2database by h2database.
the class Parser method readCase.
private Expression readCase() {
if (readIf("END")) {
readIf("CASE");
return ValueExpression.getNull();
}
if (readIf("ELSE")) {
Expression elsePart = readExpression().optimize(session);
read("END");
readIf("CASE");
return elsePart;
}
int i;
Function function;
if (readIf("WHEN")) {
function = Function.getFunction(database, "CASE");
function.setParameter(0, null);
i = 1;
do {
function.setParameter(i++, readExpression());
read("THEN");
function.setParameter(i++, readExpression());
} while (readIf("WHEN"));
} else {
Expression expr = readExpression();
if (readIf("END")) {
readIf("CASE");
return ValueExpression.getNull();
}
if (readIf("ELSE")) {
Expression elsePart = readExpression().optimize(session);
read("END");
readIf("CASE");
return elsePart;
}
function = Function.getFunction(database, "CASE");
function.setParameter(0, expr);
i = 1;
read("WHEN");
do {
function.setParameter(i++, readExpression());
read("THEN");
function.setParameter(i++, readExpression());
} while (readIf("WHEN"));
}
if (readIf("ELSE")) {
function.setParameter(i, readExpression());
}
read("END");
readIf("CASE");
function.doneWithParameters();
return function;
}
use of de.neemann.digital.hdl.model2.expression.Expression 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;
}
Aggregations