Insert() public method

Inserts a Database item and points the Cursor to the new item
This is an overloaded function for Insert(key, record, 0).
public Insert ( byte key, byte record ) : void
key byte The key of the new item
record byte The record of the new item
return void
Beispiel #1
0
        private void InsertNegative()
        {
            Cursor c = new Cursor(db);
            byte[] q;
            byte[] k1 = new byte[5]; k1[0] = 5;
            byte[] r1 = new byte[5]; r1[0] = 1;
            byte[] r2 = new byte[5]; r2[0] = 2;
            c.Insert(k1, r1);
            q = c.GetRecord();
            checkEqual(r1, q);
            q = c.GetKey();
            checkEqual(k1, q);

            try {
                c.Insert(k1, r2);
            }
            catch (DatabaseException e) {
                Assert.AreEqual(UpsConst.UPS_DUPLICATE_KEY, e.ErrorCode);
            }
        }
Beispiel #2
0
        private void InsertDuplicate()
        {
            Cursor c = new Cursor(db);
            byte[] q;
            byte[] k1 = new byte[5]; k1[0] = 5;
            byte[] r1 = new byte[5]; r1[0] = 1;
            byte[] r2 = new byte[5]; r2[0] = 2;
            c.Insert(k1, r1);
            q = c.GetRecord();
            checkEqual(r1, q);
            q = c.GetKey();
            checkEqual(k1, q);

            c.Insert(k1, r2, UpsConst.UPS_DUPLICATE);
            q = c.GetRecord();
            checkEqual(r2, q);
            q = c.GetKey();
            checkEqual(k1, q);
        }
Beispiel #3
0
        private void Insert()
        {
            Cursor c = new Cursor(db);
            byte[] q;
            byte[] k1 = new byte[5]; k1[0] = 5;
            byte[] k2 = new byte[5]; k2[0] = 6;
            byte[] r1 = new byte[5]; r1[0] = 1;
            byte[] r2 = new byte[5]; r2[0] = 2;
            c.Insert(k1, r1);
            q = c.GetRecord();
            checkEqual(r1, q);
            q = c.GetKey();
            checkEqual(k1, q);

            c.Insert(k2, r2);
            q = c.GetRecord();
            checkEqual(r2, q);
            q = c.GetKey();
            checkEqual(k2, q);
        }
Beispiel #4
0
        private void GetDuplicateCount()
        {
            Cursor c = new Cursor(db);
            byte[] k1 = new byte[5]; k1[0] = 5;
            byte[] r1 = new byte[5]; r1[0] = 1;
            byte[] r2 = new byte[5]; r2[0] = 2;
            byte[] r3 = new byte[5]; r2[0] = 2;
            c.Insert(k1, r1);
            Assert.AreEqual(1, c.GetDuplicateCount());

            c.Insert(k1, r2, UpsConst.UPS_DUPLICATE);
            Assert.AreEqual(2, c.GetDuplicateCount());

            c.Insert(k1, r3, UpsConst.UPS_DUPLICATE);
            Assert.AreEqual(3, c.GetDuplicateCount());

            c.Erase();
            c.MoveFirst();
            Assert.AreEqual(2, c.GetDuplicateCount());
        }
Beispiel #5
0
 private void Erase()
 {
     Cursor c = new Cursor(db);
     byte[] k1 = new byte[5]; k1[0] = 5;
     byte[] r1 = new byte[5]; r1[0] = 1;
     c.Insert(k1, r1);
     c.Erase();
 }
 private void CursorTest()
 {
     Transaction t = env.Begin();
     Cursor c = new Cursor(db, t);
     byte[] k = new byte[5];
     byte[] r = new byte[5];
     c.Insert(k, r);
     db.Find(t, k);
     c.Close();
     t.Commit();
     db.Find(k);
 }