use of org.h2.command.Command in project h2database by h2database.
the class Parser method parseDeleteGivenTable.
private void parseDeleteGivenTable(Delete command, Expression limit, int start) {
if (readIf("WHERE")) {
Expression condition = readExpression();
command.setCondition(condition);
}
if (readIf("LIMIT") && limit == null) {
limit = readTerm().optimize(session);
}
command.setLimit(limit);
setSQL(command, "DELETE", start);
}
use of org.h2.command.Command in project h2database by h2database.
the class Parser method parsePrepare.
private Prepared parsePrepare() {
if (readIf("COMMIT")) {
TransactionCommand command = new TransactionCommand(session, CommandInterface.PREPARE_COMMIT);
command.setTransactionName(readUniqueIdentifier());
return command;
}
String procedureName = readAliasIdentifier();
if (readIf("(")) {
ArrayList<Column> list = New.arrayList();
for (int i = 0; ; i++) {
Column column = parseColumnForTable("C" + i, true);
list.add(column);
if (readIf(")")) {
break;
}
read(",");
}
}
read("AS");
Prepared prep = parsePrepared();
PrepareProcedure command = new PrepareProcedure(session);
command.setProcedureName(procedureName);
command.setPrepared(prep);
return command;
}
use of org.h2.command.Command in project h2database by h2database.
the class Parser method parseBackup.
private Prepared parseBackup() {
BackupCommand command = new BackupCommand(session);
read("TO");
command.setFileName(readExpression());
return command;
}
use of org.h2.command.Command in project h2database by h2database.
the class Parser method parseCreateTable.
private CreateTable parseCreateTable(boolean temp, boolean globalTemp, boolean persistIndexes) {
boolean ifNotExists = readIfNotExists();
String tableName = readIdentifierWithSchema();
if (temp && globalTemp && equalsToken("SESSION", schemaName)) {
// support weird syntax: declare global temporary table session.xy
// (...) not logged
schemaName = session.getCurrentSchemaName();
globalTemp = false;
}
Schema schema = getSchema();
CreateTable command = new CreateTable(session, schema);
command.setPersistIndexes(persistIndexes);
command.setTemporary(temp);
command.setGlobalTemporary(globalTemp);
command.setIfNotExists(ifNotExists);
command.setTableName(tableName);
command.setComment(readCommentIf());
if (readIf("(")) {
if (!readIf(")")) {
do {
parseTableColumnDefinition(command, schema, tableName);
} while (readIfMore(false));
}
}
// Allows "COMMENT='comment'" in DDL statements (MySQL syntax)
if (readIf("COMMENT")) {
if (readIf("=")) {
// read the complete string comment, but nothing with it for now
readString();
}
}
if (readIf("ENGINE")) {
if (readIf("=")) {
// map MySQL engine types onto H2 behavior
String tableEngine = readUniqueIdentifier();
if ("InnoDb".equalsIgnoreCase(tableEngine)) {
// ok
} else if (!"MyISAM".equalsIgnoreCase(tableEngine)) {
throw DbException.getUnsupportedException(tableEngine);
}
} else {
command.setTableEngine(readUniqueIdentifier());
}
}
if (readIf("WITH")) {
command.setTableEngineParams(readTableEngineParams());
}
// MySQL compatibility
if (readIf("AUTO_INCREMENT")) {
read("=");
if (currentTokenType != VALUE || currentValue.getType() != Value.INT) {
throw DbException.getSyntaxError(sqlCommand, parseIndex, "integer");
}
read();
}
readIf("DEFAULT");
if (readIf("CHARSET")) {
read("=");
if (!readIf("UTF8")) {
read("UTF8MB4");
}
}
if (temp) {
if (readIf("ON")) {
read("COMMIT");
if (readIf("DROP")) {
command.setOnCommitDrop();
} else if (readIf("DELETE")) {
read("ROWS");
command.setOnCommitTruncate();
}
} else if (readIf("NOT")) {
if (readIf("PERSISTENT")) {
command.setPersistData(false);
} else {
read("LOGGED");
}
}
if (readIf("TRANSACTIONAL")) {
command.setTransactional(true);
}
} else if (!persistIndexes && readIf("NOT")) {
read("PERSISTENT");
command.setPersistData(false);
}
if (readIf("HIDDEN")) {
command.setHidden(true);
}
if (readIf("AS")) {
if (readIf("SORTED")) {
command.setSortedInsertMode(true);
}
command.setQuery(parseSelect());
}
// for MySQL compatibility
if (readIf("ROW_FORMAT")) {
if (readIf("=")) {
readColumnIdentifier();
}
}
return command;
}
use of org.h2.command.Command in project h2database by h2database.
the class Parser method parseAlterTableAddColumn.
private AlterTableAlterColumn parseAlterTableAddColumn(String tableName, Schema schema, boolean ifTableExists) {
readIf("COLUMN");
AlterTableAlterColumn command = new AlterTableAlterColumn(session, schema);
command.setType(CommandInterface.ALTER_TABLE_ADD_COLUMN);
command.setTableName(tableName);
command.setIfTableExists(ifTableExists);
if (readIf("(")) {
command.setIfNotExists(false);
do {
parseTableColumnDefinition(command, schema, tableName);
} while (readIfMore(true));
} else {
boolean ifNotExists = readIfNotExists();
command.setIfNotExists(ifNotExists);
parseTableColumnDefinition(command, schema, tableName);
}
if (readIf("BEFORE")) {
command.setAddBefore(readColumnIdentifier());
} else if (readIf("AFTER")) {
command.setAddAfter(readColumnIdentifier());
} else if (readIf("FIRST")) {
command.setAddFirst();
}
return command;
}
Aggregations