/// <summary>
        /// The method is called when the user has selected to view a table extension instance.
        /// The method generates a select on all fields, with no joins.
        /// </summary>
        /// <param name="selectedExtensionTable">The designer metadata designating the view.</param>
        /// <returns>The string containing the SQL command.</returns>
        private StringBuilder GenerateFromTableExtension(Tables.ITableExtension selectedExtensionTable, bool addGroupBy)
        {
            var  result = new StringBuilder();
            bool first  = true;

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

            Metadata.MetaModel.AxTableExtension extension = this.MetadataProvider.TableExtensions.Read(selectedExtensionTable.Name);
            var baseTableName = selectedExtensionTable.Name.Split('.').First();
            var tables        = this.SuperTables(baseTableName);

            tableName = baseTableName;

            HashSet <string> extendedFields = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var extendedField in extension.Fields)
            {
                extendedFields.Add(extendedField.Name);
            }

            if (tables.First().SaveDataPerCompany == Metadata.Core.MetaModel.NoYes.Yes)
            {
                result.AppendLine($"SELECT {SqlNameMangling.GetSqlTableName(tables.First().Name)}.DATAAREAID, COUNT(*) AS COUNTER");
            }
            else
            {
                result.AppendLine("SELECT COUNT(*) AS COUNTER");
            }

            result.AppendLine("FROM " + SqlNameMangling.GetSqlTableName(tables.First().Name));

            if (tables.First().SaveDataPerCompany == Metadata.Core.MetaModel.NoYes.Yes && addGroupBy)
            {
                result.AppendLine($"GROUP BY {SqlNameMangling.GetSqlTableName(tables.First().Name)}.{SqlNameMangling.GetValidSqlNameForField("DATAAREAID")}");
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// The method is called when the user has selected to view a table extension instance.
        /// The method generates a select on all fields, with no joins.
        /// </summary>
        /// <param name="selectedExtensionTable">The designer metadata designating the view.</param>
        /// <returns>The string containing the SQL command.</returns>
        private StringBuilder GenerateFromTableExtension(TablesAutomation.ITableExtension selectedExtensionTable)
        {
            var  result = new StringBuilder();
            bool first  = true;

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

            AxTableExtension extension = this.MetadataProvider.TableExtensions.Read(selectedExtensionTable.Name);
            var baseTableName          = selectedExtensionTable.Name.Split('.').First();
            var tables = this.SuperTables(baseTableName);

            HashSet <string> extendedFields = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var extendedField in extension.Fields)
            {
                extendedFields.Add(extendedField.Name);
            }

            result.AppendLine("select ");

            // List the extension fields first...
            this.AddFields(result, tables.First(), extension.Fields, ref first);

            // Then the normal ones...
            this.AddFields(result, tables.First(), tables.First().Fields.Where(f => !extendedFields.Contains(f.Name)), ref first);

            // And then system fields
            this.AddSystemFields(result, tables.First(), ref first);

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

            if (tables.First().SaveDataPerCompany == Metadata.Core.MetaModel.NoYes.Yes)
            {
                result.AppendLine("-- where " + SqlNameMangling.GetValidSqlNameForField("DataAreaId") + " = 'DAT'");
            }

            return(result);
        }