private boolean readIfExists(boolean ifExists) { if (readIf("IF")) { read("EXISTS"); ifExists = true; } return ifExists; }
private void parseAutoIncrement(Column column) { long start = 1, increment = 1; if (readIf("(")) { start = readLong(); if (readIf(",")) { increment = readLong(); } read(")"); } column.setAutoIncrement(true, start, increment); }
private Prepared parseTruncate() { read("TABLE"); Table table = readTableOrView(); TruncateTable command = new TruncateTable(session); command.setTable(table); return command; }
private CreateUserDataType parseCreateUserDataType() { boolean ifNotExists = readIfNotExists(); CreateUserDataType command = new CreateUserDataType(session); command.setTypeName(readUniqueIdentifier()); read("AS"); Column col = parseColumnForTable("VALUE", true); if (readIf("CHECK")) { Expression expr = readExpression(); col.addCheckConstraint(session, expr); } col.rename(null); command.setColumn(col); command.setIfNotExists(ifNotExists); return command; }
private AlterSchemaRename parseAlterSchema() { String schemaName = readIdentifierWithSchema(); Schema old = getSchema(); AlterSchemaRename command = new AlterSchemaRename(session); command.setOldSchema(getSchema(schemaName)); read("RENAME"); read("TO"); String newName = readIdentifierWithSchema(old.getName()); checkSchema(old); command.setNewName(newName); return command; }
private Prepared parseBackup() { BackupCommand command = new BackupCommand(session); read("TO"); command.setFileName(readExpression()); return command; }
private String readColumnIdentifier() { if (currentTokenType != IDENTIFIER) { throw DbException.getSyntaxError(sqlCommand, parseIndex, "identifier"); } String s = currentToken; read(); return s; }
private AlterIndexRename parseAlterIndex() { String indexName = readIdentifierWithSchema(); Schema old = getSchema(); AlterIndexRename command = new AlterIndexRename(session); command.setOldIndex(getSchema().getIndex(indexName)); read("RENAME"); read("TO"); String newName = readIdentifierWithSchema(old.getName()); checkSchema(old); command.setNewName(newName); return command; }
/** * Parse a SQL code snippet that represents a table name. * * @param sql the code snippet * @return the table object */ public Table parseTableName(String sql) { parameters = New.arrayList(); initialize(sql); read(); return readTableOrView(); } }
/** * Parse a SQL code snippet that represents an expression. * * @param sql the code snippet * @return the expression object */ public Expression parseExpression(String sql) { parameters = New.arrayList(); initialize(sql); read(); return readExpression(); }
private boolean readIf(String token) { if (!currentTokenQuoted && equalsToken(token, currentToken)) { read(); return true; } addExpected(token); return false; }
private boolean readIfMore() { if (readIf(",")) { return !readIf(")"); } read(")"); return false; }
private AlterView parseAlterView() { AlterView command = new AlterView(session); String viewName = readIdentifierWithSchema(); Table tableView = getSchema().findTableOrView(session, viewName); if (!(tableView instanceof TableView)) { throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName); } TableView view = (TableView) tableView; command.setView(view); read("RECOMPILE"); return command; }
private void read(String expected) { if (currentTokenQuoted || !equalsToken(expected, currentToken)) { addExpected(expected); throw getSyntaxError(); } read(); }
private boolean readBooleanSetting() { if (currentTokenType == VALUE) { boolean result = currentValue.getBoolean().booleanValue(); read(); return result; } if (readIf("TRUE") || readIf("ON")) { return true; } else if (readIf("FALSE") || readIf("OFF")) { return false; } else { throw getSyntaxError(); } }
private Prepared parse(String sql, boolean withExpectedList) { initialize(sql); if (withExpectedList) { expectedList = New.arrayList(); } else { expectedList = null; } parameters = New.arrayList(); currentSelect = null; currentPrepared = null; recompileAlways = false; indexedParameterList = null; read(); return parsePrepared(); }
private Query parseSelectSub() { if (readIf("(")) { Query command = parseSelectUnion(); read(")"); return command; } Select select = parseSelectSimple(); return select; }
private boolean isSelect() { int start = lastParseIndex; while (readIf("(")) { // need to read ahead, it could be a nested union: // ((select 1) union (select 1)) } boolean select = isToken("SELECT") || isToken("FROM"); parseIndex = start; read(); return select; }
private Function readFunctionWithoutParameters(String name) { if (readIf("(")) { read(")"); } Function function = Function.getFunction(database, name); function.doneWithParameters(); return function; }