public 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(HamConst.HAM_DUPLICATE_KEY, e.ErrorCode); } }
public 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, HamConst.HAM_DUPLICATE); q = c.GetRecord(); checkEqual(r2, q); q = c.GetKey(); checkEqual(k1, q); }
public 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); }
public 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 Cursor10000Test() { //create database Hamster.Environment env = new Hamster.Environment(); env.Create("ntest.db"); Parameter[] param = new Parameter[1]; param[0] = new Parameter(); param[0].name = HamConst.HAM_PARAM_KEY_TYPE; param[0].value = HamConst.HAM_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(); }
public void Cursor10000Test() { //create database Database hamster = CreateDatabase("test.db"); //insert records for (ulong i = 0; i < 10000; i++) { byte[] key = BitConverter.GetBytes(i); byte[] record = new byte[20]; hamster.Insert(key, record); } //close database hamster.Close(); //reopen again hamster = OpenDatabase("test.db"); Cursor cursor = new Cursor(hamster); 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(); hamster.Close(); }