Close() public method

Closes the Environment
This method wraps the native ups_env_close function.
public Close ( ) : void
return void
示例#1
0
 private void OpenString()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create("ntest.db");
         env.Close();
         env.Open("ntest.db");
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("unexpected exception " + e);
     }
 }
示例#2
0
        private void SetComparator()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            byte[]      k     = new byte[5];
            byte[]      r     = new byte[5];
            Parameter[] param = new Parameter[1];
            param[0]       = new Parameter();
            param[0].name  = UpsConst.UPS_PARAM_KEY_TYPE;
            param[0].value = UpsConst.UPS_TYPE_CUSTOM;

            compareCounter = 0;
            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1, 0, param);
                db.SetCompareFunc(new CompareFunc(MyCompareFunc));
                db.Insert(k, r);
                k[0] = 1;
                db.Insert(k, r);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e) {
                Assert.Fail("unexpected exception " + e);
            }
            Assert.AreEqual(1, compareCounter);
        }
示例#3
0
        private void InsertKey()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            byte[] k  = new byte[5];
            byte[] r1 = new byte[5];
            byte[] r2;
            try {
                env.Create("ntest.db");
                db    = env.CreateDatabase(1);
                k[0]  = 1;
                r1[0] = 1;
                db.Insert(k, r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);

                k[0]  = 2;
                r1[0] = 2;
                db.Insert(k, r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);

                k[0]  = 3;
                r1[0] = 3;
                db.Insert(k, r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e) {
                Assert.Fail("unexpected exception " + e);
            }
        }
示例#4
0
        private void InsertKeyInvalidParam()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            byte[] k = new byte[5];
            byte[] r = new byte[5];
            env.Create("ntest.db");
            db = env.CreateDatabase(1);
            try {
                db.Insert(null, r);
            }
            catch (NullReferenceException) {
            }
            try {
                db.Insert(k, null);
            }
            catch (NullReferenceException) {
            }
            try {
                db.Insert(k, r, 9999);
            }
            catch (DatabaseException e) {
                Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
            }
            db.Close();
            env.Close();
        }
示例#5
0
        private void InsertRecNo()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            byte[] r1 = new byte[5];
            byte[] r2;
            try
            {
                env.Create("ntest.db");
                db    = env.CreateDatabase(1, UpsConst.UPS_RECORD_NUMBER);
                r1[0] = 1;
                var k = db.InsertRecNo(r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);

                r1[0] = 2;
                k     = db.InsertRecNo(r1);
                r2    = db.Find(k);
                checkEqual(r1, r2);

                r1[0] = 3;
                k     = db.InsertRecNo(r1);
                r2    = db.Find(k);
                checkEqual(r1, r2);
            }
            catch (DatabaseException e)
            {
                Assert.Fail("unexpected exception " + e);
            }
            db.Close();
            env.Close();
        }
示例#6
0
 private void Flush()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     env.Create("ntest.db");
     env.Flush();
     env.Close();
 }
示例#7
0
 private void OpenStringIntIntParameter()
 {
     Upscaledb.Environment env   = new Upscaledb.Environment();
     Parameter[]           param = new Parameter[1];
     param[0]       = new Parameter();
     param[0].name  = UpsConst.UPS_PARAM_CACHESIZE;
     param[0].value = 1024;
     try {
         env.Create("ntest.db", 0, 0644, param);
         env.Close();
         env.Open("ntest.db", 0, param);
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("unexpected exception " + e);
     }
 }
示例#8
0
        private void CreateString()
        {
            Database db = new Database();

            Upscaledb.Environment env = new Upscaledb.Environment();
            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1);
                db.Close();
                env.Close();
                env.Open("ntest.db");
                db = env.OpenDatabase(1);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e) {
                Assert.Fail("Unexpected exception " + e);
            }
        }
示例#9
0
 private void CreateStringInt()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create(null, UpsConst.UPS_IN_MEMORY);
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("unexpected exception " + e);
     }
 }
示例#10
0
 private void OpenStringNegative()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Open("ntestxxxxx.db");
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_FILE_NOT_FOUND, e.ErrorCode);
     }
 }
示例#11
0
 private void CreateStringNull()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create(null);
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
     }
 }
示例#12
0
        private void AutoCleanupCursors()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            env.Create("ntest.db");
            db = env.CreateDatabase(1);
            Cursor cursor = new Cursor(db);

            // let gc do the cleanup
            env.Close();
        }
示例#13
0
 private void CreateDatabaseNegative()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create("ntest.db");
         Database db = env.CreateDatabase((short)0);
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
     }
     env.Close();
 }
示例#14
0
 private void OpenDatabaseNegative()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create("ntest.db");
         Database db = env.OpenDatabase((short)99);
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_DATABASE_NOT_FOUND, e.ErrorCode);
     }
     env.Close();
 }
示例#15
0
        private void Transactions()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            env.Create("ntest.db", UpsConst.UPS_ENABLE_TRANSACTIONS);
            db = env.CreateDatabase(1);

            byte[] k = new byte[5];
            byte[] r = new byte[5];
            db.Insert(k, r);
            db.Close();
            env.Close();
        }
示例#16
0
        private void Recovery()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            env.Create("ntest.db", UpsConst.UPS_ENABLE_RECOVERY);
            db = env.CreateDatabase(1);

            byte[] k = new byte[5];
            byte[] r = new byte[5];
            db.Insert(k, r);
            db.Close();
            env.Close();
        }
示例#17
0
        private void FindKeyNull()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1);
                byte[] r = db.Find(null);
            }
            catch (NullReferenceException) {
            }
            db.Close();
            env.Close();
        }
示例#18
0
 private void CreateStringIntIntParameterNeg()
 {
     Upscaledb.Environment env   = new Upscaledb.Environment();
     Parameter[]           param = new Parameter[1];
     param[0]       = new Parameter();
     param[0].name  = UpsConst.UPS_PARAM_PAGESIZE;
     param[0].value = 777;
     try {
         env.Create("ntest.db", 0, 0644, param);
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PAGESIZE, e.ErrorCode);
     }
 }
示例#19
0
        private void EraseKeyNegative()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            byte[] k = new byte[5];
            env.Create("ntest.db");
            db = env.CreateDatabase(1);
            try {
                db.Erase(null);
            }
            catch (NullReferenceException) {
            }
            db.Close();
            env.Close();
        }
示例#20
0
        private void EraseUnknownKey()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            byte[] k = new byte[5];
            env.Create("ntest.db");
            db = env.CreateDatabase(1);
            try {
                db.Erase(k);
            }
            catch (DatabaseException e) {
                Assert.AreEqual(UpsConst.UPS_KEY_NOT_FOUND, e.ErrorCode);
            }
            db.Close();
            env.Close();
        }
示例#21
0
        private void CreateInvalidParameter()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            Parameter[] param = new Parameter[3];
            param[1] = new Parameter();
            param[2] = new Parameter();
            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1, 0, param);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e) {
                Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
            }
        }
示例#22
0
        private void EraseUnknownDatabase()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            byte[] k = new byte[5];
            byte[] r = new byte[5];

            env.Create("ntest.db");
            Database db = env.CreateDatabase((short)13);

            db.Insert(k, r);
            db.Close();
            try {
                env.EraseDatabase((short)99);
            }
            catch (DatabaseException e) {
                Assert.AreEqual(UpsConst.UPS_DATABASE_NOT_FOUND, e.ErrorCode);
            }
            env.Close();
        }
示例#23
0
        private void GetKeyCount()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            env.Create("ntest.db");
            db = env.CreateDatabase(1);

            byte[] k = new byte[5];
            byte[] r = new byte[5];
            Assert.AreEqual(0, db.GetCount());
            db.Insert(k, r);
            Assert.AreEqual(1, db.GetCount());
            k[0] = 1;
            db.Insert(k, r);
            Assert.AreEqual(2, db.GetCount());
            db.Close();
            env.Close();
        }
示例#24
0
        private void InsertKeyNegative()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            byte[] k = new byte[5];
            byte[] r = new byte[5];
            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1);
                db.Insert(k, r);
                db.Insert(k, r);
            }
            catch (DatabaseException e) {
                Assert.AreEqual(UpsConst.UPS_DUPLICATE_KEY, e.ErrorCode);
            }
            db.Close();
            env.Close();
        }
示例#25
0
        private void Cursor10000Test()
        {
            //create database
            Upscaledb.Environment env = new Upscaledb.Environment();
            env.Create("ntest.db");

            Parameter[] param = new Parameter[1];
            param[0]       = new Parameter();
            param[0].name  = UpsConst.UPS_PARAM_KEY_TYPE;
            param[0].value = UpsConst.UPS_TYPE_UINT64;
            Database db = env.CreateDatabase(1, 0, param);

            //insert records
            for (ulong i = 0; i < 10000; i++)
            {
                byte[] key    = BitConverter.GetBytes(i);
                byte[] record = new byte[20];
                db.Insert(key, record);
            }

            //close database
            db.Close();

            //reopen again
            db = env.OpenDatabase(1);
            Cursor cursor = new Cursor(db);

            cursor.MoveFirst();
            ulong firstKey = BitConverter.ToUInt64(cursor.GetKey(), 0);

            Assert.AreEqual((ulong)0, firstKey);

            cursor.MoveLast();
            ulong lastKey = BitConverter.ToUInt64(cursor.GetKey(), 0);

            Assert.AreEqual((ulong)9999, lastKey);

            //close database
            cursor.Close();
            db.Close();
            env.Close();
        }
示例#26
0
 private void CreateDatabaseShort()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     byte[] k = new byte[5];
     byte[] r = new byte[5];
     try {
         env.Create("ntest.db");
         Database db = env.CreateDatabase((short)13);
         db.Insert(k, r);
         db.Close();
         db = env.OpenDatabase((short)13);
         byte[] f = db.Find(k);
         checkEqual(r, f);
         // db.Close();
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("unexpected exception " + e);
     }
 }
        public void Start(string context, int recordCount, int?threadCount = null)
        {
            Log.Clear();

            Context     = context;
            RecordCount = recordCount;
            ThreadCount = threadCount;
            var engine = GetType().Name;

            Log.AppendLine($"# Context: {Context} | Engine: {engine} | Records: {recordCount} | Threads: {threadCount}");

            var databaseName = $@"{context.Replace(" ", "_").ToLower()}_{engine.ToLower()}.db";

            if (Directory.Exists(databaseName))
            {
                Directory.Delete(databaseName, true);
            }

            var databasePath = Path.Combine(System.Environment.CurrentDirectory, databaseName);

            var environment = new Upscaledb.Environment();
            var db          = new Database();

            environment.Create(databaseName);
            db = environment.CreateDatabase(1);

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            _actions.ForEach(action => action(db));

            stopWatch.Stop();

            environment.Flush();
            environment.Close();
            db.Close();

            Log.AppendFormat("# Context: {0} | Engine: {1} | Total time: {2:hh\\:mm\\:ss\\.ffff}\n", Context, engine, stopWatch.Elapsed);
            Log.AppendLine("\n");
        }
示例#28
0
        private void InsertKeyOverwrite()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            byte[] k = new byte[5];
            byte[] r = new byte[5];
            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1);
                db.Insert(k, r);
                r[0] = 1;
                db.Insert(k, r, UpsConst.UPS_OVERWRITE);
                byte[] r2 = db.Find(k);
                checkEqual(r, r2);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e) {
                Assert.Fail("unexpected exception " + e);
            }
        }
示例#29
0
        private void ApproxMatching()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            byte[] k1 = new byte[5];
            byte[] r1 = new byte[5];
            k1[0] = 1; r1[0] = 1;
            byte[] k2 = new byte[5];
            byte[] r2 = new byte[5];
            k2[0] = 2; r2[0] = 2;
            byte[] k3 = new byte[5];
            byte[] r3 = new byte[5];
            k3[0] = 3; r3[0] = 3;
            try
            {
                env.Create("ntest.db");
                db = env.CreateDatabase(1);
                db.Insert(k1, r1);
                db.Insert(k2, r2);
                db.Insert(k3, r3);

                Cursor c = new Cursor(db);
                byte[] r = c.Find(k2, UpsConst.UPS_FIND_GT_MATCH);
                checkEqual(r, r3);
                checkEqual(k2, k3);
                k2[0] = 2;
                r     = c.Find(k2, UpsConst.UPS_FIND_GT_MATCH);
                checkEqual(r, r1);
                checkEqual(k2, k1);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e)
            {
                Assert.Fail("unexpected exception " + e);
            }
        }
示例#30
0
        private void GetDatabaseNames()
        {
            Database db;

            short[] names;
            short[] s1 = { 13 };
            short[] s2 = { 13, 14 };
            short[] s3 = { 13, 14, 15 };
            Upscaledb.Environment env = new Upscaledb.Environment();

            env.Create("ntest.db");
            db    = env.CreateDatabase(13);
            names = env.GetDatabaseNames();
            Assert.AreEqual(s1.Length, names.Length);
            for (int i = 0; i < s1.Length; i++)
            {
                Assert.AreEqual(s1[i], names[i]);
            }

            db    = env.CreateDatabase(14);
            names = env.GetDatabaseNames();
            Assert.AreEqual(s2.Length, names.Length);
            for (int i = 0; i < s2.Length; i++)
            {
                Assert.AreEqual(s2[i], names[i]);
            }

            db    = env.CreateDatabase(15);
            names = env.GetDatabaseNames();
            Assert.AreEqual(s3.Length, names.Length);
            for (int i = 0; i < s3.Length; i++)
            {
                Assert.AreEqual(s3[i], names[i]);
            }

            env.Close();
        }
示例#31
0
        static void Main(string[] args)
        {
            byte[] key = new byte[5];
            byte[] record = new byte[5];
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();

            /*
             * first, create a new Database
             */
            env.Create("test.db");
            db = env.CreateDatabase(1);

            /*
             * now we can insert, delete or lookup values in the Database
             *
             * for our test program, we just insert a few values, then look them
             * up, then delete them and try to look them up again (which will fail).
             */
            for (int i = 0; i < LOOP; i++) {
                key[0] = (byte)i;
                record[0] = (byte)i;
                db.Insert(key, record);
            }

            /*
             * now look up all values
             */
            for (int i = 0; i < LOOP; i++) {
                key[0] = (byte)i;
                byte[] r = db.Find(key);

                /*
                 * check if the value is ok
                 */
                if (r[0] != (byte)i) {
                    Console.Out.WriteLine("db.Find() returned bad value");
                    return;
                }
            }

            /*
             * close the Database handle, then re-open it (just to demonstrate how
             * to open a Database file)
             */
            db.Close();
            env.Close();
            env.Open("test.db");
            db = env.OpenDatabase(1);

            /*
             * now erase all values
             */
            for (int i = 0; i < LOOP; i++) {
                key[0] = (byte)i;
                db.Erase(key);
            }

            /*
             * once more we try to find all values... every db.Find() call must
             * now fail with HAM_KEY_NOT_FOUND
             */
            for (int i = 0; i < LOOP; i++) {
                key[0] = (byte)i;

                try {
                    byte[] r = db.Find(key);
                }
                catch (DatabaseException e) {
                    if (e.ErrorCode != UpsConst.UPS_KEY_NOT_FOUND) {
                        Console.Out.WriteLine("db.Find() returned error " + e);
                        return;
                    }
                }
            }

            /*
             * We're done! No need to close the Database handle - it's closed automatically
             */
            Console.Out.WriteLine("Success!");
        }
示例#32
0
        private void SetComparator()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            byte[] k = new byte[5];
            byte[] r = new byte[5];
            Parameter[] param = new Parameter[1];
            param[0] = new Parameter();
            param[0].name = UpsConst.UPS_PARAM_KEY_TYPE;
            param[0].value = UpsConst.UPS_TYPE_CUSTOM;

            compareCounter = 0;
            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1, 0, param);
                db.SetCompareFunc(new CompareFunc(MyCompareFunc));
                db.Insert(k, r);
                k[0] = 1;
                db.Insert(k, r);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e) {
                Assert.Fail("unexpected exception " + e);
            }
            Assert.AreEqual(1, compareCounter);
        }
示例#33
0
        private void Transactions()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            env.Create("ntest.db", UpsConst.UPS_ENABLE_TRANSACTIONS);
            db = env.CreateDatabase(1);

            byte[] k = new byte[5];
            byte[] r = new byte[5];
            db.Insert(k, r);
            db.Close();
            env.Close();
        }
示例#34
0
        private void Cursor10000Test()
        {
            //create database
            Upscaledb.Environment env = new Upscaledb.Environment();
            env.Create("ntest.db");

            Parameter[] param = new Parameter[1];
            param[0] = new Parameter();
            param[0].name = UpsConst.UPS_PARAM_KEY_TYPE;
            param[0].value = UpsConst.UPS_TYPE_UINT64;
            Database db = env.CreateDatabase(1, 0, param);

            //insert records
            for (ulong i = 0; i < 10000; i++)
            {
                byte[] key = BitConverter.GetBytes(i);
                byte[] record = new byte[20];
                db.Insert(key, record);
            }

            //close database
            db.Close();

            //reopen again
            db = env.OpenDatabase(1);
            Cursor cursor = new Cursor(db);

            cursor.MoveFirst();
            ulong firstKey = BitConverter.ToUInt64(cursor.GetKey(), 0);
            Assert.AreEqual((ulong)0, firstKey);

            cursor.MoveLast();
            ulong lastKey = BitConverter.ToUInt64(cursor.GetKey(), 0);
            Assert.AreEqual((ulong)9999, lastKey);

            //close database
            cursor.Close();
            db.Close();
            env.Close();
        }
示例#35
0
        private void Recovery()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            env.Create("ntest.db", UpsConst.UPS_ENABLE_RECOVERY);
            db = env.CreateDatabase(1);

            byte[] k = new byte[5];
            byte[] r = new byte[5];
            db.Insert(k, r);
            db.Close();
            env.Close();
        }
示例#36
0
 private void OpenStringNegative()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Open("ntestxxxxx.db");
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_FILE_NOT_FOUND, e.ErrorCode);
     }
 }
示例#37
0
 private void AutoCleanupCursors4()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     env.Create("ntest.db");
     db = env.CreateDatabase(1);
     Cursor cursor1 = new Cursor(db);
     Cursor cursor2 = cursor1.Clone();
     Cursor cursor3 = cursor1.Clone();
     Cursor cursor4 = cursor1.Clone();
     Cursor cursor5 = cursor1.Clone();
     cursor3.Close();
     cursor5.Close();
     // let gc do the cleanup
     env.Close();
 }
示例#38
0
 private void OpenDatabaseNegative()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create("ntest.db");
         Database db = env.OpenDatabase((short)99);
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_DATABASE_NOT_FOUND, e.ErrorCode);
     }
     env.Close();
 }
示例#39
0
 private void Flush()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     env.Create("ntest.db");
     env.Flush();
     env.Close();
 }
示例#40
0
 private void FindUnknownKey()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     byte[] k = new byte[5];
     try {
         env.Create("ntest.db");
         db = env.CreateDatabase(1);
         byte[] r = db.Find(k);
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_KEY_NOT_FOUND, e.ErrorCode);
     }
     db.Close();
     env.Close();
 }
示例#41
0
        private void GetKeyCount()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            env.Create("ntest.db");
            db = env.CreateDatabase(1);

            byte[] k = new byte[5];
            byte[] r = new byte[5];
            Assert.AreEqual(0, db.GetCount());
            db.Insert(k, r);
            Assert.AreEqual(1, db.GetCount());
            k[0] = 1;
            db.Insert(k, r);
            Assert.AreEqual(2, db.GetCount());
            db.Close();
            env.Close();
        }
示例#42
0
 private void FindKeyNull()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     try {
         env.Create("ntest.db");
         db = env.CreateDatabase(1);
         byte[] r = db.Find(null);
     }
     catch (NullReferenceException) {
     }
     db.Close();
     env.Close();
 }
示例#43
0
        private void EraseKeyTwice()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            byte[] k = new byte[5];
            byte[] r = new byte[5];

            env.Create("ntest.db");
            db = env.CreateDatabase(1);
            db.Insert(k, r);
            byte[] r2 = db.Find(k);
            checkEqual(r, r2);
            db.Erase(k);

            try {
                db.Erase(k);
            }
            catch (DatabaseException e) {
                Assert.AreEqual(UpsConst.UPS_KEY_NOT_FOUND, e.ErrorCode);
            }
            db.Close();
            env.Close();
        }
示例#44
0
 private void EraseKeyNegative()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     byte[] k = new byte[5];
     env.Create("ntest.db");
     db = env.CreateDatabase(1);
     try {
         db.Erase(null);
     }
     catch (NullReferenceException) {
     }
     db.Close();
     env.Close();
 }
示例#45
0
 private void CreateDatabaseNegative()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create("ntest.db");
         Database db = env.CreateDatabase((short)0);
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
     }
     env.Close();
 }
示例#46
0
 private void CreateInvalidParameter()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     Parameter[] param = new Parameter[3];
     param[1] = new Parameter();
     param[2] = new Parameter();
     try {
         env.Create("ntest.db");
         db = env.CreateDatabase(1, 0, param);
         db.Close();
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
     }
 }
示例#47
0
 private void RenameDatabase()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     byte[] k = new byte[5];
     byte[] r = new byte[5];
     try {
         env.Create("ntest.db");
         Database db = env.CreateDatabase((short)13);
         db.Insert(k, r);
         db.Close();
         env.RenameDatabase((short)13, (short)15);
         db = env.OpenDatabase((short)15);
         byte[] f = db.Find(k);
         checkEqual(r, f);
         // db.Close();
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("unexpected exception " + e);
     }
 }
示例#48
0
 private void InsertKeyOverwrite()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     byte[] k = new byte[5];
     byte[] r = new byte[5];
     try {
         env.Create("ntest.db");
         db = env.CreateDatabase(1);
         db.Insert(k, r);
         r[0] = 1;
         db.Insert(k, r, UpsConst.UPS_OVERWRITE);
         byte[] r2 = db.Find(k);
         checkEqual(r, r2);
         db.Close();
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("unexpected exception " + e);
     }
 }
示例#49
0
 private void OpenString()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create("ntest.db");
         env.Close();
         env.Open("ntest.db");
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("unexpected exception " + e);
     }
 }
示例#50
0
        private void InsertRecNo()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            byte[] r1 = new byte[5];
            byte[] r2;
            try
            {
                env.Create("ntest.db");
                db = env.CreateDatabase(1, UpsConst.UPS_RECORD_NUMBER);
                r1[0] = 1;
                var k = db.InsertRecNo(r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);

                r1[0] = 2;
                k = db.InsertRecNo(r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);

                r1[0] = 3;
                k = db.InsertRecNo(r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);
            }
            catch (DatabaseException e)
            {
                Assert.Fail("unexpected exception " + e);
            }
            db.Close();
            env.Close();
        }
示例#51
0
        private void InsertKey()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            byte[] k = new byte[5];
            byte[] r1 = new byte[5];
            byte[] r2;
            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1);
                k[0] = 1;
                r1[0] = 1;
                db.Insert(k, r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);

                k[0] = 2;
                r1[0] = 2;
                db.Insert(k, r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);

                k[0] = 3;
                r1[0] = 3;
                db.Insert(k, r1);
                r2 = db.Find(k);
                checkEqual(r1, r2);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e) {
                Assert.Fail("unexpected exception " + e);
            }
        }
示例#52
0
        private void EraseUnknownDatabase()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            byte[] k = new byte[5];
            byte[] r = new byte[5];

            env.Create("ntest.db");
            Database db = env.CreateDatabase((short)13);
            db.Insert(k, r);
            db.Close();
            try {
                env.EraseDatabase((short)99);
            }
            catch (DatabaseException e) {
                Assert.AreEqual(UpsConst.UPS_DATABASE_NOT_FOUND, e.ErrorCode);
            }
            env.Close();
        }
示例#53
0
        private void GetDatabaseNames()
        {
            Database db;
            short[] names;
            short[] s1 ={ 13 };
            short[] s2 ={ 13, 14 };
            short[] s3 ={ 13, 14, 15 };
            Upscaledb.Environment env = new Upscaledb.Environment();

            env.Create("ntest.db");
            db = env.CreateDatabase(13);
            names = env.GetDatabaseNames();
            Assert.AreEqual(s1.Length, names.Length);
            for (int i = 0; i < s1.Length; i++)
                Assert.AreEqual(s1[i], names[i]);

            db = env.CreateDatabase(14);
            names = env.GetDatabaseNames();
            Assert.AreEqual(s2.Length, names.Length);
            for (int i = 0; i < s2.Length; i++)
                Assert.AreEqual(s2[i], names[i]);

            db = env.CreateDatabase(15);
            names = env.GetDatabaseNames();
            Assert.AreEqual(s3.Length, names.Length);
            for (int i = 0; i < s3.Length; i++)
                Assert.AreEqual(s3[i], names[i]);

            env.Close();
        }
示例#54
0
 private void InsertKeyInvalidParam()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     byte[] k = new byte[5];
     byte[] r = new byte[5];
     env.Create("ntest.db");
     db = env.CreateDatabase(1);
     try {
         db.Insert(null, r);
     }
     catch (NullReferenceException) {
     }
     try {
         db.Insert(k, null);
     }
     catch (NullReferenceException) {
     }
     try {
         db.Insert(k, r, 9999);
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
     }
     db.Close();
     env.Close();
 }
示例#55
0
 private void CreateString()
 {
     Database db = new Database();
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create("ntest.db");
         db = env.CreateDatabase(1);
         db.Close();
         env.Close();
         env.Open("ntest.db");
         db = env.OpenDatabase(1);
         db.Close();
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("Unexpected exception " + e);
     }
 }
示例#56
0
 private void InsertKeyNegative()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     byte[] k = new byte[5];
     byte[] r = new byte[5];
     try {
         env.Create("ntest.db");
         db = env.CreateDatabase(1);
         db.Insert(k, r);
         db.Insert(k, r);
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_DUPLICATE_KEY, e.ErrorCode);
     }
     db.Close();
     env.Close();
 }
示例#57
0
 private void CreateStringIntIntParameter()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     Parameter[] param = new Parameter[1];
     param[0] = new Parameter();
     param[0].name = UpsConst.UPS_PARAM_CACHESIZE;
     param[0].value = 1024;
     try {
         env.Create("ntest.db", 0, 0644, param);
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("Unexpected exception " + e);
     }
 }
示例#58
0
 private void CreateStringIntIntParameterNeg()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     Parameter[] param = new Parameter[1];
     param[0] = new Parameter();
     param[0].name = UpsConst.UPS_PARAM_CACHESIZE;
     param[0].value = 1024;
     try {
         env.Create("ntest.db", UpsConst.UPS_IN_MEMORY, 0644, param);
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
     }
 }
示例#59
0
        private void ApproxMatching()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            byte[] k1 = new byte[5];
            byte[] r1 = new byte[5];
            k1[0] = 1; r1[0] = 1;
            byte[] k2 = new byte[5];
            byte[] r2 = new byte[5];
            k2[0] = 2; r2[0] = 2;
            byte[] k3 = new byte[5];
            byte[] r3 = new byte[5];
            k3[0] = 3; r3[0] = 3;
            try
            {
                env.Create("ntest.db");
                db = env.CreateDatabase(1);
                db.Insert(k1, r1);
                db.Insert(k2, r2);
                db.Insert(k3, r3);

                Cursor c = new Cursor(db);
                byte[] r = c.Find(k2, UpsConst.UPS_FIND_GT_MATCH);
                checkEqual(r, r3);
                checkEqual(k2, k3);
                k2[0] = 2;
                r = c.Find(k2, UpsConst.UPS_FIND_GT_MATCH);
                checkEqual(r, r1);
                checkEqual(k2, k1);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e)
            {
                Assert.Fail("unexpected exception " + e);
            }
        }
示例#60
0
 private void CreateStringNull()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     try {
         env.Create(null);
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
     }
 }