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); } }
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); }
private void GetKey() { Cursor c = new Cursor(db); byte[] k = new byte[5]; byte[] r = new byte[5]; db.Insert(k, r); c.MovePrevious(); byte[] f = c.GetKey(); checkEqual(k, f); }
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); }
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(); }