/// <summary>
        /// Parses and adds data column to the collection.
        /// </summary>
        /// <param name="columnData"></param>
        internal void Parse(byte[] columnData)
        {
            LDB_DataColumn column = new LDB_DataColumn();

            column.Parse(columnData);

            m_pColumns.Add(column);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts internal data to .NET data type.
        /// </summary>
        /// <param name="coulmn">Column what data it is.</param>
        /// <param name="val">Internal data value.</param>
        /// <returns></returns>
        internal static object ConvertFromInternalData(LDB_DataColumn coulmn, byte[] val)
        {
            if (coulmn.DataType == LDB_DataType.Bool)
            {
                return(Convert.ToBoolean(val[0]));
            }
            else if (coulmn.DataType == LDB_DataType.DateTime)
            {
                /* Data structure
                 *                      1 byte day
                 *                      1 byte month
                 *                      4 byte year (int)
                 *                      1 byte hour
                 *                      1 byte minute
                 *                      1 byte second
                 */

                byte[] dateBytes = new byte[13];
                // day
                int day = val[0];
                // month
                int month = val[1];
                // year
                int year = ldb_Utils.ByteToInt(val, 2);
                // hour
                int hour = val[6];
                // minute
                int minute = val[7];
                // second
                int second = val[8];

                return(new DateTime(year, month, day, hour, minute, second));
            }
            else if (coulmn.DataType == LDB_DataType.Long)
            {
                return(ldb_Utils.ByteToLong(val, 0));
            }
            else if (coulmn.DataType == LDB_DataType.Int)
            {
                return(ldb_Utils.ByteToInt(val, 0));
            }
            else if (coulmn.DataType == LDB_DataType.String)
            {
                return(Encoding.UTF8.GetString(val));
            }
            else
            {
                throw new Exception("Invalid column data type, never must reach here !");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds column to db file.
        /// </summary>
        /// <param name="column"></param>
        internal void AddColumn(LDB_DataColumn column)
        {
            if (column.ColumnSize < 1)
            {
                throw new Exception("Invalid column size '" + column.ColumnSize + "' for column '" +
                                    column.ColumnName + "' !");
            }

            // Find free column data area

            long currentColumnOffset = m_ColumnsStartOffset;
            long freeColumnPosition  = -1;

            // Loop all columns data areas, see it there any free left
            for (int i = 0; i < 100; i++)
            {
                byte[] columnInfo = new byte[102];
                if (ReadFromFile(currentColumnOffset, columnInfo, 0, columnInfo.Length) != columnInfo.Length)
                {
                    throw new Exception("Invalid columns data area length !");
                }

                // We found unused column data area
                if (columnInfo[0] == '\0')
                {
                    freeColumnPosition = currentColumnOffset - 102;
                    break;
                }

                currentColumnOffset += 102;
            }

            if (freeColumnPosition != -1)
            {
                // TODO: If there is data ???

                // Store column
                byte[] columnData = column.ToColumnInfo();
                WriteToFile(currentColumnOffset, columnData, 0, columnData.Length);
            }
            else
            {
                throw new Exception("Couldn't find free column space ! ");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds column to db file.
        /// </summary>
        /// <param name="column"></param>
        internal void AddColumn(LDB_DataColumn column)
        {
            // Find free column data area

            // Set position over version, free data pages count and data page data area size
            m_pDbFile.Position = 68;

            long             freeColumnPosition = -1;
            StreamLineReader r = new StreamLineReader(m_pDbFile);

            // Loop all columns data areas, see it there any free left
            for (int i = 0; i < 100; i++)
            {
                byte[] columnInfo = r.ReadLine();
                if (columnInfo == null)
                {
                    throw new Exception("Invalid columns data area length !");
                }

                // We found unused column data area
                if (columnInfo[0] == '\0')
                {
                    freeColumnPosition = m_pDbFile.Position;
                    break;
                }
            }
            m_FilePosition = m_pDbFile.Position;

            if (freeColumnPosition != -1)
            {
                // TODO: If there is data ???

                // Move to row start
                SetFilePosition(GetFilePosition() - 102);

                // Store column
                byte[] columnData = column.ToColumnInfo();
                WriteToFile(columnData, 0, columnData.Length);
            }
            else
            {
                throw new Exception("Couldn't find free column space ! ");
            }
        }
        /// <summary>
        /// Ads specified data column to collection.
        /// </summary>
        /// <param name="column"></param>
        public void Add(LDB_DataColumn column)
        {
            if (Contains(column.ColumnName))
            {
                throw new Exception("Data column with specified name '" + column.ColumnName +
                                    "' already exists !");
            }

            if (m_pOwner.GetType() == typeof(DbFile))
            {
                ((DbFile)m_pOwner).AddColumn(column);
            }
            else if (m_pOwner.GetType() == typeof(lsDB_FixedLengthTable))
            {
                ((lsDB_FixedLengthTable)m_pOwner).AddColumn(column);
            }

            m_pColumns.Add(column);
        }
        /// <summary>
        /// Ads specified data column to collection.
        /// </summary>
        /// <param name="column"></param>
        public void Add(LDB_DataColumn column)
        {
            if (Contains(column.ColumnName))
            {
                throw new Exception("Data column with specified name '" + column.ColumnName +
                                    "' already exists !");
            }

            if (m_pOwner.GetType() == typeof (DbFile))
            {
                ((DbFile) m_pOwner).AddColumn(column);
            }
            else if (m_pOwner.GetType() == typeof (lsDB_FixedLengthTable))
            {
                ((lsDB_FixedLengthTable) m_pOwner).AddColumn(column);
            }

            m_pColumns.Add(column);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets or sets specified data column value.
        /// </summary>
        public object this[LDB_DataColumn column]
        {
            get
            {
                int index = m_pOwnerDb.Columns.IndexOf(column);
                if (index == -1)
                {
                    throw new Exception("Table doesn't contain column '" + column.ColumnName + "' !");
                }

                return(this[index]);
            }

            set
            {
                int index = m_pOwnerDb.Columns.IndexOf(column);
                if (index == -1)
                {
                    throw new Exception("Table doesn't contain column '" + column.ColumnName + "' !");
                }

                this[index] = value;
            }
        }
 /// <summary>
 /// Gets if data column collection contains specified column.
 /// </summary>
 /// <param name="column">Data column.</param>
 /// <returns></returns>
 public bool Contains(LDB_DataColumn column)
 {
     return m_pColumns.Contains(column);
 }
        /// <summary>
        /// Parses and adds data column to the collection.
        /// </summary>
        /// <param name="columnData"></param>
        internal void Parse(byte[] columnData)
        {
            LDB_DataColumn column = new LDB_DataColumn();
            column.Parse(columnData);

            m_pColumns.Add(column);
        }
 /// <summary>
 /// Removes specified data column from collection.
 /// </summary>
 /// <param name="column">Data column which to remove.</param>
 public void Remove(LDB_DataColumn column)
 {
     m_pColumns.Remove(column);
 }
 /// <summary>
 /// Gets specified data column index in collection. Returns -1 if no such column.
 /// </summary>
 /// <param name="column">Data column.</param>
 /// <returns></returns>
 public int IndexOf(LDB_DataColumn column)
 {
     return m_pColumns.IndexOf(column);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Converts data to specied column internal store data.
        /// </summary>
        /// <param name="coulmn">Column where to store data.</param>
        /// <param name="val">Data to convert.</param>
        /// <returns></returns>
        internal static byte[] ConvertToInternalData(LDB_DataColumn coulmn, object val)
        {
            if (val == null)
            {
                throw new Exception("Null values aren't supported !");
            }

            if (coulmn.DataType == LDB_DataType.Bool)
            {
                if (val.GetType() != typeof(bool))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of bool, but value contains '" + val.GetType() +
                                        "' !");
                }

                return(new[] { Convert.ToByte((bool)val) });
            }
            else if (coulmn.DataType == LDB_DataType.DateTime)
            {
                if (val.GetType() != typeof(DateTime))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of DateTime, but value contains '" +
                                        val.GetType() + "' !");
                }

                /* Data structure
                 *                      1 byte day
                 *                      1 byte month
                 *                      4 byte year (int)
                 *                      1 byte hour
                 *                      1 byte minute
                 *                      1 byte second
                 */

                DateTime d         = (DateTime)val;
                byte[]   dateBytes = new byte[13];
                // day
                dateBytes[0] = (byte)d.Day;
                // month
                dateBytes[1] = (byte)d.Month;
                // year
                Array.Copy(ldb_Utils.IntToByte(d.Year), 0, dateBytes, 2, 4);
                // hour
                dateBytes[6] = (byte)d.Hour;
                // minute
                dateBytes[7] = (byte)d.Minute;
                // second
                dateBytes[8] = (byte)d.Second;

                return(dateBytes);
            }
            else if (coulmn.DataType == LDB_DataType.Long)
            {
                if (val.GetType() != typeof(long))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of Long, but value contains '" + val.GetType() +
                                        "' !");
                }

                return(ldb_Utils.LongToByte((long)val));
            }
            else if (coulmn.DataType == LDB_DataType.Int)
            {
                if (val.GetType() != typeof(int))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of Int, but value contains '" + val.GetType() +
                                        "' !");
                }

                return(ldb_Utils.IntToByte((int)val));
            }
            else if (coulmn.DataType == LDB_DataType.String)
            {
                if (val.GetType() != typeof(string))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of String, but value contains '" + val.GetType() +
                                        "' !");
                }

                return(Encoding.UTF8.GetBytes(val.ToString()));
            }
            else
            {
                throw new Exception("Invalid column data type, never must reach here !");
            }
        }
 /// <summary>
 /// Removes specified column from database file.
 /// </summary>
 /// <param name="column"></param>
 internal void RemoveColumn(LDB_DataColumn column)
 {
     throw new Exception("TODO:");
 }
Exemplo n.º 14
0
        /// <summary>
        /// Gets or sets specified data column value.
        /// </summary>
        public object this[LDB_DataColumn column]
        {
            get
            {
                int index = m_pOwnerDb.Columns.IndexOf(column);
                if (index == -1)
                {
                    throw new Exception("Table doesn't contain column '" + column.ColumnName + "' !");
                }

                return this[index];
            }

            set
            {
                int index = m_pOwnerDb.Columns.IndexOf(column);
                if (index == -1)
                {
                    throw new Exception("Table doesn't contain column '" + column.ColumnName + "' !");
                }

                this[index] = value;
            }
        }
        /// <summary>
        /// Adds column to db file.
        /// </summary>
        /// <param name="column"></param>
        internal void AddColumn(LDB_DataColumn column)
        {
            if (column.ColumnSize < 1)
            {
                throw new Exception("Invalid column size '" + column.ColumnSize + "' for column '" +
                                    column.ColumnName + "' !");
            }

            // Find free column data area

            long currentColumnOffset = m_ColumnsStartOffset;
            long freeColumnPosition = -1;
            // Loop all columns data areas, see it there any free left
            for (int i = 0; i < 100; i++)
            {
                byte[] columnInfo = new byte[102];
                if (ReadFromFile(currentColumnOffset, columnInfo, 0, columnInfo.Length) != columnInfo.Length)
                {
                    throw new Exception("Invalid columns data area length !");
                }

                // We found unused column data area
                if (columnInfo[0] == '\0')
                {
                    freeColumnPosition = currentColumnOffset - 102;
                    break;
                }

                currentColumnOffset += 102;
            }

            if (freeColumnPosition != -1)
            {
                // TODO: If there is data ???

                // Store column
                byte[] columnData = column.ToColumnInfo();
                WriteToFile(currentColumnOffset, columnData, 0, columnData.Length);
            }
            else
            {
                throw new Exception("Couldn't find free column space ! ");
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Converts data to specied column internal store data.
        /// </summary>
        /// <param name="coulmn">Column where to store data.</param>
        /// <param name="val">Data to convert.</param>
        /// <returns></returns>
        internal static byte[] ConvertToInternalData(LDB_DataColumn coulmn, object val)
        {
            if (val == null)
            {
                throw new Exception("Null values aren't supported !");
            }

            if (coulmn.DataType == LDB_DataType.Bool)
            {
                if (val.GetType() != typeof (bool))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of bool, but value contains '" + val.GetType() +
                                        "' !");
                }

                return new[] {Convert.ToByte((bool) val)};
            }
            else if (coulmn.DataType == LDB_DataType.DateTime)
            {
                if (val.GetType() != typeof (DateTime))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of DateTime, but value contains '" +
                                        val.GetType() + "' !");
                }

                /* Data structure
					1 byte day
					1 byte month
					4 byte year (int)
					1 byte hour
					1 byte minute
					1 byte second
				*/

                DateTime d = (DateTime) val;
                byte[] dateBytes = new byte[13];
                // day
                dateBytes[0] = (byte) d.Day;
                // month
                dateBytes[1] = (byte) d.Month;
                // year
                Array.Copy(ldb_Utils.IntToByte(d.Year), 0, dateBytes, 2, 4);
                // hour
                dateBytes[6] = (byte) d.Hour;
                // minute
                dateBytes[7] = (byte) d.Minute;
                // second
                dateBytes[8] = (byte) d.Second;

                return dateBytes;
            }
            else if (coulmn.DataType == LDB_DataType.Long)
            {
                if (val.GetType() != typeof (long))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of Long, but value contains '" + val.GetType() +
                                        "' !");
                }

                return ldb_Utils.LongToByte((long) val);
            }
            else if (coulmn.DataType == LDB_DataType.Int)
            {
                if (val.GetType() != typeof (int))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of Int, but value contains '" + val.GetType() +
                                        "' !");
                }

                return ldb_Utils.IntToByte((int) val);
            }
            else if (coulmn.DataType == LDB_DataType.String)
            {
                if (val.GetType() != typeof (string))
                {
                    throw new Exception("Column '" + coulmn.ColumnName +
                                        "' requires datatype of String, but value contains '" + val.GetType() +
                                        "' !");
                }

                return Encoding.UTF8.GetBytes(val.ToString());
            }
            else
            {
                throw new Exception("Invalid column data type, never must reach here !");
            }
        }
 /// <summary>
 /// Gets if data column collection contains specified column.
 /// </summary>
 /// <param name="column">Data column.</param>
 /// <returns></returns>
 public bool Contains(LDB_DataColumn column)
 {
     return(m_pColumns.Contains(column));
 }
 /// <summary>
 /// Gets specified data column index in collection. Returns -1 if no such column.
 /// </summary>
 /// <param name="column">Data column.</param>
 /// <returns></returns>
 public int IndexOf(LDB_DataColumn column)
 {
     return(m_pColumns.IndexOf(column));
 }
 /// <summary>
 /// Removes specified data column from collection.
 /// </summary>
 /// <param name="column">Data column which to remove.</param>
 public void Remove(LDB_DataColumn column)
 {
     m_pColumns.Remove(column);
 }
Exemplo n.º 20
0
        /// <summary>
        /// Converts internal data to .NET data type.
        /// </summary>
        /// <param name="coulmn">Column what data it is.</param>
        /// <param name="val">Internal data value.</param>
        /// <returns></returns>
        internal static object ConvertFromInternalData(LDB_DataColumn coulmn, byte[] val)
        {
            if (coulmn.DataType == LDB_DataType.Bool)
            {
                return Convert.ToBoolean(val[0]);
            }
            else if (coulmn.DataType == LDB_DataType.DateTime)
            {
                /* Data structure
					1 byte day
					1 byte month
					4 byte year (int)
					1 byte hour
					1 byte minute
					1 byte second
				*/

                byte[] dateBytes = new byte[13];
                // day
                int day = val[0];
                // month
                int month = val[1];
                // year
                int year = ldb_Utils.ByteToInt(val, 2);
                // hour
                int hour = val[6];
                // minute
                int minute = val[7];
                // second
                int second = val[8];

                return new DateTime(year, month, day, hour, minute, second);
            }
            else if (coulmn.DataType == LDB_DataType.Long)
            {
                return ldb_Utils.ByteToLong(val, 0);
            }
            else if (coulmn.DataType == LDB_DataType.Int)
            {
                return ldb_Utils.ByteToInt(val, 0);
            }
            else if (coulmn.DataType == LDB_DataType.String)
            {
                return Encoding.UTF8.GetString(val);
            }
            else
            {
                throw new Exception("Invalid column data type, never must reach here !");
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Removes specified column from database file.
 /// </summary>
 /// <param name="column"></param>
 internal void RemoveColumn(LDB_DataColumn column)
 {
     throw new Exception("TODO:");
 }
Exemplo n.º 22
0
        /// <summary>
        /// Adds column to db file.
        /// </summary>
        /// <param name="column"></param>
        internal void AddColumn(LDB_DataColumn column)
        {
            // Find free column data area

            // Set position over version, free data pages count and data page data area size
            m_pDbFile.Position = 68;

            long freeColumnPosition = -1;
            StreamLineReader r = new StreamLineReader(m_pDbFile);
            // Loop all columns data areas, see it there any free left
            for (int i = 0; i < 100; i++)
            {
                byte[] columnInfo = r.ReadLine();
                if (columnInfo == null)
                {
                    throw new Exception("Invalid columns data area length !");
                }

                // We found unused column data area
                if (columnInfo[0] == '\0')
                {
                    freeColumnPosition = m_pDbFile.Position;
                    break;
                }
            }
            m_FilePosition = m_pDbFile.Position;

            if (freeColumnPosition != -1)
            {
                // TODO: If there is data ???

                // Move to row start
                SetFilePosition(GetFilePosition() - 102);

                // Store column
                byte[] columnData = column.ToColumnInfo();
                WriteToFile(columnData, 0, columnData.Length);
            }
            else
            {
                throw new Exception("Couldn't find free column space ! ");
            }
        }