Exemplo n.º 1
0
        private (string fieldName, object value) CheckComparisonArguments(ScalarExpression left, ScalarExpression right)
        {
            ColumnReference columnReference = null;
            object          value           = null;

            if (left is ColumnReference leftColumn)
            {
                columnReference = leftColumn;
            }
            if (right is ColumnReference rightColumn)
            {
                if (columnReference != null)
                {
                    //TODO: Fix exception
                    throw new System.Exception("Elasticsearch filter can not compare two columns");
                }
                columnReference = rightColumn;
            }
            if (left is Literal leftLiteral)
            {
                value = leftLiteral.GetValue();
            }
            if (right is Literal rightLiteral)
            {
                value = rightLiteral.GetValue();
            }
            if (columnReference == null || value == null)
            {
                throw new System.Exception("Comparisions for elasticsearch filter must contain only a column and a value");
            }
            return(string.Join(".", columnReference.Identifiers), value);
        }
Exemplo n.º 2
0
        public override void VisitColumnReference(ColumnReference columnReference)
        {
            var identifiers = columnReference.Identifiers;

            if (_lambdaParameters != null &&
                _lambdaParameters.Count > 0 &&
                _lambdaParameters.Peek().TryGetValue(identifiers.FirstOrDefault(), out var parameterExpression))
            {
                if (identifiers.Count > 1)
                {
                    AddExpressionToStack(MemberUtils.GetSubfieldMember(identifiers, 1, parameterExpression, _visitorMetadata.OperationsProvider));
                }
                else
                {
                    AddExpressionToStack(parameterExpression);
                }

                return;
            }

            identifiers = MemberUtils.RemoveAlias(_previousStage, identifiers);
            var memberAccess = MemberUtils.GetMember(_previousStage, identifiers, _visitorMetadata.OperationsProvider, out var property);

            AddUsedProperty(property);
            AddExpressionToStack(memberAccess);
            AddNameToStack(string.Join(".", identifiers));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Creates a sheet reference from a rectangle and a sheet
        /// </summary>
        /// <param name="rect">The rectangle to create the sheet reference from</param>
        /// <param name="sheet">The sheet that the reference will be on</param>
        /// <returns>A sheet reference that matches the given rectangle and is on the given sheet</returns>
        /// <remarks>
        ///     Use this method when you have a rectangle that you would like translated into a sheet reference.  Note that the
        ///     top-left corner of the sheet is (1,1).  The method will try to create the appropriate type of reference based on
        ///     the
        ///     dimensions of the rectangle.  For example: A rectangle 1 unit wide and 1 unit tall will be translated into a cell
        ///     reference
        /// </remarks>
        /// <exception cref="T:System.ArgumentException">
        ///     <para>The resulting sheet reference is not within the bounds of its sheet</para>
        ///     <para>The given sheet argument is not registered with the SheetManager</para>
        /// </exception>
        /// <example>
        ///     The following code creates a reference to the range A1:B2 on the currently active sheet
        ///     <code>
        /// Dim engine As New FormulaEngine
        /// Dim rect As New Rectangle(1, 1, 2, 2)
        /// Dim ref As ISheetReference = factory.FromRectangle(rect)
        /// </code>
        /// </example>
        public ISheetReference FromRectangle(ISheet sheet, Rectangle rect)
        {
            FormulaEngine.ValidateNonNull(sheet, "sheet");
            SheetReference @ref;
            Rectangle      sheetRect = SheetReference.GetSheetRectangle(sheet);

            if (rect.Width == 1 & rect.Height == 1)
            {
                @ref = new CellReference(rect.Top, rect.Left);
            }
            else if (rect.Height == sheetRect.Height)
            {
                @ref = new ColumnReference(rect.Left, rect.Right - 1);
            }
            else if (rect.Width == sheetRect.Width)
            {
                @ref = new RowReference(rect.Top, rect.Bottom - 1);
            }
            else
            {
                @ref = new CellRangeReference(rect);
            }

            InitializeGridReference(@ref, sheet);
            return(@ref);
        }
Exemplo n.º 4
0
        public void TestBasicColumnReference()
        {
            var ctx   = new Machine().Initialize();
            var table = new TableMeta()
            {
                Name = "table"
            };

            Context.AddColumn(new ColumnMeta()
            {
                Name = "a", Type = ColumnType.Number
            }, table);
            ctx.AddTable(table);

            var input = "table.a";

            var parser    = new Parser();
            var reference = parser.ParseReference(input, 0, ctx, new SelectStatement(), new Parser.ReferenceFlags()
            {
                ResolveReferences = true
            });
            var expected = new ColumnReference()
            {
                Column = "a", Table = "table", InputLength = input.Length
            };

            Assert.AreEqual(reference, expected);
        }
Exemplo n.º 5
0
        public ColumnReferenceInfo(String alias, ColumnReference reference)
        {
            ArgumentValidator.ValidateNotNull(nameof(reference), reference);

            this._alias     = alias;
            this._reference = reference;
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Creates a reference to a range of columns on a given sheet
        /// </summary>
        /// <param name="sheet">The sheet the reference will use</param>
        /// <param name="start">The left column of the range</param>
        /// <param name="finish">The right column of the range</param>
        /// <returns>A sheet reference to the range of columns on the given sheet</returns>
        /// <remarks>
        ///     This method will create a sheet reference to an entire range of columns on the given sheet.  Use it when you
        ///     want to reference entire columns and have the two indices handy.
        /// </remarks>
        /// <exception cref="T:System.ArgumentException">
        ///     <para>The resultant range is not within the bounds of the given sheet</para>
        ///     <para>The given sheet argument is not registered with the SheetManager</para>
        /// </exception>
        /// <example>
        ///     The following example creates a reference to columns A through C on the currently active sheet
        ///     <code>
        /// Dim engine As New FormulaEngine
        /// Dim ref As ISheetReference = engine.ReferenceFactory.Columns(1, 3)
        /// </code>
        /// </example>
        public ISheetReference Columns(ISheet sheet, int start, int finish)
        {
            FormulaEngine.ValidateNonNull(sheet, "sheet");
            var @ref = new ColumnReference(start, finish);

            InitializeGridReference(@ref, sheet);
            return(@ref);
        }
Exemplo n.º 7
0
        public void TestColumnReferenceAccept()
        {
            Mock <KoraliumSqlVisitor> mock            = new Mock <KoraliumSqlVisitor>();
            ColumnReference           columnReference = new ColumnReference();

            columnReference.Accept(mock.Object);
            mock.Verify(x => x.VisitColumnReference(columnReference));
        }
Exemplo n.º 8
0
        public void TestVisitColumnReference()
        {
            ColumnReference    columnReference    = new ColumnReference();
            KoraliumSqlVisitor koraliumSqlVisitor = new KoraliumSqlVisitor();

            koraliumSqlVisitor.Visit(columnReference);

            //Nothing to verify yet, only that no exceptions are thrown
            Assert.Pass();
        }
Exemplo n.º 9
0
        public override void VisitColumnReference(ColumnReference columnReference)
        {
            var identifiers = columnReference.Identifiers;

            identifiers = MemberUtils.RemoveAlias(_previousStage, identifiers);
            var memberAccess = MemberUtils.GetMember(_previousStage, identifiers, _visitorMetadata.OperationsProvider, out var property);

            _usedProperties.Add(property);

            _groupByExpressions.Add(new GroupByExpression(memberAccess, string.Join(".", identifiers), property));
        }
Exemplo n.º 10
0
        public ColumnMeta FindColumn(ColumnReference reference)
        {
            var tableMeta = FindTable(reference);

            if (tableMeta != null)
            {
                return(tableMeta.Columns.Find(c => c.Name.ToUpper() == reference.Column.ToUpper()));
            }

            return(null);
        }
Exemplo n.º 11
0
        private VisitResult VisitColumnReferenceExpression_Internal(ColumnReference columnReference)
        {
            var identifiers = columnReference.Identifiers;

            identifiers = MemberUtils.RemoveAlias(_previousStage, identifiers);
            var memberAccess = MemberUtils.GetMember(_previousStage, identifiers, _visitorMetadata.OperationsProvider, out var property);

            AddUsedProperty(property);
            return(new VisitResult()
            {
                Expression = memberAccess
            });
        }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="column"></param>
        /// <returns></returns>
        /// <remarks>
        /// In this function call, tables are always referenced by
        /// their aliases, if they have one.
        /// </remarks>
        public string GetResolvedColumnName(ColumnReference column)
        {
            string tablename;

            if (!String.IsNullOrEmpty(column.TableReference.Alias))
            {
                tablename = QuoteIdentifier(column.TableReference.Alias);
            }
            else
            {
                tablename = GetResolvedTableName(column.TableReference);
            }

            return(GetResolvedColumnName(tablename, column.ColumnName));
        }
Exemplo n.º 13
0
        public void TestCloneColumnReference()
        {
            ColumnReference columnReference = new ColumnReference()
            {
                Identifiers = new List <string>()
                {
                    "test"
                }
            };

            var clone = columnReference.Clone() as ColumnReference;

            Assert.AreEqual(columnReference, clone);
            Assert.IsFalse(ReferenceEquals(columnReference, clone));
            Assert.IsFalse(ReferenceEquals(columnReference.Identifiers, clone.Identifiers));
        }
        private Column ResolveColumnReference(Table table, Column column)
        {
            ColumnReference columnRef = column as ColumnReference;

            if (columnRef == null)
            {
                return(column);
            }

            var result = table.Columns.SingleOrDefault(c => c.Name == columnRef.Name);

            if (result == null)
            {
                throw new TaupoInvalidOperationException("The column '" + columnRef.Name + "' was not found in '" + table + "'");
            }

            return(result);
        }
Exemplo n.º 15
0
        public ColumnReference TryFindReferenceRecursive(ColumnReference reference, int level)
        {
            if (reference.Table == MainSource.Table || reference.Table == MainSource.Identifier)
            {
                reference.Table           = MainSource.Table;
                reference.TableIdentifier = MainSource.Identifier;
                reference.ParentLevel     = level;
                return(reference);
            }

            if (Parent != null)
            {
                return(Parent.TryFindReferenceRecursive(reference, level + 1));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Assigns the column node unique identifier for expression.
        /// </summary>
        /// <param name="columns">The columns.</param>
        /// <param name="reportColumn">The report column.</param>
        /// <param name="context">The context.</param>
        private static void AssignColumnNodeGuidForExpression(IEnumerable <SelectColumn> columns, ReportColumn reportColumn, FromEntityContext context)
        {
            // Get the GUID of the report column
            Guid reportColumnGuid;

            if (context.ReportColumnMap.ContainsKey(reportColumn.Id))
            {
                reportColumnGuid = context.ReportColumnMap[reportColumn.Id];
            }
            else
            {
                return;
            }

            // Look up the select column using the GUID
            SelectColumn selectColumn = columns.FirstOrDefault(c => c.ColumnId == reportColumnGuid);

            if (selectColumn == null)
            {
                return;
            }
            // Handle column reference expressions
            if (selectColumn.Expression != null)
            {
                ColumnReferenceExpression columnReferenceExpression =
                    reportColumn.ColumnExpression.As <ColumnReferenceExpression>();
                if (columnReferenceExpression != null)
                {
                    long rootNodeId = columnReferenceExpression.ExpressionReferencesColumn.Id;
                    // Get the GUID for the referenced column rather than root node and populate
                    ColumnReference columnReference = selectColumn.Expression as ColumnReference;
                    if (columnReference != null)
                    {
                        columnReference.ColumnId = context.ReportColumnMap[rootNodeId];
                    }
                }
                else
                {
                    ResolveExpressionToNode(StructuredQueryHelper.WalkExpressions(selectColumn.Expression), context);
                }
            }
        }
Exemplo n.º 17
0
 private SheetReference TryParseGridReference(string s)
 {
     if (CellReference.IsValidString(s))
     {
         return(CellReference.FromString(s));
     }
     if (CellRangeReference.IsValidString(s))
     {
         return(CellRangeReference.FromString(s));
     }
     if (ColumnReference.IsValidString(s))
     {
         return(ColumnReference.FromString(s));
     }
     if (RowReference.IsValidString(s))
     {
         return(RowReference.FromString(s));
     }
     return(null);
 }
Exemplo n.º 18
0
        /// <summary>
        /// Resolves the references to hook up various node and column identifiers from the entity model context.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="report">The report.</param>
        /// <param name="context">The context.</param>
        internal static void ResolveReferences(StructuredQuery query, Report report, FromEntityContext context)
        {
            if (query.RootEntity is AggregateEntity)
            {
                AggregateEntity ae = query.RootEntity as AggregateEntity;
                foreach (ResourceDataColumn rdc in ae.GroupBy.OfType <ResourceDataColumn>())
                {
                    rdc.NodeId = context.ReportNodeMap[rdc.SourceNodeEntityId];
                }
            }
            // Resolve the Node Expressions for report columns
            foreach (ReportColumn reportColumn in report.ReportColumns)
            {
                AssignColumnNodeGuidForExpression(query.SelectColumns, reportColumn, context);
            }

            // Resolve the Node expressions for the analyser
            foreach (QueryCondition queryCondition in query.Conditions)
            {
                ResolveExpressionToNode(StructuredQueryHelper.WalkExpressions(queryCondition.Expression), context);

                ColumnReference columnReference = queryCondition.Expression as ColumnReference;
                //if the expression is ColumnReferenceExpression, the referenced report column must exists
                if (columnReference != null && context.ColumnReferenceMap.ContainsKey(columnReference.ExpressionId) && context.ReportColumnMap.ContainsKey(context.ColumnReferenceMap[columnReference.ExpressionId]))
                {
                    columnReference.ColumnId = context.ReportColumnMap[context.ColumnReferenceMap[columnReference.ExpressionId]];
                }
            }

            // Resolve the order by expressions (NOTE: Am assuming that order by can only contain column references here)
            foreach (ColumnReference columnReference in query.OrderBy.Select(orderByItem => orderByItem.Expression).OfType <ColumnReference>())
            {
                //the orderby expression is ColumnReferenceExpression, the referenced report column must exists
                if (context.ColumnReferenceMap.ContainsKey(columnReference.ExpressionId) &&
                    context.ReportColumnMap.ContainsKey(context.ColumnReferenceMap[columnReference.ExpressionId]))
                {
                    columnReference.ColumnId =
                        context.ReportColumnMap[context.ColumnReferenceMap[columnReference.ExpressionId]];
                }
            }
        }
Exemplo n.º 19
0
        public override void VisitColumnReference(ColumnReference columnReference)
        {
            var identifiers = columnReference.Identifiers;

            identifiers = MemberUtils.RemoveAlias(_previousStage, identifiers);

            Expression expression;

            if (_inAggregateFunction)
            {
                expression = MemberUtils.GetMemberGroupByInValue(_previousStage, identifiers, _visitorMetadata.OperationsProvider, out var property);
                AddUsedProperty(property);
            }
            else
            {
                expression = MemberUtils.GetMemberGroupByInKey(_previousStage, identifiers, _visitorMetadata.OperationsProvider, out var property);
                AddUsedProperty(property);
            }

            AddExpressionToStack(expression);
            AddNameToStack(string.Join(".", identifiers));
        }
Exemplo n.º 20
0
        public void TestTableReference()
        {
            var ctx = new Machine().Initialize();

            ctx.AddTable(new TableMeta()
            {
                Name = "table"
            });

            var input = "table";

            var parser    = new Parser();
            var reference = parser.ParseReference(input, 0, ctx, new SelectStatement(), new Parser.ReferenceFlags()
            {
                TableOnly = true
            });
            var expected = new ColumnReference()
            {
                Table = "table"
            };

            Assert.AreEqual(reference, expected);
        }
Exemplo n.º 21
0
        public void TestColumnReferenceEquals()
        {
            ColumnReference first = new ColumnReference()
            {
                Identifiers = new List <string>()
                {
                    "test"
                }
            };

            ColumnReference firstClone = new ColumnReference()
            {
                Identifiers = new List <string>()
                {
                    "test"
                }
            };

            ColumnReference second = new ColumnReference()
            {
                Identifiers = new List <string>()
                {
                    "test2"
                }
            };

            //Equals
            Assert.IsTrue(Equals(first, firstClone));
            Assert.IsFalse(Equals(first, null));
            Assert.IsFalse(Equals(first, "test"));
            Assert.IsFalse(Equals(first, second));

            //Hash code
            Assert.AreEqual(first.GetHashCode(), firstClone.GetHashCode());
            Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
        }
Exemplo n.º 22
0
 public override void VisitColumnReference(ColumnReference columnReference)
 {
     //Add the alias to the front
     columnReference.Identifiers.Insert(0, _tableAlias);
 }
Exemplo n.º 23
0
 protected virtual void ColumnRef(ColumnReference colref)
 {
     Put("%i", colref.RefColumnName);
     //WriteRaw(QuoteIdentifier(colref.Name, null));
 }
Exemplo n.º 24
0
        /// <summary>
        /// Remove any columns from a report that are not required to achieve a rollup result.
        /// </summary>
        /// <remarks>
        /// If columns get removed here then the query optimiser will later remove various joins.
        /// This can affect whether some rows are repeated.
        /// Some aggregate types (e.g. max/min) are unaffected by this.
        /// Some types (e.g. Count) are very affected by this, so we replace columns with simpler ones, rather than removing them completely.
        /// Some types (e.g. Sum) in principle could be affected by this, but in practice are OK because they will reference the relationship branch that is relevant to them anyway.
        /// </remarks>
        /// <param name="query">The original query.</param>
        /// <param name="clientAggregate">Aggregate settings that are used to determine what columns are used.</param>
        /// <returns>A clone of the query, with unused columns removed.</returns>
        public static StructuredQuery RemoveUnusedColumns(StructuredQuery query, ClientAggregate clientAggregate, bool supportQuickSearch = false)
        {
            StructuredQuery queryCopy = query.DeepCopy( );

            // Determine columns that are used by the rollup
            HashSet <Guid> referencedColumns = new HashSet <Guid>(clientAggregate.AggregatedColumns.Select(a => a.ReportColumnId)
                                                                  .Concat(clientAggregate.GroupedColumns.Select(g => g.ReportColumnId)));

            // Also include columns that are referenced by analyzer conditions
            foreach (QueryCondition condition in query.Conditions)
            {
                ColumnReference colRefExpr = condition.Expression as ColumnReference;
                if (colRefExpr == null)
                {
                    continue;
                }
                referencedColumns.Add(colRefExpr.ColumnId);
            }

            // Ensure that the inner report returns at least something. (This will typically be the ID column).
            if (referencedColumns.Count == 0 && query.SelectColumns.Count > 0)
            {
                referencedColumns.Add(query.SelectColumns [0].ColumnId);
            }

            // There are two types of optimisations. Either we can just pull out all unused columns, and let the structured query optimiser
            // remove the subsequent relationship joins - which is OK for things like max & min in particular.
            // But in some cases (e.g. for Count) we need to ensure we capture all relationships to get the true fanout.
            // This is safer, but less efficient.
            bool strictlyMaintainRowPresence = clientAggregate.AggregatedColumns.Any(ag => ag.AggregateMethod == AggregateMethod.Count);

            if (!strictlyMaintainRowPresence)
            {
                // Remove all unused columns
                queryCopy.SelectColumns.RemoveAll(column => !referencedColumns.Contains(column.ColumnId));
            }
            else
            {
                // Visit each column and determine if it can be removed, or converted to a simpler type
                List <SelectColumn> columns  = queryCopy.SelectColumns;
                List <Guid>         toRemove = new List <Guid>( );
                for (int i = 0; i < columns.Count; i++)
                {
                    SelectColumn column = columns [i];
                    if (referencedColumns.Contains(column.ColumnId))
                    {
                        continue;
                    }

                    // Replace field lookups with an equivalent ID column .. to maintain the relationship join, but remove the field join.
                    ResourceDataColumn fieldColumnExpr = column.Expression as ResourceDataColumn;
                    if (fieldColumnExpr != null)
                    {
                        // TODO: we could delete this column entire IF the entire relationship path to it is 'to one' relationships, without any advance properties to enforce rows.
                        // UPDATE: for quick serach purpose, the column expression should be ResourceDataColumn but skip in select clause.
                        // however for performance reasons, if without quick search, still change to IdExpression
                        if (supportQuickSearch)
                        {
                            column.IsHidden = true;
                        }
                        else
                        {
                            column.Expression = new IdExpression {
                                NodeId = fieldColumnExpr.NodeId
                            }
                        };

                        continue;
                    }

                    // Remove aggregate expressions if they don't have group-bys. (A group-by would cause the aggregate to return more than one row).
                    AggregateExpression aggExpr = column.Expression as AggregateExpression;
                    if (aggExpr != null)
                    {
                        AggregateEntity aggNode = StructuredQueryHelper.FindNode(queryCopy.RootEntity, aggExpr.NodeId) as AggregateEntity;
                        if (aggNode != null)
                        {
                            if (aggNode.GroupBy == null || aggNode.GroupBy.Count == 0)
                            {
                                toRemove.Add(column.ColumnId);
                            }
                        }
                    }

                    // Would be nice to remove calculated columns .. but probably too risky
                }
                queryCopy.SelectColumns.RemoveAll(column => toRemove.Contains(column.ColumnId));
            }

            // Remove any obsolete order-by instructions
            queryCopy.OrderBy.RemoveAll(orderBy =>
            {
                ColumnReference colRefExpr = orderBy.Expression as ColumnReference;
                if (colRefExpr == null)
                {
                    return(false);
                }

                bool colStillPresent = queryCopy.SelectColumns.Any(column => column.ColumnId == colRefExpr.ColumnId);
                return(!colStillPresent);
            });

            return(queryCopy);
        }
    }
Exemplo n.º 25
0
 protected AbstractColumnCommand(int num, XElement inner) : base(num)
 {
     this.column = XMLParser.ParseColumnReference(inner);
 }
Exemplo n.º 26
0
 public virtual void VisitColumnReference(ColumnReference columnReference)
 {
     //NOP
 }
Exemplo n.º 27
0
 public ColumnReferenceInfo(ColumnReference aRef)
     : this(null, aRef)
 {
 }
        /// <summary>
        /// Gets the drawing information for a particular element in the compartment.
        /// </summary>
        /// <param name="listField">The <see cref="ShapeField"/> of this <see cref="ColumnElementListCompartment"/> which
        /// paints the items in this compartment.</param>
        /// <param name="row">The index of the array of items whose item drawing information is of interest.</param>
        /// <param name="itemDrawInfo">A previously initialized <see cref="ItemDrawInfo"/> object whose properties will be modified.</param>
        public override void GetItemDrawInfo(ListField listField, int row, ItemDrawInfo itemDrawInfo)
        {
            base.GetItemDrawInfo(listField, row, itemDrawInfo);
            Column currentColumn = this.Items[row] as Column;

            Debug.Assert(currentColumn != null, "An item in the ColumnElementListCompartment is not a column.");

            if (!currentColumn.IsNullable)
            {
                itemDrawInfo.AlternateFont = true;
            }

            StringBuilder columnText     = new StringBuilder();
            bool          seenConstraint = false;
            LinkedElementCollection <UniquenessConstraint> tableUniquenessConstraints = null;
            Table currentTable = null;

            foreach (UniquenessConstraint constraint in UniquenessConstraintIncludesColumn.GetUniquenessConstraints(currentColumn))
            {
                if (seenConstraint)
                {
                    columnText.Append(CommaString);
                }
                if (constraint.IsPrimary)
                {
                    columnText.Append(PrimaryKeyString);
                }
                else
                {
                    if (tableUniquenessConstraints == null)
                    {
                        currentTable = currentColumn.Table;
                        tableUniquenessConstraints = currentTable.UniquenessConstraintCollection;
                    }
                    int constraintNumber = 0;
                    foreach (UniquenessConstraint tableConstraint in tableUniquenessConstraints)
                    {
                        if (!tableConstraint.IsPrimary)
                        {
                            ++constraintNumber;
                            if (tableConstraint == constraint)
                            {
                                break;
                            }
                        }
                    }
                    columnText.AppendFormat(AlternateKeyString, constraintNumber);
                }
                seenConstraint = true;
            }
            LinkedElementCollection <ReferenceConstraint> tableReferenceConstraints = null;

            foreach (ColumnReference columnReference in ColumnReference.GetLinksToTargetColumnCollection(currentColumn))
            {
                if (seenConstraint)
                {
                    columnText.Append(CommaString);
                }
                if (tableReferenceConstraints == null)
                {
                    if (currentTable == null)
                    {
                        currentTable = currentColumn.Table;
                    }
                    tableReferenceConstraints = currentTable.ReferenceConstraintCollection;
                }
                columnText.AppendFormat(ForeignKeyString, tableReferenceConstraints.IndexOf(columnReference.ReferenceConstraint) + 1);
                seenConstraint = true;
            }
            if (seenConstraint)
            {
                columnText.Append(ColonString);
            }
            columnText.Append(currentColumn.Name);
            if (((RelationalDiagram)this.Diagram).DisplayDataTypes)
            {
                columnText.Append(ColonString);
                columnText.Append(GetDataType(currentColumn.AssociatedValueType));
            }
            itemDrawInfo.Text = columnText.ToString();
        }
Exemplo n.º 29
0
 public override Reference CreateReference()
 {
     return(ColumnReference.FromString(_image));
 }
Exemplo n.º 30
0
        /// <summary>
        ///     Gets the type of the column database.
        /// </summary>
        /// <param name="sourceQuery">The source query.</param>
        /// <param name="selectColumn">The select column.</param>
        /// <returns></returns>
        private static DatabaseType GetColumnDatabaseType(StructuredQuery sourceQuery, SelectColumn selectColumn)
        {
            DatabaseType columnType = DatabaseType.UnknownType;

            var field = selectColumn.Expression as ResourceDataColumn;

            if (field != null)
            {
                ResourceDataColumn dataField = field;
                if (dataField.CastType != null && dataField.CastType.GetDisplayName( ) != DatabaseType.UnknownType.GetDisplayName( ))
                {
                    columnType = dataField.CastType;
                }
                else
                {
                    columnType = GetFieldDataType(dataField.FieldId);
                }
            }
            else if (selectColumn.Expression is StructureViewExpression)
            {
                columnType = DatabaseType.StructureLevelsType;
            }
            else
            {
                var expression = selectColumn.Expression as CalculationExpression;

                if (expression != null)
                {
                    //TODO hack now
                    if (expression.DisplayType != null && expression.DisplayType != DatabaseType.UnknownType)
                    {
                        return(expression.DisplayType);
                    }
                }
                else
                {
                    var reference = selectColumn.Expression as ColumnReference;

                    if (reference != null)
                    {
                        ColumnReference columnReference = reference;
                        // Sanity check. Prevent infinite recursion
                        if (columnReference.ColumnId != selectColumn.ColumnId)
                        {
                            SelectColumn referencedColumn = sourceQuery.SelectColumns.FirstOrDefault(c => c.ColumnId == columnReference.ColumnId);
                            columnType = GetColumnDatabaseType(sourceQuery, referencedColumn);
                        }
                    }
                    else
                    {
                        var aggregateExpression = selectColumn.Expression as AggregateExpression;

                        if (aggregateExpression != null)
                        {
                            if (aggregateExpression.Expression is StructureViewExpression)
                            {
                                columnType = DatabaseType.StructureLevelsType;
                            }
                            else
                            {
                                columnType = (aggregateExpression.Expression is ResourceDataColumn) ? ((ResourceDataColumn)(aggregateExpression.Expression)).CastType : DatabaseType.StringType;
                            }
                        }
                        else if (selectColumn.Expression is IdExpression)
                        {
                            columnType = DatabaseType.IdentifierType;
                        }
                    }
                }
            }

            return(columnType);
        }
Exemplo n.º 31
0
        // ---
        private string GetResolvedColumnName(ColumnReference column)
        {
            string tablename;
            if (!String.IsNullOrEmpty(column.TableReference.Alias))
            {
                tablename = QuoteIdentifier(column.TableReference.Alias);
            }
            else
            {
                tablename = GetResolvedTableName(column.TableReference);
            }

            return String.Format("{0}.{1}", tablename, QuoteIdentifier(column.ColumnName));
        }