Find() public method

Searches a key and points the Cursor to this key; returns the record of the key
public Find ( byte key ) : byte[]
key byte
return byte[]
Exemplo n.º 1
0
 private void Find()
 {
     Cursor c = new Cursor(db);
     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;
     db.Insert(k1, r1);
     db.Insert(k2, r2);
     c.Find(k1);
     byte[] f = c.GetRecord();
     checkEqual(r1, f);
     c.Find(k2);
     byte[] g = c.GetRecord();
     checkEqual(r2, g);
 }
Exemplo n.º 2
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);
            }
        }