コード例 #1
0
        /// <summary>
        /// The method is called when the user has selected to view a single view.
        /// The method generates a select on all fields, with no joins.
        /// </summary>
        /// <param name="selectedTable">The designer metadata designating the view.</param>
        /// <returns>The string containing the SQL command.</returns>
        private StringBuilder GenerateFromView(ViewsAutomation.IView selectedView)
        {
            var result = new StringBuilder();

            result.AppendLine(string.Format(CultureInfo.InvariantCulture, "use {0}", BusinessDatabaseName));
            result.AppendLine("go");

            if (!string.IsNullOrEmpty(selectedView.DeveloperDocumentation))
            {
                result.Append("-- " + selectedView.Name);
                result.AppendLine(" : " + this.ResolveLabel(selectedView.DeveloperDocumentation));
            }
            else
            {
                result.AppendLine();
            }

            result.AppendLine("select * ");
            result.AppendLine("from " + SqlNameMangling.GetSqlTableName(selectedView.Name));

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Generate the SQL command selecting the set of fields from the given field groups
        /// from the underlying view.
        /// </summary>
        /// <param name="selectedFieldGroups">The list of field groups to select fields from.</param>
        /// <returns>The string containing the SQL command.</returns>
        private StringBuilder GenerateFromViewFieldGroups(IEnumerable <ViewsAutomation.IFieldGroup> selectedFieldGroups)
        {
            var result = new StringBuilder();

            if (!selectedFieldGroups.Any())
            {
                return(result);
            }

            // Used to capture the set of fields containing the union of the fields
            // from the selected field groups.
            var fields = new HashSet <string>();

            ViewsAutomation.IView selectedView = selectedFieldGroups.FirstOrDefault().View;

            foreach (var fieldGroup in selectedFieldGroups)
            {
                var refs = fieldGroup.FieldGroupFieldReferences;
                foreach (IFieldGroupFieldReference reference in refs)
                {
                    fields.Add(reference.DataField);
                }
            }

            // Now the (unique) set of fields is captured.
            // Generate the SQL query from the IBaseField references.
            IList <ViewsAutomation.IViewBaseField> fieldsToSelect = new List <ViewsAutomation.IViewBaseField>();

            foreach (ViewsAutomation.IViewBaseField child in selectedView.ViewBaseFields)
            {
                if (fields.Contains(child.Name))
                {
                    fieldsToSelect.Add(child);
                }
            }

            return(this.GenerateFromViewFieldList(fieldsToSelect));
        }
コード例 #3
0
        /// <summary>
        /// Generate the SQL command selecting the given fields from the underlying table.
        /// </summary>
        /// <param name="fields">The list of fields to select</param>
        /// <returns>The string containing the SQL command.</returns>
        private StringBuilder GenerateFromViewFieldList(IEnumerable <ViewsAutomation.IViewBaseField> fields)
        {
            var result = new StringBuilder();

            result.AppendLine(string.Format(CultureInfo.InvariantCulture, "use {0}", BusinessDatabaseName));
            result.AppendLine("go");

            if (!fields.Any())
            {
                return(result);
            }

            ViewsAutomation.IView selectedView1 = fields.FirstOrDefault().View;
            AxView view = this.MetadataProvider.Views.Read(selectedView1.Name);

            // Expand the developer documentation, if any
            if (!string.IsNullOrEmpty(view.DeveloperDocumentation))
            {
                result.Append("-- " + view.Name);
                result.AppendLine(" : " + this.ResolveLabel(view.DeveloperDocumentation));
            }
            else
            {
                result.AppendLine();
            }

            result.AppendLine("select");
            bool first = true;

            foreach (ViewsAutomation.IViewField field in fields.OfType <ViewsAutomation.IViewField>())
            {
                this.AddField(result, view.Name, field.Name, null, ref first);

                // The field name refers to a name on the datasource. Find the datasource
                // and the underlying table.
                AxTable table = this.FindTableInDataSource(view, field.DataSource);
                table = this.SuperTables(table.Name).First();

                if (table != null)
                {
                    AxTableField tableField = table.Fields[field.DataField];
                    if (tableField != null)
                    {
                        var edt = tableField.ExtendedDataType;

                        if (!string.IsNullOrWhiteSpace(edt))
                        {
                            // See if it happens to be an array field. If so, the first index
                            // does not have a suffix ([<n>]), and has already been written.
                            if (this.MetadataProvider.Edts.Exists(edt))
                            {
                                AxEdt typeDefinition = this.metadataProvider.Edts.Read(edt);
                                for (int i = 2; i <= typeDefinition.ArrayElements.Count + 1; i++)
                                {
                                    var fn = field.Name + "[" + i.ToString(CultureInfo.InvariantCulture) + "]";
                                    this.AddField(result, view.Name, fn, null, ref first);
                                }
                            }
                        }
                    }
                }
            }

            // Now deal with computed columns.
            foreach (ViewsAutomation.IViewComputedColumn computedColumn in fields.OfType <ViewsAutomation.IViewComputedColumn>())
            {
                this.AddField(result, view.Name, computedColumn.Name, null, ref first);
            }

            result.AppendLine("from " + SqlNameMangling.GetSqlTableName(view.Name));

            return(result);
        }