Ejemplo n.º 1
0
        string IDfnElement.ToDfnSyntax()
        {
            StringBuilder sb = new StringBuilder();

            // The primary key is special.
            if (this == Table.PkeyGet)
            {
                if (Table.IsPkeySequenced)
                {
                    sb.Append("  pkey sequenced " + Fields[0].Name);
                }
                else
                {
                    sb.Append("  pkey {");
                    sb.Append(Fields.DfnSyntaxList());
                    sb.Append("}");
                }
                if (HasCode && InternalHasIndex && Name == DefaultName)
                {
                    return(sb.ToString());
                }
                sb.Append(" {\r\n");
            }
            else
            {
                sb.Append("  " + DfnSyntaxPrefix + " ");
                sb.Append(IsMulti ? "multi" : "single");
                if (DfnSyntaxTarget != null)
                {
                    sb.Append(" " + DfnSyntaxTarget);
                }
                sb.Append(" {\r\n");
                sb.Append(DfnSyntaxExtraLines);
                if (Tables.Count > 0 || ParamTables.Count > 0)
                {
                    sb.Append("    tables {\r\n");
                    sb.Append(ParamTables.DfnSyntaxList(true));
                    sb.Append(Tables.DfnSyntaxList(true));
                    sb.Append("    };\r\n");
                }
                if (Joins.Count > 0)
                {
                    bool isBy = true;
                    foreach (NrdoJoin join in Joins)
                    {
                        if (!join.isSelfToTarget)
                        {
                            isBy = false;
                        }
                    }
                    if (isBy)
                    {
                        sb.Append("    by {");
                        sb.Append(Joins.MapAndJoin("; ", join => join.From.Field.Name + " " + join.To.Field.Name));
                        sb.Append("};\r\n");
                    }
                    else
                    {
                        sb.Append(Joins.DfnSyntaxBlock("    joins", true));
                    }
                }
                sb.Append(Fields.DfnSyntaxBlock("    fields", false));
                sb.Append(Params.DfnSyntaxBlock("    params", true));
                if (Where != null)
                {
                    sb.Append("    where [" + Where + "];\r\n");
                }
                if (OrderBy.Count > 0)
                {
                    sb.Append(OrderBy.DfnSyntaxBlock("    orderby", false));
                }
            }
            if (!HasCode)
            {
                sb.Append("    nocode;\r\n");
            }
            if (!InternalHasIndex)
            {
                sb.Append("    noindex;\r\n");
            }
            if (Name != DefaultName)
            {
                sb.Append("    called " + Name + ";\r\n");
            }
            sb.Append("  }");
            return(sb.ToString());
        }