// Protected // protected Tuple <CellAffinity, int> SizeTypeOf(List <Expression> Xs) { int MaxSize = -1; CellAffinity MaxAffinity = CellAffinity.BOOL; foreach (Expression x in Xs) { CellAffinity ca = x.TypeOf(); MaxAffinity = CellAffinityHelper.Highest(MaxAffinity, ca); if (MaxAffinity == ca) { MaxSize = Math.Max(MaxSize, x.SizeOf()); } } return(new Tuple <CellAffinity, int>(MaxAffinity, MaxSize)); }
/// <summary> /// /// </summary> /// <param name="Names"></param> /// <param name="Types"></param> /// <returns></returns> public static Schema FromString(string Names, string Types) { string[] NameArray = Names.Split(','); string[] TypeArray = Types.Split(','); if (NameArray.Length != TypeArray.Length) { throw new ArgumentException("The name and type tags have different counts"); } Schema columns = new Schema(); for (int i = 0; i < NameArray.Length; i++) { string[] x = TypeArray[i].Split('.'); CellAffinity t = CellAffinityHelper.Parse(x[0]); int size = 8; if (t == CellAffinity.CSTRING && x.Length == 2) { size = int.Parse(x[1]); } else if (t == CellAffinity.CSTRING) { size = Schema.DEFAULT_STRING_SIZE; } else if (t == CellAffinity.BINARY && x.Length == 2) { size = int.Parse(x[1]); } else if (t == CellAffinity.BINARY) { size = Schema.DEFAULT_BLOB_SIZE; } columns.Add(NameArray[i], t, size); } return(columns); }
// Adds // /// <summary> /// Adds a column to the schema; will throw an exception if a column name passed already exists in the schema /// </summary> /// <param name="Alias">The column name</param> /// <param name="Affinity">The column affinity</param> /// <param name="Nullable">A boolean, true means the column can be nulls, false means the column cannot be null</param> /// <param name="PageSize">The size in bytes; this will be ignored if the affinity is not variable (not string or blob)</param> public void Add(string Name, CellAffinity Affinity, int Size, bool Nullable) { // Check the name size // if (Name.Length > MAX_COLUMN_NAME_LEN) { Name = Name.Substring(0, MAX_COLUMN_NAME_LEN); } // Check the size // if (CellAffinityHelper.IsVariableLength(Affinity) && Size == 0) { throw new Exception("Variable length types must have a size greater than zero"); } // Check if exists // if (this.Contains(Name)) { throw new Exception("Column already exists: " + Name); } // Check for capacity // if (this.Count >= MAX_COLUMNS) { throw new Exception("Schema cannot accept any more columns"); } // Get the size // int v = CellSerializer.FixLength(Affinity, Size); // Build record // Record r = Record.Stitch(new Cell(Name), new Cell((byte)Affinity), new Cell(Nullable), new Cell(v)); // Accumulate record // this._Cache.Allocate(Name, r); // Hash code // this._HashCode += r.GetHashCode(new Key(1, 2)) * this.Count; }