Exemple #1
0
        public void RecWrite()
        {
            using (var rec = new DaoRec(CopyDb("Write"), "Tabl"))
            {
                rec.Read();
                rec.Put("IntField", 11);
                rec.Put("RealField", 1.6);
                rec.Put("StringField1", "Большой текст");
                rec.Put("StringField2", "TextTextTextTextTextText", true);
                rec.Put("BoolField", false);
                rec.Put("TimeField", new DateTime(2016, 07, 02));
                Assert.AreEqual(11, rec.GetInt("IntField"));
                Assert.AreEqual(1.6, rec.GetDouble("RealField"));
                Assert.AreEqual("Большой текст", rec.GetString("StringField1"));
                Assert.AreEqual("TextTextTe", rec.GetString("StringField2"));
                Assert.AreEqual(new DateTime(2016, 07, 02), rec.GetTime("TimeField"));
                Assert.IsFalse(rec.GetBool("BoolField"));
                Assert.AreEqual(1, rec.GetInt("Id"));
                rec.Update();
                rec.MoveFirst();
                Assert.AreEqual(11, rec.GetInt("IntField"));
                Assert.AreEqual(1.6, rec.GetDouble("RealField"));
                Assert.AreEqual("Большой текст", rec.GetString("StringField1"));
                Assert.AreEqual("TextTextTe", rec.GetString("StringField2"));
                Assert.AreEqual(new DateTime(2016, 07, 02), rec.GetTime("TimeField"));
                Assert.IsFalse(rec.GetBool("BoolField"));
                Assert.AreEqual(1, rec.GetInt("Id"));
                rec.Put(1, 11);
                rec.Put(2, 1.6);
                rec.Put(3, "Большой текст");
                rec.Put(4, "TextTextTextTextTextText", true);
                rec.Put(5, false);
                rec.Put(6, new DateTime(2016, 07, 02));
                Assert.AreEqual(11, rec.GetInt("IntField"));
                Assert.AreEqual(1.6, rec.GetDouble("RealField"));
                Assert.AreEqual("Большой текст", rec.GetString("StringField1"));
                Assert.AreEqual("TextTextTe", rec.GetString("StringField2"));
                Assert.AreEqual(new DateTime(2016, 07, 02), rec.GetTime("TimeField"));
                Assert.IsFalse(rec.GetBool("BoolField"));
                Assert.AreEqual(1, rec.GetInt("Id"));

                rec.Read();
                rec.Put("IntField", (int?)null);
                rec.Put("RealField", (double?)null);
                rec.Put("StringField1", (string)null);
                rec.Put("StringField2", "Text", true);
                rec.Put("BoolField", (bool?)false);
                rec.Put("TimeField", (DateTime?)null);
                Assert.AreEqual(null, rec.GetIntNull("IntField"));
                Assert.AreEqual(0, rec.GetDouble("RealField"));
                Assert.AreEqual("", rec.GetString("StringField1", ""));
                Assert.AreEqual("Text", rec.GetString("StringField2"));
                Assert.AreEqual(false, rec.GetBoolNull("BoolField"));
                Assert.AreEqual(2, rec.GetInt("Id"));
                rec.Read();
                rec.MovePrevious();
                Assert.AreEqual(0, rec.GetInt("IntField"));
                Assert.AreEqual(null, rec.GetDoubleNull("RealField"));
                Assert.AreEqual(null, rec.GetString("StringField1"));
                Assert.AreEqual("Text", rec.GetString("StringField2"));
                Assert.AreEqual(null, rec.GetTimeNull("TimeField"));
                Assert.AreEqual(false, rec.GetBool("BoolField"));
                Assert.AreEqual(2, rec.GetIntNull("Id"));
                rec.Put(1, (int?)null);
                rec.Put(2, (double?)null);
                rec.Put(3, (string)null);
                rec.Put(4, "Text", true);
                rec.Put(5, (bool?)false);
                rec.Put(6, (DateTime?)null);
                Assert.AreEqual(null, rec.GetIntNull("IntField"));
                Assert.AreEqual(0, rec.GetDouble("RealField"));
                Assert.AreEqual("", rec.GetString("StringField1", ""));
                Assert.AreEqual("Text", rec.GetString("StringField2"));
                Assert.AreEqual(false, rec.GetBoolNull("BoolField"));
                Assert.AreEqual(2, rec.GetInt("Id"));

                Assert.AreEqual(5, rec.RecordCount);
                Assert.IsTrue(rec.MoveLast());
                rec.Delete();
                Assert.AreEqual(4, rec.RecordCount);
                Assert.IsTrue(rec.MoveLast());
                Assert.AreEqual(40, rec.GetInt("IntField"));
                Assert.AreEqual(4.5, rec.GetDouble("RealField"));
                Assert.AreEqual("Большой текст 4", rec.GetString("StringField1"));
                Assert.IsTrue(rec.MoveLast());
                Assert.IsFalse(rec.MoveNext());
                Assert.IsTrue(rec.EOF);
                rec.AddNew();
                rec.Put("IntField", 60);
                rec.Put("RealField", 6.6);
                rec.Put("StringField1", "Большой текст 6");
                rec.Put("StringField2", "Text6", true);
                rec.Put("BoolField", true);
                rec.Put("TimeField", new DateTime(2016, 07, 06));
                Assert.AreEqual(60, rec.GetInt("IntField"));
                Assert.AreEqual(6.6, rec.GetDouble("RealField"));
                Assert.AreEqual("Большой текст 6", rec.GetString("StringField1"));
                Assert.AreEqual("Text6", rec.GetString("StringField2"));
                Assert.AreEqual(new DateTime(2016, 07, 06), rec.GetTime("TimeField"));
                Assert.IsTrue(rec.GetBool("BoolField"));
                Assert.AreEqual(6, rec.GetInt("Id"));
                Assert.IsTrue(rec.MoveFirst());
                Assert.IsTrue(rec.MoveLast());
                Assert.AreEqual(60, rec.GetInt("IntField"));
                Assert.AreEqual(6.6, rec.GetDouble("RealField"));
                Assert.AreEqual("Большой текст 6", rec.GetString("StringField1"));
                Assert.AreEqual("Text6", rec.GetString("StringField2"));
                Assert.AreEqual(new DateTime(2016, 07, 06), rec.GetTime("TimeField"));
                Assert.IsTrue(rec.GetBool("BoolField"));
                Assert.AreEqual(6, rec.GetInt("Id"));
                Assert.AreEqual(5, rec.RecordCount);
                Assert.IsTrue(rec.HasRows);
            }
        }
Exemple #2
0
        public void Rec()
        {
            var db   = CopyDb("");
            var file = File("");
            var rec  = new DaoRec(db, "Tabl");

            Assert.IsNotNull(rec.DaoDb);
            Assert.AreEqual(file, rec.DaoDb.File);
            Assert.AreEqual(7, rec.FieldsCount);
            Assert.IsTrue(rec.ContainsField("IntField"));
            Assert.IsTrue(rec.ContainsField("RealField"));
            Assert.IsTrue(rec.ContainsField("StringField1"));
            Assert.IsTrue(rec.ContainsField("id"));

            Assert.AreEqual(5, rec.RecordCount);
            Assert.IsTrue(rec.HasRows);
            Assert.IsFalse(rec.EOF);
            Assert.IsFalse(rec.BOF);
            Assert.IsFalse(rec.Read());
            Assert.IsTrue(rec.MoveFirst());
            Assert.IsTrue(rec.MoveNext());
            Assert.IsTrue(rec.MoveFirst());
            Assert.IsFalse(rec.MovePrevious());
            Assert.IsTrue(rec.BOF);
            Assert.IsFalse(rec.EOF);
            Assert.IsTrue(rec.MoveLast());
            Assert.IsTrue(rec.MovePrevious());
            Assert.IsTrue(rec.MoveLast());
            Assert.IsFalse(rec.MoveNext());
            Assert.IsTrue(rec.EOF);
            Assert.IsFalse(rec.BOF);
            Assert.IsFalse(rec.NoMatch);
            rec.Dispose();

            rec = new DaoRec(db, "EmptyTabl");
            Assert.IsNotNull(rec.DaoDb);
            Assert.AreEqual(file, rec.DaoDb.File);
            Assert.AreEqual(1, rec.FieldsCount);
            Assert.IsTrue(rec.ContainsField("StringField"));

            Assert.AreEqual(0, rec.RecordCount);
            Assert.IsFalse(rec.HasRows);
            Assert.IsTrue(rec.EOF);
            Assert.IsTrue(rec.BOF);
            Assert.IsFalse(rec.Read());
            Assert.IsFalse(rec.MoveFirst());
            Assert.IsFalse(rec.MoveNext());
            Assert.IsFalse(rec.MoveLast());
            Assert.IsFalse(rec.MovePrevious());
            Assert.IsTrue(rec.EOF);
            Assert.IsTrue(rec.EOF);
            Assert.IsFalse(rec.NoMatch);
            rec.Dispose();

            rec = new DaoRec(db, "SELECT Tabl.IntField, Tabl.RealField, SubTabl.StringSubField FROM Tabl INNER JOIN SubTabl ON Tabl.Id = SubTabl.ParentId");
            Assert.IsNotNull(rec.DaoDb);
            Assert.AreEqual(file, rec.DaoDb.File);
            Assert.AreEqual(3, rec.FieldsCount);
            Assert.IsTrue(rec.ContainsField("IntField"));
            Assert.IsTrue(rec.ContainsField("RealField"));
            Assert.IsTrue(rec.ContainsField("StringSubField"));

            Assert.AreEqual(7, rec.RecordCount);
            Assert.IsTrue(rec.HasRows);
            Assert.IsFalse(rec.EOF);
            Assert.IsFalse(rec.BOF);
            Assert.IsFalse(rec.Read());
            Assert.IsTrue(rec.MoveFirst());
            Assert.IsTrue(rec.MoveNext());
            Assert.IsTrue(rec.MoveFirst());
            Assert.IsFalse(rec.MovePrevious());
            Assert.IsTrue(rec.BOF);
            Assert.IsFalse(rec.EOF);
            Assert.IsTrue(rec.MoveLast());
            Assert.IsTrue(rec.MovePrevious());
            Assert.IsTrue(rec.MoveLast());
            Assert.IsFalse(rec.MoveNext());
            Assert.IsTrue(rec.EOF);
            Assert.IsFalse(rec.BOF);
            Assert.IsFalse(rec.NoMatch);
            rec.Dispose();

            db.Dispose();
        }