Ejemplo n.º 1
0
        /// <summary>
        /// Checks a record for nullness, type affinity, size overflow, and field count
        /// </summary>
        /// <param name="R">A record to check</param>
        /// <param name="FixAffinity">If true, the method will cast an invalid affinity cell</param>
        /// <returns>A boolean describing whether or not the check fails</returns>
        public bool Check(Record R, bool FixAffinity)
        {
            // Check length //
            if (R.Count != this.Count)
            {
                throw new Exception(String.Format("Record size {0} does not match schema size {1}", R.Count, this.Count));
            }

            // Check nullness and affinity //
            for (int i = 0; i < R.Count; i++)
            {
                // Check affinity //
                if (R[i].Affinity != this.ColumnAffinity(i) && this.ColumnAffinity(i) != CellAffinity.VARIANT && !FixAffinity)
                {
                    throw new Exception(String.Format("Column Affinities do not match {0} : {1} != {2}", i, R[i].Affinity, this.ColumnAffinity(i)));
                }
                else if (R[i].Affinity != this.ColumnAffinity(i) && this.ColumnAffinity(i) != CellAffinity.VARIANT)
                {
                    R[i] = CellConverter.Cast(R[i], this.ColumnAffinity(i));
                }

                // Check nullness //
                if (!this.ColumnNull(i) && R[i].IsNull)
                {
                    throw new Exception(String.Format("Column {0} is null", i));
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell         c = this._Children[0].Evaluate(Memory);
                Cell         d = this._Children[1].Evaluate(Memory);
                CellAffinity a = (CellAffinity)d.BYTE;

                return(CellConverter.Cast(c, a));
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Fixing any affinity issues by auto casting the cell type to the correct type based on the column
        /// </summary>
        /// <param name="R">A record to check</param>
        /// <returns>A record</returns>
        public Record Fix(Record R)
        {
            // Check nullness and affinity //
            for (int i = 0; i < R.Count; i++)
            {
                // Cast to a new affinity if need by //
                if (R[i].Affinity != this.ColumnAffinity(i) && this.ColumnAffinity(i) != CellAffinity.VARIANT)
                {
                    R[i] = CellConverter.Cast(R[i], this.ColumnAffinity(i));
                }
            }

            return(R);
        }