Beispiel #1
0
        private static IEnumerable <string> GetParts(ExportSettings.FieldSetting field)
        {
            var parts              = new List <string>();
            var dbType             = QPContext.DatabaseType;
            var ns                 = SqlQuerySyntaxHelper.DbSchemaName(dbType);
            var contentItemIdField = dbType == DatabaseType.Postgres ? "content_item_id::integer" : "content_item_id";

            if (field.Related == null || !field.Related.Any())
            {
                parts.Add($"{SqlQuerySyntaxHelper.CastToString(dbType, field.TableAlias)}.content_item_id");
            }
            else
            {
                foreach (var f in field.Related)
                {
                    switch (f.ExactType)
                    {
                    case FieldExactTypes.M2MRelation:

                        parts.Add($"{ns}.qp_link_titles({f.LinkId.Value}, {field.TableAlias}.{contentItemIdField}, {f.RelatedAttributeId}, 255)");
                        break;

                    case FieldExactTypes.O2MRelation:
                        parts.Add($"{SqlQuerySyntaxHelper.CastToString(dbType, $"{f.TableAlias}.{SqlQuerySyntaxHelper.EscapeEntityName(dbType, f.RelatedAttributeName)}")}");
                        break;

                    case FieldExactTypes.M2ORelation:

                        parts.Add($"{ns}.qp_m2o_titles(base.{contentItemIdField}, {f.Id}, {field.RelatedAttributeId}, 255)");
                        break;

                    default:
                        parts.Add(new[]
                        {
                            FieldExactTypes.Date,
                            FieldExactTypes.DateTime,
                            FieldExactTypes.Time,
                            FieldExactTypes.Textbox,
                            FieldExactTypes.VisualEdit,
                            FieldExactTypes.Numeric,
                            FieldExactTypes.Classifier
                        }.Contains(f.ExactType)
                                ? $"coalesce({SqlQuerySyntaxHelper.CastToString(dbType, $"{field.TableAlias}.{SqlQuerySyntaxHelper.EscapeEntityName(dbType, f.Name)}")}, '')"
                                : $"coalesce( {field.TableAlias}.{SqlQuerySyntaxHelper.EscapeEntityName(dbType, f.Name)}, '')");
                        break;
                    }
                }
            }

            return(parts);
        }