Esempio n. 1
0
        public object Select(RawTableJoinRow rows)
        {
            var selectExpression   = ParseAsSelect(_FunctionCall.Sql);
            var querySpecification = (SqlQuerySpecification)selectExpression.SelectSpecification.QueryExpression;

            var db      = (( MemoryDbConnection )_RawData.Command.Connection).GetMemoryDatabase( );
            var batch   = new MemoryDbDataReader.ResultBatch(  );
            var rawData = new RawData(_RawData.Command, batch);

            rawData.RawRowList.Add(rows);
            var statement = new ExecuteQueryStatement(db, _RawData.Command);

            statement.InitializeFields(batch, querySpecification.SelectClause.Children.ToList(  ), rawData);
            new QueryResultBuilder(rawData, false).AddData(batch);

            var row = batch.ResultRows[0];

            for (int fieldIndex = 0; fieldIndex < batch.Fields.Count; fieldIndex++)
            {
                if (row[fieldIndex] != null && row[fieldIndex] is DBNull == false)
                {
                    _DbType     = (DbType)Enum.Parse(typeof(DbType), batch.Fields[fieldIndex].DbType, true);
                    _ReturnType = batch.Fields[fieldIndex].NetType;
                    return(row[fieldIndex]);
                }
            }
            return(null);
        }
Esempio n. 2
0
        public static object GetValue(SqlScalarExpression expression, MemoryDbDataReader.ResultBatch batch, ArrayList row)
        {
            switch (expression)
            {
            case SqlColumnRefExpression columnRef:
            {
                var name  = GetColumnName(columnRef);
                var field = batch.Fields.FirstOrDefault(f => f.Name == name);
                if (field == null)
                {
                    throw new SqlInvalidColumnNameException(name);
                }

                return(row[field.FieldIndex]);
            }

            case SqlLiteralExpression literal:
            {
                if (literal.Type == LiteralValueType.Integer)
                {
                    var fieldIndex = int.Parse(literal.Value);
                    return(row[fieldIndex]);
                }
                throw new NotImplementedException($"Unsupported scalarExpression : '{ expression.GetType(  ) }'");
            }

            default:
                throw new NotImplementedException($"Unsupported scalarExpression : '{ expression.GetType(  ) }'");
            }
        }
Esempio n. 3
0
        public void AddData(MemoryDbDataReader.ResultBatch batch)
        {
            var internalList = new List <InternalResultRow>(  );

            var fields      = batch.Fields.Cast <MemoryDbDataReader.ReaderFieldData>(  ).ToList();
            var isAggregate = fields
                              .Any(s => s.SelectFieldData is ISelectDataAggregate);

            if (_RawData.GroupByFields.Any( ) || isAggregate)
            {
                AddAggregateRowData(internalList, fields);
            }
            else
            {
                AddRowData(internalList, fields);
            }

            batch.ResultRows = AddOrderedResultRows(batch, fields, internalList, _RawData.SortOrder);
            if (batch.MaxRowsCount.HasValue)
            {
                batch.ResultRows = batch.ResultRows.Take(batch.MaxRowsCount.Value).ToList(  );
            }
        }