Skip to content

Pure C#.Net SQLite database could run on windows/linux/macos and supports REAL memory database.

License

Notifications You must be signed in to change notification settings

GuoHuiChen/NSQLite

 
 

Repository files navigation

NSQLite Build Status Bitdeli Badge

This is a pure C# SQLite implement. I forked it from CsharpSQLite. And its origin source is on Google Code. More infomation could find at InfoQ.

I added a new feature of support REAL memory database. For the word REAL I mean it behaves just like file based SQLite.

SQLite supports memory database as well. But it only created by new connection created and will dispose while the connection closed. And all your operation should use this connection. And if other thread want to use this connection will cause an error.

The new feature I added is to handles file access functions and port them to memory acess functions. The result will store in a Dictionary<string, byte[]>, it use the file name as key and file content as value. So we can visit the memory file multi times. And we can initialize it with a real file content instead of run initialize SQL statements. It just like a file but the speed will be a lot of fast than a file.

I tested it in my project DbEntry.Net for unit test. The file based SQLite costs about 50s and the memory version only costs about 10s. It also a little faster than file based SQLite on RamDisk.

The following code is the base class of my unit tests. The commented code is use file based SQLite.

public class DataTestBase : SqlTestBase
{
    private const string FileName = "UnitTest.db";
	private static readonly string TestFilePath = "/Volumes/RamDisk/" + FileName;
    private static readonly byte[] TestFileBuffer = ResourceHelper.ReadAll(typeof(DataTestBase), FileName);

    protected override void OnSetUp()
    {
		/*
        File.Delete(TestFilePath);
        using (Stream s = new FileStream(TestFilePath, FileMode.Create))
        {
            s.Write(TestFileBuffer, 0, TestFileBuffer.Length);
        }
		*/
		System.Data.SQLite.TypeHolder.Type = StreamType.Memory;
		var bs = new byte[TestFileBuffer.Length];
		TestFileBuffer.CopyTo(bs, 0);
		System.Data.SQLite.MemFileStream.Files [TestFilePath] = bs;
    }

    protected override void OnTearDown()
    {
		System.Data.SQLite.MemStreamHandler.Instance.Delete (TestFilePath);
		//File.Delete(TestFilePath);
    }
}

About

Pure C#.Net SQLite database could run on windows/linux/macos and supports REAL memory database.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.3%
  • Other 0.7%