Click here to Skip to main content
12,449,762 members (75,892 online)
Click here to Skip to main content

Stats

184.9K views
7.9K downloads
338 bookmarked
Posted

Building an embedded database engine in C#

, 10 Jun 2009 CPOL
DbfDotNet is a very fast and compact fully managed standalone database/entity framework, for the .Net Framework.
using System;
using System.Collections.Generic;
using System.Text;

namespace DbfDotNet
{
 
    public class DbfTable<TRecord> : IEnumerable<TRecord>
        where TRecord : DbfRecord, new()
    {
        internal Core.DbfFile<TRecord> mDbfFile;

        public DbfTable(string filePath, System.Text.Encoding encoding, DbfVersion version)
        {
            mDbfFile = Core.DbfFile<TRecord>.Get(filePath, encoding, version);
        }

        public TRecord NewRecord()
        {
            return mDbfFile.NewRecord();
        }

        #region IEnumerable<TRecord> Members

        public IEnumerator<TRecord> GetEnumerator()
        {
            return mDbfFile.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        //public NdxFile<TRecord>[] OpenIndexes
        //{
        //    get {
        //        return this.mDbfFile.mIndexes.ToArray();
        //    }
        //}


        public int RecordCount
        {
            get { return (int)mDbfFile.RecordCount; }
        }

        public List<Core.ColumnDefinition> Columns
        {
            get { return mDbfFile.Columns; }
        }
        
        public TRecord GetRecord(UInt32 p)
        {
            return (TRecord)mDbfFile.InternalGetRecord((uint)p, false);
        }

        public void Close()
        {
            mDbfFile.StopReading();
            mDbfFile = null;
        }

        public void EmptyTable()
        {
            mDbfFile.EmptyTable();
        }

        public DbfIndex<TRecord> GetIndex(string filepath, SortOrder<TRecord> sortOrder)
        {
            var indexTable = DbfDotNet.Core.NdxFile<TRecord>.Get(filepath, this.mDbfFile, sortOrder);
            if (indexTable.mDbfIndex==null)
            {
                indexTable.mDbfIndex = new DbfIndex<TRecord>();
                indexTable.mDbfFile = mDbfFile;
                indexTable.mDbfIndex.mIndexTable = indexTable;
            }
            return (DbfIndex<TRecord>)indexTable.mDbfIndex;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pascal Ganaye
Software Developer (Senior)
France France
I am a French programmer.
These days I spend most of my time with the .NET framework, JavaScript and html.

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 10 Jun 2009
Article Copyright 2009 by Pascal Ganaye
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid