Exemplo n.º 1
0
        /// <summary>
        /// Parses a key from a string
        /// </summary>
        /// <param name="BString">BString to parse</param>
        /// <returns>Key parsed from the string</returns>
        public static Key Parse(string Text)
        {
            string[]    s  = Text.Split(',');
            int         i  = 0;
            KeyAffinity ka = KeyAffinity.Ascending;
            Key         k  = new Key();

            foreach (string r in s)
            {
                string[] t = r.Trim().Split(' ');

                if (s.Length == 2)
                {
                    ka = ParseAffinity(s[1]);
                }
                else
                {
                    ka = KeyAffinity.Ascending;
                }

                i = int.Parse(t[0]);

                k.Add(i, ka);
            }

            return(k);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns the index of field index passed
 /// </summary>
 /// <param name="Index">The field index</param>
 /// <param name="Affinity">The sort type</param>
 /// <returns>The key index or -1 if the index is not present</returns>
 public int IndexOf(int Index, KeyAffinity Affinity)
 {
     for (int i = 0; i < this.Count; i++)
     {
         if (this[i] == Index && this.Affinity(i) == Affinity)
         {
             return(i);
         }
     }
     return(-1);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Parses a string into a key
        /// </summary>
        /// <param name="BString">The text list of columns</param>
        /// <returns>A key</returns>
        public Key KeyParse(string Text)
        {
            Key k = new Key();

            if (Text == "*")
            {
                return(Key.Build(this.Count));
            }

            string[] t = Text.Split(',');

            foreach (string s in t)
            {
                // Parse out the 'NAME KEY_AFFINITY' logic //
                string[] u = s.Trim().Split(' ');
                string   v = u[0]; // column name
                string   w = "A";  // affinity (Optional)
                if (u.Length > 1)
                {
                    w = u[1];
                }

                // get index and affinity
                int         j = this.ColumnIndex(v);
                KeyAffinity a = Key.ParseAffinity(w);

                // Accumulate values //
                if (j != -1)
                {
                    k.Add(j, a);
                }
                else if (v.ToList().TrueForAll((c) => { return("1234567890".Contains(c)); }))
                {
                    k.Add(int.Parse(v), a);
                }
            }
            return(k);
        }
Exemplo n.º 4
0
        // Static Methods //
        /// <summary>
        /// Converts a byte array to a TableHeader
        /// </summary>
        /// <param name="Buffer"></param>
        /// <param name="Location"></param>
        /// <returns></returns>
        public static TableHeader FromHash(byte[] Buffer, int Location)
        {
            // Check the size //
            if (Buffer.Length - Location < TableHeader.SIZE)
            {
                throw new Exception("Buffer is incorrect size");
            }

            // Check the hash key //
            if (BitConverter.ToInt32(Buffer, Location + OFFSET_HASH_KEY) != HASH_KEY)
            {
                throw new Exception("Invalid hash key");
            }

            // Create //
            TableHeader h   = new TableHeader();
            int         Len = 0;

            // Alias //
            Len    = BitConverter.ToInt32(Buffer, Location + OFFSET_NAME_LEN);
            h.Name = ASCIIEncoding.ASCII.GetString(Buffer, Location + OFFSET_NAME, Len);

            // Directory //
            Len         = BitConverter.ToInt32(Buffer, Location + OFFSET_DIR_LEN);
            h.Directory = ASCIIEncoding.ASCII.GetString(Buffer, Location + OFFSET_DIR, Len);

            // Extension //
            Len         = BitConverter.ToInt32(Buffer, Location + OFFSET_EXT_LEN);
            h.Extension = ASCIIEncoding.ASCII.GetString(Buffer, Location + OFFSET_EXT, Len);

            // Page count //
            h.PageCount = BitConverter.ToInt32(Buffer, Location + OFFSET_PAGE_COUNT);

            // Row count //
            h.RecordCount = BitConverter.ToInt64(Buffer, Location + OFFSET_RECORD_COUNT);

            // Column Count //
            int ColCount = BitConverter.ToInt32(Buffer, Location + OFFSET_COLUMN_COUNT);

            // First Page //
            h.OriginPageID = BitConverter.ToInt32(Buffer, Location + OFFSET_FIRST_PAGE_ID);

            // Last Page //
            h.TerminalPageID = BitConverter.ToInt32(Buffer, Location + OFFSET_LAST_PAGE_ID);

            // Page PageSize //
            h.PageSize = BitConverter.ToInt32(Buffer, Location + OFFSET_PAGE_SIZE);

            // Radix Page //
            h.RootPageID = BitConverter.ToInt32(Buffer, Location + OFFSET_ROOT_PAGE_ID);

            // Key //
            h.ClusterKey      = new Key();
            h.ClusterKeyState = (BinaryRecordTree.TreeAffinity)Buffer[Location + OFFSET_SORT_KEY]; // gets the unique
            int KeyCount = BitConverter.ToInt32(Buffer, Location + OFFSET_SORT_KEY + 4);           // gets the key size

            for (int i = 0; i < KeyCount; i++)
            {
                int         loc      = Location + OFFSET_SORT_KEY + 8 + 8 * i;
                int         idx      = BitConverter.ToInt32(Buffer, loc);
                KeyAffinity affinity = (KeyAffinity)BitConverter.ToInt32(Buffer, loc + 4);
                h.ClusterKey.Add(idx, affinity);
            }

            // Read the index table //
            int idx_cnt = BitConverter.ToInt32(Buffer, Location + OFFSET_INDEX_COUNT);

            for (int i = 0; i < idx_cnt; i++)
            {
                int         pos   = Location + OFFSET_INDEX_TABLE + i * IndexHeader.SIZE_HASH;
                IndexHeader idx_h = IndexHeader.Read(Buffer, pos);
                h.IndexHeaders.Add(idx_h);
            }

            // Load the columns //
            h.Columns = new Schema();
            for (int i = 0; i < ColCount; i++)
            {
                int          RecordOffset = Location + OFFSET_COLUMNS + i * COL_REC_LEN;
                int          NameLen      = (int)Buffer[RecordOffset];
                string       ColName      = ASCIIEncoding.ASCII.GetString(Buffer, RecordOffset + COL_NAME_PTR, NameLen);
                CellAffinity ColType      = (CellAffinity)Buffer[RecordOffset + COL_AFFINITY];

                int  ColSize = (int)(BitConverter.ToInt16(Buffer, RecordOffset + COL_SIZE));
                bool ColNull = true;
                if (ColSize < 0)
                {
                    ColSize = -ColSize;
                    ColNull = false;
                }

                h.Columns.Add(ColName, ColType, ColSize, ColNull);
            }

            return(h);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Appends the key
 /// </summary>
 /// <param name="Index">Field offset</param>
 /// <param name="Affinity">Desired key affinity</param>
 public void Add(int Index, KeyAffinity Affinity)
 {
     this._data.Add(new Cell(Index, (int)Affinity));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Appends the key
 /// </summary>
 /// <param name="Index">Field offset</param>
 /// <param name="Affinity">Desired key affinity</param>
 public void Add(int Index, KeyAffinity Affinity)
 {
     this._data.Add(new Cell(Index, (int)Affinity));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Sets the sort by affinity
 /// </summary>
 /// <param name="Index"></param>
 /// <param name="Affinity"></param>
 public void SetAffinity(int Index, KeyAffinity Affinity)
 {
     this._data[Index] = new Cell(this._data[Index].INT_A, (int)Affinity);
 }