Ejemplo n.º 1
0
        // --- create ------------------------------------------------------

        // from existing columns, with normalisation by default
        public static DataHeading Create(IEnumerable <DataColumn> columns, bool istuple = true)
        {
            Logger.Assert(columns != null && columns.All(c => c.DataType.IsVariable), "bad columns");
            var dh = new DataHeading()
            {
                _columns = columns.ToArray(),
                IsTuple  = istuple,
            };

            dh._coldict = Enumerable.Range(0, dh._columns.Length)
                          .ToDictionary(x => dh._columns[x].Name, x => x);
            return((istuple) ? DataTypeTuple.Get(dh).Heading : dh);
        }
Ejemplo n.º 2
0
 // construct a type from a base name, optional heading and optional user type name
 public static DataType Derive(DataType basetype, DataHeading heading, string username)
 {
     if (basetype == DataTypes.Table)
     {
         return(DataTypeRelation.Get(heading));
     }
     if (basetype == DataTypes.Row)
     {
         return(DataTypeTuple.Get(heading));
     }
     if (basetype == DataTypes.User)
     {
         return(DataTypeUser.Get(username, heading.Columns));
     }
     return(basetype);
 }
Ejemplo n.º 3
0
        // Get type from dictionary, or create and add
        // Every relation needs a row type, so make sure they use the same heading
        public static DataTypeRelation Get(DataHeading heading)
        {
            if (_headings.ContainsKey(heading))
            {
                return(_headings[heading]);
            }
            var tupletype = DataTypeTuple.Get(heading);
            var dt        = DataTypeRelation.Create("relation", tupletype.Heading, TypeFlags.Variable | TypeFlags.Generated | TypeFlags.HasHeading);

            dt.Ordinal         = _headings.Count + 1;
            dt.ChildTupleType  = tupletype;
            dt.NativeType      = TypeMaker.CreateType(dt);
            _headings[heading] = dt;
            var x = Activator.CreateInstance(dt.NativeType);

            return(dt);
        }
Ejemplo n.º 4
0
        // Create a row that belongs to a table.
        // Can be called with a tuple or non-tuple heading. If the latter, reorder values to match tuple heading.
        public static DataRow Create(DataHeading heading, TypedValue[] values)
        {
            if (values.Length != heading.Degree)
            {
                throw new ArgumentOutOfRangeException("values", "wrong degree");
            }
            Logger.Assert(values.All(v => v != null), "null value");
            var newheading = (heading.IsTuple) ? heading : DataTypeTuple.Get(heading).Heading;
            var dr         = new DataRow()
            {
                DataType = DataTypeTuple.Get(heading),
                Heading  = newheading,
                _values  = (heading.IsTuple) ? values : newheading.Columns.Select(c => values[heading.FindIndex(c)]).ToArray(),
            };

            dr._hashcode = dr.CalcHashCode();
            dr.Heading.CheckValues(dr.Values);
            return(dr);
        }