private static object GetReturnValue(ISelectData select, List <RawTableRow> row) { var value = select.Select(new RawTableJoinRow(row)); return(IsParentUnaryNegate(select.Expression) ? HelperReflection.Negate(value) : value); }
public static object GetValue(SqlScalarExpression expression, Type type, RawData rawData, List <RawTableRow> row, bool getTypeFromLiteral = false) { switch (expression) { case SqlColumnRefExpression columnRef: { var field = GetTableColumn(columnRef, rawData); var select = new SelectDataFromColumn(field, rawData); return(GetReturnValue(select, row)); } case SqlUnaryScalarExpression unaryScalarExpression: { var value = GetValue(unaryScalarExpression.Expression, type, rawData, row); if (unaryScalarExpression.Operator == SqlUnaryScalarOperatorType.Negative) { value = HelperReflection.Negate(value); } return(value); } case SqlLiteralExpression literal: { if (literal.Type == LiteralValueType.Null) { return(null); } var literalType = getTypeFromLiteral ? GetTypeFromLiteralType(literal.Type) : type; return(GetValueFromString(literalType, literal)); } case SqlScalarVariableRefExpression variableRef: { return(GetValueFromParameter(variableRef.VariableName, rawData.Parameters, rawData.Command.Variables)); } case SqlScalarRefExpression scalarRef: { var field = GetTableColumn((SqlObjectIdentifier)scalarRef.MultipartIdentifier, rawData); var select = new SelectDataFromColumn(field, rawData); return(GetReturnValue(select, row)); } case SqlGlobalScalarVariableRefExpression globalRef: { var select = new SelectDataFromGlobalVariables(globalRef.VariableName, rawData); return(GetReturnValue(select, row)); } case SqlBuiltinScalarFunctionCallExpression functionCall: { var select = new SelectDataBuilder( ).Build(functionCall, rawData); return(GetReturnValue(select, row)); } case SqlSearchedCaseExpression caseExpression: { var select = new SelectDataFromCaseExpression(caseExpression, rawData); return(GetReturnValue(select, row)); } case SqlScalarSubQueryExpression subQuery: { var database = new MemoryDbConnection().GetMemoryDatabase( ); var command = new MemoryDbCommand(rawData.Command.Connection, rawData.Command.Parameters, rawData.Command.Variables); return(database.ExecuteSqlScalar(subQuery.QueryExpression.Sql, command)); } case SqlBinaryScalarExpression binaryScalarExpression: { var select = new SelectDataFromBinaryScalarExpression(binaryScalarExpression, rawData); return(GetReturnValue(select, row)); } default: throw new NotImplementedException($"Unsupported scalarExpression : '{ expression.GetType( ) }'"); } }