Ejemplo n.º 1
0
    public string GetDdl()
    {
        var colums = Colums.Select(x =>
        {
            var sql = $"{x.ColumName} {x.ColumType}";
            if (x.KeyKind == ConstraintsKind.Primary && Indexs.Count(idx => idx.FieldNames.Contains(x.ColumName)) < 1)
            {
                sql += " primary key";
            }
            else if (x.KeyKind == ConstraintsKind.NotNull)
            {
                sql += " not null";
            }
            return(sql.ToUpper());
        });

        var index = Indexs.GroupBy(x => x.IndexName)
                    .Where(x => 0 < x.Count())
                    .Select(x =>
        {
            var sql = "PRIMARY KEY (";
            foreach (var col in x)
            {
                sql += col.FieldNames;
            }
            sql += ")";
            return(sql);
        });

        return($"CREATE TABLE {TableName.ToUpper()} ({ string.Join(", ", colums.Union(index).ToArray())})");
    }
Ejemplo n.º 2
0
        public TEntity Update(TEntity entity)
        {
            if (entity is EntityBase)
            {
                (entity as EntityBase).Status = Entities.Enums.RowStatus.Updated;
            }
            var updateCmd  = string.Join(",", Colums.Split(',').Select(x => string.Format("[{0}].[{1}] = @{1}", TableName, x)));
            var entityList = connection.Query <TEntity>(string.Format(UPDATE_QUERY, TableName, updateCmd), entity);

            return(GetById(entity.Id));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the Next response values
        /// </summary>
        /// <returns></returns>
        public List <DataMessageObject> GetNext()
        {
            try
            {
                if (DBDataReader.Read())
                {
                    string ColTime = Colums.FirstOrDefault(col => col.Value.ConceptType == ConceptTypeEnum.Dimension && ((IDimensionConcept)col.Value).DimensionType == DimensionTypeEnum.Time).Key;
                    string TimeVal = DBDataReader[ColTime].ToString();

                    Dictionary <string, object> Vals = new Dictionary <string, object>();
                    foreach (string col in Colums.Keys)
                    {
                        if (Colums[col] != null && Colums[col].ConceptType == ConceptTypeEnum.Dimension && ((IDimensionConcept)Colums[col]).DimensionType == DimensionTypeEnum.Frequency && ((IDimensionConcept)Colums[col]).IsFakeFrequency)
                        {
                            Vals[col] = (TimePeriodDBFormat.GetFrequencyValueFromTime(TimeVal));
                        }
                        else if (Colums[col] != null && Colums[col].ConceptObjectCode == FlyConfiguration.Time_Format_Id && isFakeTimeFormat)
                        {
                            Vals[col] = (TimePeriodDBFormat.GetTimeFormatValueFromTime(TimeVal));
                        }
                        else if (Colums[col] != null && Colums[col].ConceptType == ConceptTypeEnum.Dimension && ((IDimensionConcept)Colums[col]).DimensionType == DimensionTypeEnum.Time)
                        {
                            Vals[col] = (TimePeriodDBFormat.ParseTimeVal(DBDataReader[col]));
                        }
                        else
                        {
                            Vals[col] = (DBDataReader[col]);
                        }
                    }

                    List <DataMessageObject> dmo = new List <DataMessageObject>();
                    Colums.Keys.ToList().ForEach(col => dmo.Add(new DataMessageObject()
                    {
                        ColId   = col,
                        ColImpl = Colums[col],
                        Val     = Vals[col]
                    }));

                    RowsCounter++;
                    return(dmo);
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.DBErrorResponse, ex);
            }
        }
        public string GetDdl(DbViewModel dbVm)
        {
            var colums = Colums.Select(x =>
            {
                var sql = $"{x.ColumName} {x.ColumType}";
                if (!x.NullFlag)
                {
                    sql += " not null";
                }
                return(sql.ToUpper());
            });

            var index = Indexs
                        .Select(x =>
            {
                var sql = x.IndexName.StartsWith("rdb", System.StringComparison.OrdinalIgnoreCase) ? "" : $"CONSTRAINT {x.IndexName} ";
                switch (x.Kind)
                {
                case ConstraintsKind.Primary:
                    sql += $"PRIMARY KEY ({string.Join(", ", x.FieldNames.ToArray())})";
                    break;

                case ConstraintsKind.Foreign:
                    var idx = dbVm.Indexes.Where(dbIdx => dbIdx.IndexName == x.IndexName).First();
                    sql    += $"FOREIGN KEY({string.Join(", ", x.FieldNames.ToArray())}) REFERENCES {idx.TableName} ({string.Join(", ", idx.FieldNames.ToArray())})";
                    break;

                case ConstraintsKind.Unique:
                    sql += $"UNIQUE ({string.Join(", ", x.FieldNames.ToArray())})";
                    break;

                default:
                    return("");
                }
                return(sql);
            });

            var domain = Colums.Where(x => x.IsDomainType)
                         .Select(x => new { x.ColumType, x.ColumDataType })
                         .Distinct()
                         .Select(x => $"CREATE DOMAIN {x.ColumType} AS {x.ColumDataType};\r\n");
            var domainStr = string.Join("", domain.ToArray());

            return(domainStr + $"CREATE TABLE {TableName} ({Environment.NewLine}  { string.Join($",{Environment.NewLine}  ", colums.Union(index).ToArray()) + Environment.NewLine})");
        }
 public string GetDdl(DbViewModel dbVm)
 {
     return($"CREATE VIEW {TableName} ({string.Join(", ", Colums.Select(x => x.ColumName).ToArray())}) AS" + Environment.NewLine
            + Source);
 }