void setAttributesAsColumn(RangeVariable range, int i) { columnIndex = i; column = range.getColumn(i); dataType = column.getDataType(); rangeVariable = range; if (range.rangeType == RangeVariable.TABLE_RANGE) { rangeVariable.addColumn(columnIndex); } }
void setAutoAttributesAsColumn(RangeVariable range, int i) { columnIndex = i; column = range.getColumn(i); dataType = column.getDataType(); columnName = range.getColumnAlias(i).name; tableName = range.getTableAlias().name; rangeVariable = range; rangeVariable.addColumn(columnIndex); }
int findMatchingRangeVariableIndex(RangeVariable[] rangeVarArray) { for (int i = 0; i < rangeVarArray.length; i++) { RangeVariable rangeVar = rangeVarArray[i]; if (rangeVar.resolvesTableName(this)) { return i; } } return -1; }
public RangeVariable duplicate() { RangeVariable r = null; try { r = (RangeVariable) super.clone(); } catch (CloneNotSupportedException ex) { throw Error.runtimeError(ErrorCode.U_S0500, "RangeVariable"); } r.resetConditions(); return r; }
void prepareCheckConstraint(Session session, Table table, boolean checkValues) { // to ensure no subselects etc. are in condition check.checkValidCheckConstraint(); if (table == null) { check.resolveTypes(session, null); } else { QuerySpecification s = Expression.getCheckSelect(session, table, check); Result r = s.getResult(session, 1); if (r.getNavigator().getSize() != 0) { String[] info = new String[] {table.getName().name, ""}; throw Error.error(ErrorCode.X_23504, ErrorCode.CONSTRAINT, info); } rangeVariable = s.rangeVariables[0]; // removes reference to the Index object in range variable rangeVariable.setForCheckConstraint(); } if (check.getType() == OpTypes.NOT && check.getLeftNode().getType() == OpTypes.IS_NULL && check.getLeftNode().getLeftNode().getType() == OpTypes.COLUMN) { notNullColumnIndex = check.getLeftNode().getLeftNode().getColumnIndex(); isNotNull = true; } }
/* * Tests a row against this CHECK constraint. */ void checkCheckConstraint(Session session, Table table, Object[] data) { /* if (session.compiledStatementExecutor.rangeIterators[1] == null) { session.compiledStatementExecutor.rangeIterators[1] = rangeVariable.getIterator(session); } */ RangeIteratorBase it = (RangeIteratorBase) session.sessionContext.getCheckIterator(); if (it == null) { it = rangeVariable.getIterator(session); session.sessionContext.setCheckIterator(it); } it.currentData = data; boolean nomatch = Boolean.FALSE.equals(check.getValue(session)); it.currentData = null; if (nomatch) { String[] info = new String[] {name.name, table.tableName.name}; throw Error.error(ErrorCode.X_23504, ErrorCode.CONSTRAINT, info); } }
public String getBaseColumnName() { if (opType == OpTypes.COLUMN && rangeVariable != null) { return rangeVariable.getTable().getColumn(columnIndex).getName().name; } return null; }
public RangeIteratorBase getCheckIterator(RangeVariable rangeVariable) { RangeIterator it = rangeIterators[1]; if (it == null) { it = rangeVariable.getIterator(session); rangeIterators[1] = it; } return (RangeIteratorBase) it; }
SimpleName getSimpleName() { if (alias != null) { return alias; } if (rangeVariable != null && rangeVariable.hasColumnAlias()) { return rangeVariable.getColumnAlias(columnIndex); } if (column != null) { return column.getName(); } if (opType == OpTypes.COALESCE) { return nodes[LEFT].getSimpleName(); } else if (opType == OpTypes.ROWNUM) { return rownumName; } return null; }
boolean resolvesDuplicateColumnReference(RangeVariable rangeVar) { if (tableName == null) { Expression e = rangeVar.getColumnExpression(columnName); if (e != null) { return false; } switch (rangeVar.rangeType) { case RangeVariable.PARAMETER_RANGE: case RangeVariable.VARIALBE_RANGE: case RangeVariable.TRANSITION_RANGE: return false; default: int colIndex = rangeVar.findColumn(schema, tableName, columnName); return colIndex != -1; } } return false; }
/** * Returns the table name used in query * * @return table name */ String getTableName() { if (opType == OpTypes.MULTICOLUMN) { return tableName; } if (opType == OpTypes.COLUMN) { if (rangeVariable == null) { return tableName; } else { return rangeVariable.getTable().getName().name; } } return ""; }
void recompile(Session session, Table newTable) { String ddl = check.getSQL(); Scanner scanner = new Scanner(ddl); ParserDQL parser = new ParserDQL(session, scanner); parser.read(); parser.isCheckOrTriggerCondition = true; Expression condition = parser.XreadBooleanValueExpression(); check = condition; schemaObjectNames = parser.compileContext.getSchemaObjectNames(); // this workaround is here to stop LIKE optimisation (for proper scripting) QuerySpecification s = Expression.getCheckSelect(session, newTable, check); rangeVariable = s.rangeVariables[0]; rangeVariable.setForCheckConstraint(); }
private boolean resolveColumnReference(RangeVariable rangeVar) { Expression e = rangeVar.getColumnExpression(columnName); if (e != null) { opType = e.opType; nodes = e.nodes; dataType = e.dataType; return true; } int colIndex = rangeVar.findColumn(schema, tableName, columnName); if (colIndex == -1) { return false; } switch (rangeVar.rangeType) { case RangeVariable.PARAMETER_RANGE: case RangeVariable.VARIALBE_RANGE: { if (tableName != null) { return false; } ColumnSchema column = rangeVar.getColumn(colIndex); if (column.getParameterMode() == SchemaObject.ParameterModes.PARAM_OUT) { return false; } else { opType = rangeVar.rangeType == RangeVariable.VARIALBE_RANGE ? OpTypes.VARIABLE : OpTypes.PARAMETER; } break; } case RangeVariable.TRANSITION_RANGE: { if (tableName == null) { return false; } if (schema != null) { return false; } opType = OpTypes.TRANSITION_VARIABLE; break; } default: { break; } } setAttributesAsColumn(rangeVar, colIndex); return true; }