/** * Get the check constraint expression for this column if set. * * @param session the session * @param asColumnName the column name to use * @return the constraint expression */ public Expression getCheckConstraint(Session session, String asColumnName) { if (checkConstraint == null) { return null; } Parser parser = new Parser(session); String sql; synchronized (this) { String oldName = name; name = asColumnName; sql = checkConstraint.getSQL(); name = oldName; } return parser.parseExpression(sql); }
if (readIf("(")) { if (isSelect()) { command.setQuery(parseSelect()); read(")"); command.setQueryAlias(readFromAlias(null, Collections.singletonList("ON"))); TableView temporarySourceTableView = createCTEView( command.getQueryAlias(), querySQLOutput[0], columnTemplateList, false/* no recursion */, TableFilter sourceTableFilter = readSimpleTableFilter(0, excludeIdentifiers); command.setSourceTableFilter(sourceTableFilter); Prepared preparedQuery = prepare(session, buff.toString(), null/*paramValues*/); command.setQuery((Select) preparedQuery); read("ON"); read("("); Expression condition = readExpression(); command.setOnCondition(condition); read(")"); if (readIfAll("WHEN", "MATCHED", "THEN")) { int startMatched = lastParseIndex; if (readIf("UPDATE")) { Update updateCommand = new Update(session);
@Override public String getSQL() { return Parser.quoteIdentifier(objectName); }
private void read(String expected) { if (currentTokenQuoted || !equalsToken(expected, currentToken)) { addExpected(expected); throw getSyntaxError(); } read(); }
private boolean readIf(String token) { if (!currentTokenQuoted && equalsToken(token, currentToken)) { read(); return true; } addExpected(token); return false; }
private boolean isToken(String token) { boolean result = equalsToken(token, currentToken) && !currentTokenQuoted; if (result) { return true; } addExpected(token); return false; }
private Prepared parseCreate() { boolean orReplace = false; if (readIf("OR")) { read("REPLACE"); orReplace = true; boolean force = readIf("FORCE"); if (readIf("VIEW")) { return parseCreateView(force, orReplace); } else if (readIf("ALIAS")) { return parseCreateFunctionAlias(force); } else if (readIf("SEQUENCE")) { return parseCreateSequence(); } else if (readIf("USER")) { return parseCreateUser(); } else if (readIf("TRIGGER")) { return parseCreateTrigger(force); } else if (readIf("ROLE")) { return parseCreateRole(); } else if (readIf("SCHEMA")) { return parseCreateSchema(); } else if (readIf("CONSTANT")) { return parseCreateConstant(); } else if (readIf("DOMAIN")) { return parseCreateUserDataType(); } else if (readIf("TYPE")) { return parseCreateUserDataType(); } else if (readIf("DATATYPE")) { return parseCreateUserDataType(); } else if (readIf("AGGREGATE")) {
private Expression readCondition() { if (readIf("NOT")) { return new ConditionNot(readCondition()); if (readIf("EXISTS")) { read("("); Query query = parseSelect(); read(")"); return new ConditionExists(query); if (readIf("INTERSECTS")) { read("("); Expression r1 = readConcat(); read(","); Expression r2 = readConcat(); read(")"); return new Comparison(session, Comparison.SPATIAL_INTERSECTS, r1, r2); Expression r = readConcat(); while (true) { if (readIf("NOT")) { not = true; if (isToken("NULL")) { if (readIf("LIKE")) { Expression b = readConcat(); Expression esc = null;
private Prepared parseAlterTable() { boolean ifTableExists = readIfExists(false); String tableName = readIdentifierWithSchema(); Schema schema = getSchema(); if (readIf("ADD")) { Prepared command = parseAlterTableAddConstraintIf(tableName, schema, ifTableExists); if (command != null) { return command; return parseAlterTableAddColumn(tableName, schema, ifTableExists); } else if (readIf("SET")) { read("REFERENTIAL_INTEGRITY"); int type = CommandInterface.ALTER_TABLE_SET_REFERENTIAL_INTEGRITY; boolean value = readBooleanSetting(); AlterTableSet command = new AlterTableSet(session, schema, type, value); command.setTableName(tableName); command.setIfTableExists(ifTableExists); if (readIf("CHECK")) { command.setCheckExisting(true); } else if (readIf("NOCHECK")) { command.setCheckExisting(false); } else if (readIf("RENAME")) { if (readIf("COLUMN")) { String columnName = readColumnIdentifier(); read("TO"); AlterTableRenameColumn command = new AlterTableRenameColumn(
private CreateTrigger parseCreateTrigger(boolean force) { boolean ifNotExists = readIfNotExists(); String triggerName = readIdentifierWithSchema(null); Schema schema = getSchema(); boolean insteadOf, isBefore; if (readIf("INSTEAD")) { read("OF"); isBefore = true; insteadOf = true; } else if (readIf("BEFORE")) { insteadOf = false; isBefore = true; } else { read("AFTER"); insteadOf = false; isBefore = false; boolean onRollback = false; do { if (readIf("INSERT")) { typeMask |= Trigger.INSERT; } else if (readIf("UPDATE")) { typeMask |= Trigger.UPDATE; } else if (readIf("DELETE")) { typeMask |= Trigger.DELETE; } else if (readIf("SELECT")) { typeMask |= Trigger.SELECT; } else if (readIf("ROLLBACK")) { onRollback = true; } else {
private AlterIndexRename parseAlterIndex() { boolean ifExists = readIfExists(false); String indexName = readIdentifierWithSchema(); Schema old = getSchema(); AlterIndexRename command = new AlterIndexRename(session); command.setOldSchema(old); command.setOldName(indexName); command.setIfExists(ifExists); read("RENAME"); read("TO"); String newName = readIdentifierWithSchema(old.getName()); checkSchema(old); command.setNewName(newName); return command; }
boolean allowIndexDefinition = database.getMode().indexDefinitionInCreateTable; boolean allowAffinityKey = database.getMode().allowAffinityKey; if (readIf("CONSTRAINT")) { ifNotExists = readIfNotExists(); constraintName = readIdentifierWithSchema(schema.getName()); checkSchema(schema); comment = readCommentIf(); allowIndexDefinition = true; if (readIf("PRIMARY")) { read("KEY"); AlterTableAddConstraint command = new AlterTableAddConstraint( session, schema, ifNotExists); command.setTableName(tableName); command.setIfTableExists(ifTableExists); if (readIf("HASH")) { command.setPrimaryKeyHash(true); read("("); command.setIndexColumns(parseIndexColumnList()); if (readIf("INDEX")) { String indexName = readIdentifierWithSchema(); command.setIndex(getSchema().findIndex(session, indexName)); } else if (allowIndexDefinition && (isToken("INDEX") || isToken("KEY"))) { read(); if (DataType.getTypeByName(currentToken, database.getMode()) != null) {
private GrantRevoke parseGrantRevoke(int operationType) { GrantRevoke command = new GrantRevoke(session); command.setOperationType(operationType); boolean tableClauseExpected = addRoleOrRight(command); while (readIf(",")) { addRoleOrRight(command); if (command.isRightMode() && command.isRoleMode()) { throw DbException if (readIf("ON")) { if (readIf("SCHEMA")) { Schema schema = database.getSchema(readAliasIdentifier()); command.setSchema(schema); } else { do { Table table = readTableOrView(); command.addTable(table); } while (readIf(",")); read("TO"); } else { read("FROM"); command.setGranteeName(readUniqueIdentifier()); return command;
currentTokenType = getTokenType(currentToken); parseIndex = i; return; currentTokenType = getSpecialType(currentToken); parseIndex = i; return; case CHAR_SPECIAL_1: currentToken = sqlCommand.substring(start, i); currentTokenType = getSpecialType(currentToken); parseIndex = i; return; c = chars[i]; if ((c < '0' || c > '9') && (c < 'A' || c > 'F')) { checkLiterals(false); currentValue = ValueInt.get((int) number); currentTokenType = VALUE; (c >= 'A' ? ('A' - 0xa) : ('0')); if (number > Integer.MAX_VALUE) { readHexDecimal(start, i); return; if (c < '0' || c > '9') { if (c == '.' || c == 'E' || c == 'L') { readDecimal(start, i); break;
private Prepared parseAlterTableAddConstraintIf(String tableName, Schema schema) throws SQLException { String constraintName = null, comment = null; if (readIf("CONSTRAINT")) { constraintName = readIdentifierWithSchema(schema.getName()); checkSchema(schema); comment = readCommentIf(); if (readIf("PRIMARY")) { read("KEY"); AlterTableAddConstraint command = new AlterTableAddConstraint(session, schema); command.setType(AlterTableAddConstraint.PRIMARY_KEY); command.setConstraintName(constraintName); command.setTableName(tableName); if (readIf("HASH")) { command.setPrimaryKeyHash(true); read("("); command.setIndexColumns(parseIndexColumnList()); if (readIf("INDEX")) { String indexName = readIdentifierWithSchema(); command.setIndex(getSchema().findIndex(indexName)); } else if (database.getMode().indexDefinitionInCreateTable && (readIf("INDEX") || readIf("KEY"))) { if (!readIf("(")) { command.setIndexName(readUniqueIdentifier()); read("("); command.setIndexColumns(parseIndexColumnList());
private Prepared parseShow() { ArrayList<Value> paramValues = New.arrayList(); StringBuilder buff = new StringBuilder("SELECT "); if (readIf("CLIENT_ENCODING")) { } else if (readIf("DEFAULT_TRANSACTION_ISOLATION")) { } else if (readIf("TRANSACTION")) { read("ISOLATION"); read("LEVEL"); buff.append("'read committed' AS TRANSACTION_ISOLATION " + "FROM DUAL"); } else if (readIf("DATESTYLE")) { } else if (readIf("SERVER_VERSION")) { } else if (readIf("SERVER_ENCODING")) { } else if (readIf("TABLES")) { if (readIf("FROM")) { schema = readUniqueIdentifier(); + "WHERE TABLE_SCHEMA=? ORDER BY TABLE_NAME"); paramValues.add(ValueString.get(schema)); } else if (readIf("COLUMNS")) { read("FROM"); String tableName = readIdentifierWithSchema();
Parser parser = new Parser(createSession); parser.setRightsChecked(true); parser.setSuppliedParameterList(originalParameters); query = (Query) parser.prepare(querySQL); query.setNeverLazy(true);
private CreateTrigger parseCreateTrigger(boolean force) throws SQLException { boolean ifNotExists = readIfNoExists(); String triggerName = readIdentifierWithSchema(null); Schema schema = getSchema(); boolean isBefore; if (readIf("BEFORE")) { isBefore = true; } else { read("AFTER"); isBefore = false; if (readIf("INSERT")) { typeMask |= Trigger.INSERT; } else if (readIf("UPDATE")) { typeMask |= Trigger.UPDATE; } else if (readIf("DELETE")) { typeMask |= Trigger.DELETE; } else { throw getSyntaxError(); } while (readIf(",")); read("ON"); String tableName = readIdentifierWithSchema(); checkSchema(schema); CreateTrigger command = new CreateTrigger(session, getSchema()); command.setForce(force); command.setTriggerName(triggerName); command.setTypeMask(typeMask); command.setTableName(tableName);
/** * Parse and prepare the given SQL statement. * * @param sql the SQL statement * @param rightsChecked true if the rights have already been checked * @return the prepared statement */ public Prepared prepare(String sql, boolean rightsChecked) { Parser parser = new Parser(this); parser.setRightsChecked(rightsChecked); return parser.prepare(sql); }
/** * Parse and prepare the given SQL statement. * * @param sql the SQL statement * @param rightsChecked true if the rights have already been checked * @param literalsChecked true if the sql string has already been checked * for literals (only used if ALLOW_LITERALS NONE is set). * @return the prepared statement */ public Prepared prepare(String sql, boolean rightsChecked, boolean literalsChecked) { Parser parser = new Parser(this); parser.setRightsChecked(rightsChecked); parser.setLiteralsChecked(literalsChecked); return parser.prepare(sql); }