示例#1
0
 public void SelectMany_Array(int n)
 {
     using (var tbl = new TestTable("create table t (x int)"))
         using (var insert = tbl.Stmt <int>("insert into t values (@x)"))
             using (var select = tbl.RStmt <int>("select x from t"))
             {
                 int expectedSum = 0;
                 for (int i = 0; i < n; i++)
                 {
                     insert.Bind(i).Execute();
                     expectedSum += i;
                 }
                 int   j      = 0;
                 int[] values = new int[n];
                 foreach (Row <int> row in select.Execute())
                 {
                     row.AssignTo(out values[j++]);
                 }
                 Assert.Equal(expectedSum, Enumerable.Sum(values));
             }
 }
示例#2
0
        public void SelectMany()
        {
            P <int> p = default;
            R <int> r = default;

            using (var tbl = new TestTable("create table t (x int)"))
                using (var insert = tbl.Stmt("insert into t values(@x)", p.C))
                    using (var select = tbl.Stmt("select x from t", r.C))
                    {
                        p.Value = 1;
                        insert.Bind(p).Execute();
                        p.Value = 2;
                        insert.Bind(p).Execute();
                        int sum = 0;
                        foreach (var row in select.Execute())
                        {
                            row.AssignTo(out r);
                            sum += r.Value;
                        }
                        Assert.Equal(3, sum);
                    }
        }
示例#3
0
 public void SelectMany_IEnumerable(int n)
 {
     using (var tbl = new TestTable("create table t (x int)"))
         using (var insert = tbl.Stmt <int>("insert into t values (@x)"))
             using (var select = tbl.RStmt <int>("select x from t"))
             {
                 int expectedSum = 0;
                 for (int i = 0; i < n; i++)
                 {
                     insert.Bind(i).Execute();
                     expectedSum += i;
                 }
                 System.Collections.IEnumerable rows = select.Execute();
                 int sum = 0;
                 foreach (object?obj in rows)
                 {
                     ((Row <int>)obj !).AssignTo(out int x);
                     sum += x;
                 }
                 Assert.Equal(expectedSum, sum);
             }
 }
示例#4
0
        public void Enumerate_Reexecute()
        {
            P <int> p = default;
            R <int> r = default;

            using (var tbl = new TestTable("create table t (x int)"))
                using (var insert = tbl.Stmt("insert into t values(@x)", p.C))
                    using (var select = tbl.Stmt("select sum(x) from t", r.C))
                    {
                        p.Value = 1;
                        insert.Bind(p).Execute();
                        p.Value = 2;
                        insert.Bind(p).Execute();
                        using (var enumerator = select.Execute().GetEnumerator())
                        {
                            Assert.True(enumerator.MoveNext());
                            enumerator.Current.AssignTo(out r);
                            Assert.Equal(3, r.Value);
                        }
                        r = default;
                        select.Execute(out r);
                        Assert.Equal(3, r.Value);
                    }
        }