use of org.h2.test.db.Db.Prepared in project h2database by h2database.
the class Parser method parseSet.
private Prepared parseSet() {
if (readIf("@")) {
Set command = new Set(session, SetTypes.VARIABLE);
command.setString(readAliasIdentifier());
readIfEqualOrTo();
command.setExpression(readExpression());
return command;
} else if (readIf("AUTOCOMMIT")) {
readIfEqualOrTo();
boolean value = readBooleanSetting();
int setting = value ? CommandInterface.SET_AUTOCOMMIT_TRUE : CommandInterface.SET_AUTOCOMMIT_FALSE;
return new TransactionCommand(session, setting);
} else if (readIf("MVCC")) {
readIfEqualOrTo();
boolean value = readBooleanSetting();
Set command = new Set(session, SetTypes.MVCC);
command.setInt(value ? 1 : 0);
return command;
} else if (readIf("EXCLUSIVE")) {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.EXCLUSIVE);
command.setExpression(readExpression());
return command;
} else if (readIf("IGNORECASE")) {
readIfEqualOrTo();
boolean value = readBooleanSetting();
Set command = new Set(session, SetTypes.IGNORECASE);
command.setInt(value ? 1 : 0);
return command;
} else if (readIf("PASSWORD")) {
readIfEqualOrTo();
AlterUser command = new AlterUser(session);
command.setType(CommandInterface.ALTER_USER_SET_PASSWORD);
command.setUser(session.getUser());
command.setPassword(readExpression());
return command;
} else if (readIf("SALT")) {
readIfEqualOrTo();
AlterUser command = new AlterUser(session);
command.setType(CommandInterface.ALTER_USER_SET_PASSWORD);
command.setUser(session.getUser());
command.setSalt(readExpression());
read("HASH");
command.setHash(readExpression());
return command;
} else if (readIf("MODE")) {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.MODE);
command.setString(readAliasIdentifier());
return command;
} else if (readIf("COMPRESS_LOB")) {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.COMPRESS_LOB);
if (currentTokenType == VALUE) {
command.setString(readString());
} else {
command.setString(readUniqueIdentifier());
}
return command;
} else if (readIf("DATABASE")) {
readIfEqualOrTo();
read("COLLATION");
return parseSetCollation();
} else if (readIf("COLLATION")) {
readIfEqualOrTo();
return parseSetCollation();
} else if (readIf("BINARY_COLLATION")) {
readIfEqualOrTo();
return parseSetBinaryCollation();
} else if (readIf("CLUSTER")) {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.CLUSTER);
command.setString(readString());
return command;
} else if (readIf("DATABASE_EVENT_LISTENER")) {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.DATABASE_EVENT_LISTENER);
command.setString(readString());
return command;
} else if (readIf("ALLOW_LITERALS")) {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.ALLOW_LITERALS);
if (readIf("NONE")) {
command.setInt(Constants.ALLOW_LITERALS_NONE);
} else if (readIf("ALL")) {
command.setInt(Constants.ALLOW_LITERALS_ALL);
} else if (readIf("NUMBERS")) {
command.setInt(Constants.ALLOW_LITERALS_NUMBERS);
} else {
command.setInt(readPositiveInt());
}
return command;
} else if (readIf("DEFAULT_TABLE_TYPE")) {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.DEFAULT_TABLE_TYPE);
if (readIf("MEMORY")) {
command.setInt(Table.TYPE_MEMORY);
} else if (readIf("CACHED")) {
command.setInt(Table.TYPE_CACHED);
} else {
command.setInt(readPositiveInt());
}
return command;
} else if (readIf("CREATE")) {
readIfEqualOrTo();
// Derby compatibility (CREATE=TRUE in the database URL)
read();
return new NoOperation(session);
} else if (readIf("HSQLDB.DEFAULT_TABLE_TYPE")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("PAGE_STORE")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("CACHE_TYPE")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("FILE_LOCK")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("DB_CLOSE_ON_EXIT")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("AUTO_SERVER")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("AUTO_SERVER_PORT")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("AUTO_RECONNECT")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("ASSERT")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("ACCESS_MODE_DATA")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("OPEN_NEW")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("JMX")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("PAGE_SIZE")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("RECOVER")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("NAMES")) {
// Quercus PHP MySQL driver compatibility
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("SCOPE_GENERATED_KEYS")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("SCHEMA")) {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.SCHEMA);
command.setString(readAliasIdentifier());
return command;
} else if (readIf("DATESTYLE")) {
// PostgreSQL compatibility
readIfEqualOrTo();
if (!readIf("ISO")) {
String s = readString();
if (!equalsToken(s, "ISO")) {
throw getSyntaxError();
}
}
return new NoOperation(session);
} else if (readIf("SEARCH_PATH") || readIf(SetTypes.getTypeName(SetTypes.SCHEMA_SEARCH_PATH))) {
readIfEqualOrTo();
Set command = new Set(session, SetTypes.SCHEMA_SEARCH_PATH);
ArrayList<String> list = New.arrayList();
list.add(readAliasIdentifier());
while (readIf(",")) {
list.add(readAliasIdentifier());
}
command.setStringArray(list.toArray(new String[0]));
return command;
} else if (readIf("JAVA_OBJECT_SERIALIZER")) {
readIfEqualOrTo();
return parseSetJavaObjectSerializer();
} else {
if (isToken("LOGSIZE")) {
// HSQLDB compatibility
currentToken = SetTypes.getTypeName(SetTypes.MAX_LOG_SIZE);
}
if (isToken("FOREIGN_KEY_CHECKS")) {
// MySQL compatibility
currentToken = SetTypes.getTypeName(SetTypes.REFERENTIAL_INTEGRITY);
}
int type = SetTypes.getType(currentToken);
if (type < 0) {
throw getSyntaxError();
}
read();
readIfEqualOrTo();
Set command = new Set(session, type);
command.setExpression(readExpression());
return command;
}
}
use of org.h2.test.db.Db.Prepared in project h2database by h2database.
the class Parser method prepareCommand.
/**
* Parse a statement or a list of statements, and prepare it for execution.
*
* @param sql the SQL statement to parse
* @return the command object
*/
public Command prepareCommand(String sql) {
try {
Prepared p = parse(sql);
boolean hasMore = isToken(";");
if (!hasMore && currentTokenType != END) {
throw getSyntaxError();
}
p.prepare();
Command c = new CommandContainer(this, sql, p);
if (hasMore) {
String remaining = originalSQL.substring(parseIndex);
if (remaining.trim().length() != 0) {
c = new CommandList(this, sql, c, remaining);
}
}
return c;
} catch (DbException e) {
throw e.addSQL(originalSQL);
}
}
use of org.h2.test.db.Db.Prepared 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.test.db.Db.Prepared in project h2database by h2database.
the class Parser method parseShow.
private Prepared parseShow() {
ArrayList<Value> paramValues = New.arrayList();
StringBuilder buff = new StringBuilder("SELECT ");
if (readIf("CLIENT_ENCODING")) {
// for PostgreSQL compatibility
buff.append("'UNICODE' AS CLIENT_ENCODING FROM DUAL");
} else if (readIf("DEFAULT_TRANSACTION_ISOLATION")) {
// for PostgreSQL compatibility
buff.append("'read committed' AS DEFAULT_TRANSACTION_ISOLATION " + "FROM DUAL");
} else if (readIf("TRANSACTION")) {
// for PostgreSQL compatibility
read("ISOLATION");
read("LEVEL");
buff.append("'read committed' AS TRANSACTION_ISOLATION " + "FROM DUAL");
} else if (readIf("DATESTYLE")) {
// for PostgreSQL compatibility
buff.append("'ISO' AS DATESTYLE FROM DUAL");
} else if (readIf("SERVER_VERSION")) {
// for PostgreSQL compatibility
buff.append("'" + Constants.PG_VERSION + "' AS SERVER_VERSION FROM DUAL");
} else if (readIf("SERVER_ENCODING")) {
// for PostgreSQL compatibility
buff.append("'UTF8' AS SERVER_ENCODING FROM DUAL");
} else if (readIf("TABLES")) {
// for MySQL compatibility
String schema = Constants.SCHEMA_MAIN;
if (readIf("FROM")) {
schema = readUniqueIdentifier();
}
buff.append("TABLE_NAME, TABLE_SCHEMA FROM " + "INFORMATION_SCHEMA.TABLES " + "WHERE TABLE_SCHEMA=? ORDER BY TABLE_NAME");
paramValues.add(ValueString.get(schema));
} else if (readIf("COLUMNS")) {
// for MySQL compatibility
read("FROM");
String tableName = readIdentifierWithSchema();
String schemaName = getSchema().getName();
paramValues.add(ValueString.get(tableName));
if (readIf("FROM")) {
schemaName = readUniqueIdentifier();
}
buff.append("C.COLUMN_NAME FIELD, " + "C.TYPE_NAME || '(' || C.NUMERIC_PRECISION || ')' TYPE, " + "C.IS_NULLABLE \"NULL\", " + "CASE (SELECT MAX(I.INDEX_TYPE_NAME) FROM " + "INFORMATION_SCHEMA.INDEXES I " + "WHERE I.TABLE_SCHEMA=C.TABLE_SCHEMA " + "AND I.TABLE_NAME=C.TABLE_NAME " + "AND I.COLUMN_NAME=C.COLUMN_NAME)" + "WHEN 'PRIMARY KEY' THEN 'PRI' " + "WHEN 'UNIQUE INDEX' THEN 'UNI' ELSE '' END KEY, " + "IFNULL(COLUMN_DEFAULT, 'NULL') DEFAULT " + "FROM INFORMATION_SCHEMA.COLUMNS C " + "WHERE C.TABLE_NAME=? AND C.TABLE_SCHEMA=? " + "ORDER BY C.ORDINAL_POSITION");
paramValues.add(ValueString.get(schemaName));
} else if (readIf("DATABASES") || readIf("SCHEMAS")) {
// for MySQL compatibility
buff.append("SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA");
}
boolean b = session.getAllowLiterals();
try {
// need to temporarily enable it, in case we are in
// ALLOW_LITERALS_NUMBERS mode
session.setAllowLiterals(true);
return prepare(session, buff.toString(), paramValues);
} finally {
session.setAllowLiterals(b);
}
}
use of org.h2.test.db.Db.Prepared 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