Exemple #1
0
        private DataTypeInfo GetTypeFromFunction(DataTypeInfo currentDataType,
                                                 SqlBuiltinScalarFunctionCallExpression function, MemoryDatabase database)
        {
            DataTypeInfo dataType = SelectDataBuilder.GetDataTypeFromFunction(function.FunctionName);

            if (dataType != null)
            {
                return(dataType);
            }

            if (function is SqlConvertExpression convert)
            {
                return(new DataTypeInfo(convert.DataType.Sql, database.UserDataTypes));
            }

            var dataTypes = new List <DataTypeInfo>( );

            foreach (var argument in function.Arguments)
            {
                var newDataType = GuessDataType(argument, null, database);
                if (newDataType != null)
                {
                    dataTypes.Add(newDataType);
                }
            }

            dataType = dataTypes.FirstOrDefault(d => d is Column) ?? dataTypes.FirstOrDefault( );
            if (dataType != null)
            {
                return(dataType);
            }
            return(currentDataType);
        }
 public SelectDataFromConnectionInfo(SqlBuiltinScalarFunctionCallExpression functionCall, RawData rawData, SelectDataFunctionInfo info)
 {
     _FunctionCall = functionCall;
     _RawData      = rawData;
     if (info.ReturnDbType.HasValue)
     {
         _ReturnType = info.ReturnType;
         _DbType     = info.ReturnDbType.Value;
     }
 }
Exemple #3
0
 public Column(Table table, string name, int order,
               SqlBuiltinScalarFunctionCallExpression expression, DataTypeInfo type)
     : base(type)
 {
     ParentTable        = table;
     Name               = name;
     Order              = order;
     IsNullable         = true;
     ComputedExpression = expression;
 }
 public SelectDataFromFunctionMathAggregate(SqlBuiltinScalarFunctionCallExpression functionCall, RawData rawData, SelectDataFunctionInfo info)
 {
     _FunctionCall = functionCall;
     _RawData      = rawData;
     if (_NeedsColumn.Contains(_FunctionCall.FunctionName.ToUpper()))
     {
         _ColumnRef = GetSingleColumn(  );
         var tc = Helper.GetTableColumn(_ColumnRef, _RawData);
         _ReturnType = tc.Column.NetDataType;
         _DbType     = tc.Column.DbDataType;
     }
 }
Exemple #5
0
        public SelectDataFromFunctionLeadLag(SqlBuiltinScalarFunctionCallExpression functionCall, RawData rawData, SelectDataFunctionInfo info)
        {
            _FunctionCall = functionCall;
            _RawData      = rawData;
            if (info.ReturnDbType.HasValue)
            {
                _ReturnType = info.ReturnType;
                _DbType     = info.ReturnDbType.Value;
            }

            _SelectExpression = ParseAsSelect(_FunctionCall.Tokens);
            var batch = ExecuteSelect(_SelectExpression, _RawData.RawRowList.FirstOrDefault());

            _DbType     = ( DbType )Enum.Parse(typeof(DbType), batch.Fields[0].DbType, true);
            _ReturnType = batch.Fields[0].NetType;
        }
 public SelectDataFromFunctionConversion(SqlBuiltinScalarFunctionCallExpression functionCall, RawData rawData, SelectDataFunctionInfo info)
 {
     _FunctionCall = functionCall;
     _RawData      = rawData;
     if (info.ReturnDbType.HasValue)
     {
         _ReturnType = info.ReturnType;
         _DbType     = info.ReturnDbType.Value;
     }
     else if (functionCall is SqlCastExpression castFunction)
     {
         var dataTypeInfo = new DataTypeInfo(castFunction.DataType.Sql, rawData.Database.UserDataTypes);
         _ReturnType = dataTypeInfo.NetDataType;
         _DbType     = dataTypeInfo.DbDataType;
     }
 }
Exemple #7
0
        public override void Visit(SqlBuiltinScalarFunctionCallExpression codeObject)
        {
            _stringBuilder.Append($"{codeObject.FunctionName.ToUpper()}(");

            if (codeObject.Arguments != null)
            {
                for (var i = 0; i < codeObject.Arguments.Count; i++)
                {
                    if (i > 0)
                    {
                        _stringBuilder.Append(", ");
                    }

                    codeObject.Arguments[i].Accept(this);
                }
            }

            _stringBuilder.Append(")");
        }
        public ISelectData Build(SqlBuiltinScalarFunctionCallExpression functionCall, RawData rawData)
        {
            var functionName = functionCall.FunctionName.ToUpper();

            if (_Functions.ContainsKey(functionName) == false)
            {
                throw new SqlFunctionNotSupportedException(functionName);
            }

            var info = _Functions[functionName];

            if (info.MinimalArgumentCount > 0 &&
                (functionCall.Arguments == null || functionCall.Arguments.Count < info.MinimalArgumentCount))
            {
                throw new SqlInvalidFunctionParameterCountException(functionCall.FunctionName, info.MinimalArgumentCount);
            }

            return(Activator.CreateInstance(info.SelectType, args: new object[] { functionCall, rawData, info }) as ISelectData);
        }
 public SelectDataFromFunctionRandom(SqlBuiltinScalarFunctionCallExpression functionCall,
                                     RawData rawData, SelectDataFunctionInfo info)
 {
     _FunctionCall = functionCall;
     _RawData      = rawData;
 }
Exemple #10
0
        private void AddFieldForFunctionCall(SqlBuiltinScalarFunctionCallExpression functionCall, string name, MemoryDbDataReader.ResultBatch batch, RawData rawData)
        {
            var select = new SelectDataBuilder(  ).Build(functionCall, rawData);

            AddFieldFromSelectData(name, batch, select);
        }
 public override void Visit(SqlBuiltinScalarFunctionCallExpression codeObject)
 {
     Format(codeObject);
 }