public void NaturalInnerJoin() { SqlExpression expression = null; Assert.DoesNotThrow(() => expression = SqlExpression.Parse("SELECT * FROM persons, codes")); Assert.IsNotNull(expression); Assert.IsInstanceOf <SqlQueryExpression>(expression); SqlExpression resultExpression = null; Assert.DoesNotThrow(() => resultExpression = expression.Evaluate(Query, null)); Assert.IsNotNull(resultExpression); Assert.IsInstanceOf <SqlConstantExpression>(resultExpression); var constantExpression = (SqlConstantExpression)resultExpression; Assert.IsInstanceOf <QueryType>(constantExpression.Value.Type); var queryPlan = ((SqlQueryObject)constantExpression.Value.Value); ITable result = null; Assert.DoesNotThrow(() => result = queryPlan.QueryPlan.Evaluate(Query)); Assert.IsNotNull(result); }
public void SetValue(IQuery context, SqlExpression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } if (IsConstant) { throw new InvalidOperationException(); } if (!expression.IsConstant()) { throw new ArgumentException(); } Expression = expression; var exp = expression.Evaluate(context, null); if (exp.ExpressionType != SqlExpressionType.Constant) { throw new InvalidOperationException(); } var value = ((SqlConstantExpression)exp).Value; SetValue(value); }
private Field Evaluate(SqlExpression expression, IRequest queryContext) { var ignoreCase = queryContext.Query.IgnoreIdentifiersCase(); // Resolve any variables to the table_def for this expression. expression = Table.TableInfo.ResolveColumns(ignoreCase, expression); // Get the variable resolver and evaluate over this data. IVariableResolver vresolver = VariableResolver; var reduced = expression.Evaluate(queryContext, vresolver, null); if (reduced.ExpressionType != SqlExpressionType.Constant) { throw new InvalidOperationException("The DEFAULT expression of the column cannot be reduced to a constant"); } return(((SqlConstantExpression)reduced).Value); }