Exemple #1
0
        public void test_Load()
        {
            DataSetDalc dsDalc = createDsDalc();
            DataSet     ds     = new DataSet();

            Query subQuery = new Query("roles");

            subQuery.Condition = (QField)"role" == (QConst)"admin";
            subQuery.Fields    = new QField[] { "id" };

            Query q = new Query("users");

            q.Condition = (QField)"role" == subQuery;
            q.Sort      = new QSort[] { "name" };

            dsDalc.Load(q, ds);
            if (ds.Tables["users"].Rows.Count != 2)
            {
                throw new Exception("Load failed");
            }
            if (ds.Tables["users"].Rows[0]["name"].ToString() != "Joe" ||
                ds.Tables["users"].Rows[1]["name"].ToString() != "Mike")
            {
                throw new Exception("Load failed");
            }

            q.Sort = new QSort[] { "role", "name DESC" };
            dsDalc.Load(q, ds);
            if (ds.Tables["users"].Rows.Count != 2)
            {
                throw new Exception("Load failed");
            }
            if (ds.Tables["users"].Rows[0]["name"].ToString() != "Mike" ||
                ds.Tables["users"].Rows[1]["name"].ToString() != "Joe")
            {
                throw new Exception("Load failed");
            }

            q.Condition = (QField)"role" == subQuery & (QField)"id" > (QConst)5;
            dsDalc.Load(q, ds);
            if (ds.Tables["users"].Rows.Count != 0)
            {
                throw new Exception("Load failed");
            }
        }
Exemple #2
0
        public void test_Update()
        {
            DataSetDalc dsDalc = createDsDalc();
            DataSet     ds     = new DataSet();
            Query       q      = new Query("users");

            q.Condition = (QField)"id" == (QConst)1;

            dsDalc.Load(q, ds);
            ds.Tables["users"].Rows[0]["name"] = "Vit";
            var newRow = ds.Tables["users"].Rows.Add(new object[] { 4, "Petya", "2" });

            dsDalc.Update(ds.Tables["users"]);

            Assert.AreEqual(4, dsDalc.RecordsCount(new Query("users")), "Update failed");

            var res = dsDalc.LoadRecord(q);

            Assert.AreEqual("Vit", res["name"].ToString(), "Update failed");

            ds.Tables["users"].Rows[1].Delete();
            dsDalc.Update(ds.Tables["users"]);
            if (dsDalc.PersistedDS.Tables["users"].Rows.Count != 3)
            {
                throw new Exception("Update failed");
            }

            res         = new Hashtable();
            res["name"] = "VVV";
            var affected = dsDalc.Update(q, res);

            Assert.AreEqual(1, affected, "Update by query failed");

            var res2 = dsDalc.LoadRecord(q);

            Assert.AreEqual("VVV", res2["name"], "Update failed");
        }