use of org.h2.command.Command in project h2database by h2database.
the class Parser method parseCreateLinkedTable.
private CreateLinkedTable parseCreateLinkedTable(boolean temp, boolean globalTemp, boolean force) {
read("TABLE");
boolean ifNotExists = readIfNotExists();
String tableName = readIdentifierWithSchema();
CreateLinkedTable command = new CreateLinkedTable(session, getSchema());
command.setTemporary(temp);
command.setGlobalTemporary(globalTemp);
command.setForce(force);
command.setIfNotExists(ifNotExists);
command.setTableName(tableName);
command.setComment(readCommentIf());
read("(");
command.setDriver(readString());
read(",");
command.setUrl(readString());
read(",");
command.setUser(readString());
read(",");
command.setPassword(readString());
read(",");
String originalTable = readString();
if (readIf(",")) {
command.setOriginalSchema(originalTable);
originalTable = readString();
}
command.setOriginalTable(originalTable);
read(")");
if (readIf("EMIT")) {
read("UPDATES");
command.setEmitUpdates(true);
} else if (readIf("READONLY")) {
command.setReadOnly(true);
}
return command;
}
use of org.h2.command.Command in project h2database by h2database.
the class Parser method parseAlterSchema.
private Prepared parseAlterSchema() {
boolean ifExists = readIfExists(false);
String schemaName = readIdentifierWithSchema();
Schema old = getSchema();
read("RENAME");
read("TO");
String newName = readIdentifierWithSchema(old.getName());
Schema schema = findSchema(schemaName);
if (schema == null) {
if (ifExists) {
return new NoOperation(session);
}
throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName);
}
AlterSchemaRename command = new AlterSchemaRename(session);
command.setOldSchema(schema);
checkSchema(old);
command.setNewName(newName);
return command;
}
use of org.h2.command.Command in project h2database by h2database.
the class Parser method parseSelectSimple.
private Select parseSelectSimple() {
boolean fromFirst;
if (readIf("SELECT")) {
fromFirst = false;
} else if (readIf("FROM")) {
fromFirst = true;
} else {
throw getSyntaxError();
}
Select command = new Select(session);
int start = lastParseIndex;
Select oldSelect = currentSelect;
currentSelect = command;
currentPrepared = command;
if (fromFirst) {
parseSelectSimpleFromPart(command);
read("SELECT");
parseSelectSimpleSelectPart(command);
} else {
parseSelectSimpleSelectPart(command);
if (!readIf("FROM")) {
// select without FROM: convert to SELECT ... FROM
// SYSTEM_RANGE(1,1)
Table dual = getDualTable(false);
TableFilter filter = new TableFilter(session, dual, null, rightsChecked, currentSelect, 0, null);
command.addTableFilter(filter, true);
} else {
parseSelectSimpleFromPart(command);
}
}
if (readIf("WHERE")) {
Expression condition = readExpression();
command.addCondition(condition);
}
// the group by is read for the outer select (or not a select)
// so that columns that are not grouped can be used
currentSelect = oldSelect;
if (readIf("GROUP")) {
read("BY");
command.setGroupQuery();
ArrayList<Expression> list = New.arrayList();
do {
Expression expr = readExpression();
list.add(expr);
} while (readIf(","));
command.setGroupBy(list);
}
currentSelect = command;
if (readIf("HAVING")) {
command.setGroupQuery();
Expression condition = readExpression();
command.setHaving(condition);
}
command.setParameterList(parameters);
currentSelect = oldSelect;
setSQL(command, "SELECT", start);
return command;
}
use of org.h2.command.Command in project h2database by h2database.
the class Parser method parseAlterTableAlterColumnType.
private AlterTableAlterColumn parseAlterTableAlterColumnType(Schema schema, String tableName, String columnName, boolean ifTableExists) {
Column oldColumn = columnIfTableExists(schema, tableName, columnName, ifTableExists);
Column newColumn = parseColumnForTable(columnName, oldColumn == null ? true : oldColumn.isNullable());
AlterTableAlterColumn command = new AlterTableAlterColumn(session, schema);
command.setTableName(tableName);
command.setIfTableExists(ifTableExists);
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE);
command.setOldColumn(oldColumn);
command.setNewColumn(newColumn);
return command;
}
use of org.h2.command.Command in project h2database by h2database.
the class Parser method parseExecute.
private Prepared parseExecute() {
ExecuteProcedure command = new ExecuteProcedure(session);
String procedureName = readAliasIdentifier();
Procedure p = session.getProcedure(procedureName);
if (p == null) {
throw DbException.get(ErrorCode.FUNCTION_ALIAS_NOT_FOUND_1, procedureName);
}
command.setProcedure(p);
if (readIf("(")) {
for (int i = 0; ; i++) {
command.setExpression(i, readExpression());
if (readIf(")")) {
break;
}
read(",");
}
}
return command;
}
Aggregations