private string calculateAllVersionValueLabelId(LayerVersion lv, bool useAggregateFunction, Cartography level)
        {
            List <string> ret = new List <string>();

            foreach (var v in lv.Variables)
            {
                if (v.Use(useAggregateFunction))
                {
                    string value = LviFunctions.calculateValueField(v);
                    ret.Add(LviFunctions.calculateVersionValueLabelId(v, value, level));
                    ret.Add("'\t'");
                }
            }
            ret.RemoveAt(ret.Count - 1);
            return("CONCAT(" + String.Join(",", ret) + ")");
        }
        private string calculateAllValuesField(LayerVersion lv, bool useAggregateFunction)
        {
            List <string> ret = new List <string>();

            if (lv.Variables.Count == 0)
            {
                throw new Exception("La capa '" + lv.Layer.Caption + "' no tiene indicadores en su revisión '" + lv.Caption + "'.");
            }

            foreach (var v in lv.Variables)
            {
                if (v.Use(useAggregateFunction))
                {
                    ret.Add(LviFunctions.calculateValueField(v));
                    ret.Add("'\t'");
                }
            }
            if (ret.Count > 0)
            {
                ret.RemoveAt(ret.Count - 1);
            }
            return("CONCAT(" + String.Join(",", ret) + ")");
        }
        private void ProcessLayerVersion(string sql, LayerVersion lv, Cartography aggregateLevel = null)
        {
            List <object> fieldList = new List <object>();

            fieldList.Add(lv.Layer.Id.Value);
            fieldList.Add(lv.Id.Value);
            if (aggregateLevel == null)
            {
                fieldList.Add("null");
            }
            else
            {
                fieldList.Add("cai_cartography_id");
            }
            fieldList.Add("cai_id");
            fieldList.Add("cai_urbanity");
            fieldList.Add("id");
            // Valores
            bool   useAggregateFunction = (aggregateLevel != null);
            string allValues            = calculateAllValuesField(lv, useAggregateFunction);

            fieldList.Add(allValues);
            // Etiquetas
            string allVersionValueLabels = calculateAllVersionValueLabelId(lv, useAggregateFunction, aggregateLevel);

            fieldList.Add(allVersionValueLabels);

            // Descripción
            if (useAggregateFunction && lv.DatasetCaptionColumn != null && lv.DatasetCaptionColumn.Aggregation == AggregationEnum.Transpose && useAggregateFunction)
            {
                fieldList.Add("null");
            }
            else
            {
                fieldList.Add(LviFunctions.GetRichColumn(lv.DatasetCaption, lv.DatasetCaptionColumn));
            }
            // Summary
            if (useAggregateFunction && lv.SummaryColumn != null && lv.SummaryColumn.Aggregation == AggregationEnum.Transpose)
            {
                fieldList.Add("0");
            }
            else
            {
                fieldList.Add(LviFunctions.GetRichColumn(lv.Summary, lv.SummaryColumn));
            }

            // featureId
            if (lv.Dataset.DatasetType == DatasetTypeEnum.Shapes ||
                lv.Dataset.DatasetType == DatasetTypeEnum.Locations)
            {
                fieldList.Add(((long)lv.Dataset.Id.Value * 0x100000000) + "+id");
            }
            else
            {
                fieldList.Add("cai_id");
            }

            fieldList.Add(SpecialColumnEnum.AreaM2);
            fieldList.Add(SpecialColumnEnum.People);
            fieldList.Add(SpecialColumnEnum.Household);
            fieldList.Add(SpecialColumnEnum.Children);
            if (lv.Dataset.DatasetType == DatasetTypeEnum.Shapes)
            {
                fieldList.Add("Envelope(geometry)");
                fieldList.Add("id");
                fieldList.Add("area_m2");
                fieldList.Add("centroid");
            }
            else if (lv.Dataset.DatasetType == DatasetTypeEnum.Locations)
            {
                string point = "POINT(" + lv.Dataset.LatitudeColumn.Field + ", " +
                               lv.Dataset.LongitudeColumn.Field + ")";
                fieldList.Add("Envelope(" + point + ")");
                fieldList.Add(null);
                fieldList.Add(null);
                fieldList.Add(point);
            }
            else if (lv.Dataset.DatasetType == DatasetTypeEnum.Data)
            {
                fieldList.Add("Envelope(cai_geometry)");
                fieldList.Add(null);
                fieldList.Add(null);
                fieldList.Add("cai_centroid");
            }
            else
            {
                throw new Exception("Invalid dataset type.");
            }

            int joinShapesId;

            if (lv.Dataset.DatasetType == DatasetTypeEnum.Shapes)
            {
                joinShapesId = lv.Dataset.Id.Value;
            }
            else
            {
                joinShapesId = 0;
            }
            string select = DatasetTable.GetSelectValuesSql(lv.Dataset, fieldList, aggregateLevel);

            select += LviFunctions.AppendGeometryNotNullCondition(lv);

            rowsAffected += medea.context.Data.Session.SqlActions.ExecuteNonQuery(sql + select, true);
        }