public void QueryMap6()
        {
            int begin = 1;
            int end   = 10;

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(setName);
            stmt.SetFilter(Filter.Range(binName, begin, end));

            // Map bin contains keys "A" and "C".
            QueryPolicy policy = new QueryPolicy();

            List <string> list = new List <string>();

            list.Add("A");
            list.Add("C");

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    ListExp.Size(                     // return type VALUE returns a list
                        MapExp.GetByKeyList(MapReturnType.VALUE, Exp.Val(list), Exp.MapBin("mapbin"))),
                    Exp.Val(2)));

            RecordSet rs = client.Query(policy, stmt);

            try
            {
                int count = 0;

                while (rs.Next())
                {
                    //Console.WriteLine(rs.Record.ToString());
                    count++;
                }
                Assert.AreEqual(1, count);
            }
            finally
            {
                rs.Close();
            }
        }
Ejemplo n.º 2
0
        public void ModifyWithContext()
        {
            IList <Value> listSubA = new List <Value>();

            listSubA.Add(Value.Get("e"));
            listSubA.Add(Value.Get("d"));
            listSubA.Add(Value.Get("c"));
            listSubA.Add(Value.Get("b"));
            listSubA.Add(Value.Get("a"));

            IList <Value> listA = new List <Value>();

            listA.Add(Value.Get("a"));
            listA.Add(Value.Get("b"));
            listA.Add(Value.Get("c"));
            listA.Add(Value.Get("d"));
            listA.Add(Value.Get(listSubA));

            IList <Value> listB = new List <Value>();

            listB.Add(Value.Get("x"));
            listB.Add(Value.Get("y"));
            listB.Add(Value.Get("z"));

            client.Operate(null, keyA,
                           ListOperation.AppendItems(ListPolicy.Default, binA, (IList)listA),
                           ListOperation.AppendItems(ListPolicy.Default, binB, (IList)listB),
                           Operation.Put(new Bin(binC, "M"))
                           );

            CTX    ctx = CTX.ListIndex(4);
            Record record;
            IList  result;

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    ListExp.Size(
                        // Temporarily Append binB/binC to binA in expression.
                        ListExp.AppendItems(ListPolicy.Default, Exp.ListBin(binB),
                                            ListExp.Append(ListPolicy.Default, Exp.StringBin(binC), Exp.ListBin(binA), ctx),
                                            ctx),
                        ctx),
                    Exp.Val(9)));

            record = client.Get(policy, keyA, binA);
            AssertRecordFound(keyA, record);

            result = record.GetList(binA);
            Assert.AreEqual(5, result.Count);

            policy.filterExp = Exp.Build(
                Exp.EQ(
                    ListExp.Size(
                        // Temporarily Append local listB and local "M" string to binA in expression.
                        ListExp.AppendItems(ListPolicy.Default, Exp.Val((IList)listB),
                                            ListExp.Append(ListPolicy.Default, Exp.Val("M"), Exp.ListBin(binA), ctx),
                                            ctx),
                        ctx),
                    Exp.Val(9)));

            record = client.Get(policy, keyA, binA);
            AssertRecordFound(keyA, record);

            result = record.GetList(binA);
            Assert.AreEqual(5, result.Count);
        }