use of org.h2.test.db.Db.Prepared in project h2database by h2database.
the class Parser method parseDrop.
private Prepared parseDrop() {
if (readIf("TABLE")) {
boolean ifExists = readIfExists(false);
String tableName = readIdentifierWithSchema();
DropTable command = new DropTable(session, getSchema());
command.setTableName(tableName);
while (readIf(",")) {
tableName = readIdentifierWithSchema();
DropTable next = new DropTable(session, getSchema());
next.setTableName(tableName);
command.addNextDropTable(next);
}
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
if (readIf("CASCADE")) {
command.setDropAction(ConstraintActionType.CASCADE);
readIf("CONSTRAINTS");
} else if (readIf("RESTRICT")) {
command.setDropAction(ConstraintActionType.RESTRICT);
} else if (readIf("IGNORE")) {
command.setDropAction(ConstraintActionType.SET_DEFAULT);
}
return command;
} else if (readIf("INDEX")) {
boolean ifExists = readIfExists(false);
String indexName = readIdentifierWithSchema();
DropIndex command = new DropIndex(session, getSchema());
command.setIndexName(indexName);
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
// Support for MySQL: DROP INDEX index_name ON tbl_name
if (readIf("ON")) {
readIdentifierWithSchema();
}
return command;
} else if (readIf("USER")) {
boolean ifExists = readIfExists(false);
DropUser command = new DropUser(session);
command.setUserName(readUniqueIdentifier());
ifExists = readIfExists(ifExists);
readIf("CASCADE");
command.setIfExists(ifExists);
return command;
} else if (readIf("SEQUENCE")) {
boolean ifExists = readIfExists(false);
String sequenceName = readIdentifierWithSchema();
DropSequence command = new DropSequence(session, getSchema());
command.setSequenceName(sequenceName);
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
return command;
} else if (readIf("CONSTANT")) {
boolean ifExists = readIfExists(false);
String constantName = readIdentifierWithSchema();
DropConstant command = new DropConstant(session, getSchema());
command.setConstantName(constantName);
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
return command;
} else if (readIf("TRIGGER")) {
boolean ifExists = readIfExists(false);
String triggerName = readIdentifierWithSchema();
DropTrigger command = new DropTrigger(session, getSchema());
command.setTriggerName(triggerName);
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
return command;
} else if (readIf("VIEW")) {
boolean ifExists = readIfExists(false);
String viewName = readIdentifierWithSchema();
DropView command = new DropView(session, getSchema());
command.setViewName(viewName);
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
ConstraintActionType dropAction = parseCascadeOrRestrict();
if (dropAction != null) {
command.setDropAction(dropAction);
}
return command;
} else if (readIf("ROLE")) {
boolean ifExists = readIfExists(false);
DropRole command = new DropRole(session);
command.setRoleName(readUniqueIdentifier());
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
return command;
} else if (readIf("ALIAS")) {
boolean ifExists = readIfExists(false);
String aliasName = readIdentifierWithSchema();
DropFunctionAlias command = new DropFunctionAlias(session, getSchema());
command.setAliasName(aliasName);
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
return command;
} else if (readIf("SCHEMA")) {
boolean ifExists = readIfExists(false);
DropSchema command = new DropSchema(session);
command.setSchemaName(readUniqueIdentifier());
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
if (readIf("CASCADE")) {
command.setDropAction(ConstraintActionType.CASCADE);
} else if (readIf("RESTRICT")) {
command.setDropAction(ConstraintActionType.RESTRICT);
}
return command;
} else if (readIf("ALL")) {
read("OBJECTS");
DropDatabase command = new DropDatabase(session);
command.setDropAllObjects(true);
if (readIf("DELETE")) {
read("FILES");
command.setDeleteFiles(true);
}
return command;
} else if (readIf("DOMAIN")) {
return parseDropUserDataType();
} else if (readIf("TYPE")) {
return parseDropUserDataType();
} else if (readIf("DATATYPE")) {
return parseDropUserDataType();
} else if (readIf("AGGREGATE")) {
return parseDropAggregate();
} else if (readIf("SYNONYM")) {
boolean ifExists = readIfExists(false);
String synonymName = readIdentifierWithSchema();
DropSynonym command = new DropSynonym(session, getSchema());
command.setSynonymName(synonymName);
ifExists = readIfExists(ifExists);
command.setIfExists(ifExists);
return command;
}
throw getSyntaxError();
}
use of org.h2.test.db.Db.Prepared in project h2database by h2database.
the class Parser method parseUse.
private Prepared parseUse() {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.SCHEMA);
command.setString(readAliasIdentifier());
return command;
}
use of org.h2.test.db.Db.Prepared in project h2database by h2database.
the class Parser method parseHelp.
private Prepared parseHelp() {
StringBuilder buff = new StringBuilder("SELECT * FROM INFORMATION_SCHEMA.HELP");
int i = 0;
ArrayList<Value> paramValues = New.arrayList();
while (currentTokenType != END) {
String s = currentToken;
read();
if (i == 0) {
buff.append(" WHERE ");
} else {
buff.append(" AND ");
}
i++;
buff.append("UPPER(TOPIC) LIKE ?");
paramValues.add(ValueString.get("%" + s + "%"));
}
return prepare(session, buff.toString(), paramValues);
}
use of org.h2.test.db.Db.Prepared in project h2database by h2database.
the class AlterTableAlterColumn method execute.
private void execute(String sql, boolean ddl) {
Prepared command = session.prepare(sql);
command.update();
if (ddl) {
session.commit(true);
}
}
use of org.h2.test.db.Db.Prepared in project h2database by h2database.
the class CommandContainer method recompileIfRequired.
private void recompileIfRequired() {
if (prepared.needRecompile()) {
// TODO test with 'always recompile'
prepared.setModificationMetaId(0);
String sql = prepared.getSQL();
ArrayList<Parameter> oldParams = prepared.getParameters();
Parser parser = new Parser(session);
prepared = parser.parse(sql);
long mod = prepared.getModificationMetaId();
prepared.setModificationMetaId(0);
ArrayList<Parameter> newParams = prepared.getParameters();
for (int i = 0, size = newParams.size(); i < size; i++) {
Parameter old = oldParams.get(i);
if (old.isValueSet()) {
Value v = old.getValue(session);
Parameter p = newParams.get(i);
p.setValue(v);
}
}
prepared.prepare();
prepared.setModificationMetaId(mod);
prepareJoinBatch();
}
}
Aggregations