MTreeBookmark(SDictBookmark <Variant, Variant> outer, SList <TreeInfo <K> > info,
               bool changed, MTreeBookmark <K>?inner, Bookmark <ValueTuple <long, bool> >?pmk,
               int pos, SCList <Variant>?key = null) : base(pos)
 {
     _outer = outer; _info = info; _changed = changed;
     _inner = inner; _pmk = pmk; _filter = key ?? SCList <Variant> .Empty;
 }
Exemplo n.º 2
0
 /// <summary>
 /// A primary or unique index
 /// </summary>
 /// <param name="t"></param>
 /// <param name="c"></param>
 public SIndex(STransaction tr, long t, bool p, SList <long> c) : base(Types.SIndex, tr)
 {
     table   = t;
     primary = p;
     cols    = c;
     rows    = new SMTree(Info((STable)tr.objects.Lookup(table), cols));
 }
 public SGroupQuery(SQuery s, SDict <int, string> d, SDict <int, Serialisable> c,
                    Context cx, SDict <int, string> g, SList <Serialisable> h)
     : base(Types.SGroupQuery, d, c, cx)
 {
     source  = s;
     groupby = g;
     having  = h;
 }
Exemplo n.º 4
0
 SList <TreeInfo> Info(STable tb, SList <long> cols)
 {
     if (cols == null)
     {
         return(SList <TreeInfo> .Empty);
     }
     return(Info(tb, cols.next).InsertAt(new TreeInfo(tb.cols.Lookup(cols.element).name, 'D', 'D'), 0));
 }
Exemplo n.º 5
0
        public static SList <T> New(params T[] els)
        {
            var r = Empty;

            for (var i = els.Length - 1; i >= 0; i--)
            {
                r = new SList <T>(els[i], r);
            }
            return(r);
        }
 public bool Matches(SList <SExpression> wh, Context cx)
 {
     cx = new Context(this, cx);
     for (var b = wh.First(); b != null; b = b.Next())
     {
         if (b.Value.Lookup(cx) != SBoolean.True)
         {
             return(false);
         }
     }
     return(true);
 }
        public SSearch(SDatabase db, Reader f) : base(Types.SSearch, f)
        {
            sce = f._Get(db) as SQuery ?? throw new Exception("Query expected");
            var w = SList <Serialisable> .Empty;
            var n = f.GetInt();

            for (var i = 0; i < n; i++)
            {
                w += (f._Get(db).Lookup(new Context(sce.names, null)), i);
            }
            where = w;
        }
Exemplo n.º 8
0
        SIndex(SDatabase d, AStream f) : base(Types.SIndex, f)
        {
            table = f.GetLong();
            var n = f.ReadByte();
            var c = new long[n];

            for (var i = 0; i < n; i++)
            {
                c[i] = f.GetInt();
            }
            cols = SList <long> .New(c);

            rows = new SMTree(Info((STable)d.objects.Lookup(table), cols));
        }
Exemplo n.º 9
0
        public SIndex(STransaction tr, SIndex x, AStream f) : base(x, f)
        {
            table = tr.Fix(x.table);
            long[] c = new long[x.cols.Length];
            var    i = 0;

            for (var b = x.cols.First(); b != null; b = b.Next())
            {
                c[i++] = tr.Fix(b.Value);
            }
            cols = SList <long> .New(c);

            rows = x.rows;
        }
Exemplo n.º 10
0
        public SMTree(SList <TreeInfo <K> > ti, SList <Variant> k, long v) : base(1)
        {
            _info = ti;
            var e  = ti.element;
            var ke = k.element;

            if (e.asc != (ke.variant == Variants.Ascending))
            {
                ke = new Variant(ke.ob, e.asc);
            }
            _impl = (ti.Length < 2) ?
                    ((e.onDuplicate == TreeBehaviour.Allow) ?
                     new SITree(e, Variants.Partial, ke,
                                new Variant(Variants.Partial, new SDict <long, bool>(v, true))) :
                     new SITree(e, e.asc?Variants.Ascending:Variants.Descending, ke, new Variant(v))) :
                    new SITree(e, Variants.Compound, ke,
                               new Variant(Variants.Compound, new SMTree <K>(ti.next, k.next, v))); //these are not null
        }
Exemplo n.º 11
0
        public SGroupQuery(SDatabase db, Reader f) : base(Types.SGroupQuery, f)
        {
            source = f._Get(db) as SQuery ?? throw new Exception("Query expected");
            var g = SDict <int, string> .Empty;
            var h = SList <Serialisable> .Empty;
            var n = f.GetInt();

            for (var i = 0; i < n; i++)
            {
                g += (i, f.GetString());
            }
            n = f.GetInt();
            for (var i = 0; i < n; i++)
            {
                h += (f._Get(db).Lookup(new Context(source.names, null)), i);
            }
            groupby = g;
            having  = h;
        }
Exemplo n.º 12
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            var       them = (SList <K>)obj;
            SList <K> me   = this;

            for (; me.Length > 0 && them.Length > 0; me = me.next, them = them.next) // not null
            {
                var c = me.element.CompareTo(them.element);
                if (c != 0)
                {
                    return(c);
                }
            }
            return((me.Length > 0) ? 1 : (them.Length > 0) ? -1 : 0);
        }
Exemplo n.º 13
0
        public OrderedRowSet(RowSet sce, SList <TreeInfo <Serialisable> > ti, Context cx)
            : base(sce._tr, sce._qry, sce._aggregates, null)
        {
            _sce = sce;
            var t = new SMTree <Serialisable>(ti);
            var r = SDict <int, SRow> .Empty;
            int m = 0;

            for (var b = sce.First() as RowBookmark; b != null; b = b.Next() as RowBookmark)
            {
                var k = new Variant[ti.Length.Value];
                var i = 0;
                for (var c = ti.First(); c != null; c = c.Next())
                {
                    k[i] = new Variant(c.Value.headName.Lookup(new Context(b, cx)));
                }
                t  = t.Add(m, k);
                r += (m++, b._ob);
            }
            _tree = t;
            _rows = r;
        }
Exemplo n.º 14
0
        public SJoin(SDatabase db, Reader f) : base(Types.STableExp, _Join(db, f))
        {
            left     = f._Get(db) as SQuery ?? throw new Exception("Query expected");
            outer    = f.GetInt() == 1;
            joinType = (JoinType)f.GetInt();
            right    = f._Get(db) as SQuery ?? throw new Exception("Query expected");
            var n  = f.GetInt();
            var on = SList <SExpression> .Empty;
            var us = SList <string> .Empty;

            if (joinType.HasFlag(JoinType.Natural))
            {
                for (var lb = left.names.First(); lb != null; lb = lb.Next())
                {
                    if (right.names.Contains(lb.Value.Item1))
                    {
                        us += lb.Value.Item1;
                    }
                }
            }
            else if (joinType.HasFlag(JoinType.Named))
            {
                for (var i = 0; i < n; i++)
                {
                    us += f.GetString();
                }
            }
            else if (!joinType.HasFlag(JoinType.Cross))
            {
                for (var i = 0; i < n; i++)
                {
                    var e = f._Get(db) as SExpression
                            ?? throw new Exception("ON exp expected");
                    on += e;
                }
            }
            ons  = on;
            uses = us;
        }
Exemplo n.º 15
0
 public SSearch(SQuery s, SList <Serialisable> w)
     : base(Types.SSearch, s.display, s.cpos, new Context(s.names, null))
 {
     sce   = s;
     where = w;
 }
Exemplo n.º 16
0
 public SMTree(SList <TreeInfo <K> > ti) : base(0)
 {
     _info = ti;
     _impl = null;
 }
Exemplo n.º 17
0
 public SJoin(SQuery lf, bool ou, JoinType jt, SQuery rg, SList <SExpression> on,
              SList <string> us, SDict <int, string> d, SDict <int, Serialisable> c, Context cx)
     : base(Types.STableExp, d, c, cx)
 {
     left = lf; right = rg; outer = ou; joinType = jt; ons = on; uses = us;
 }
Exemplo n.º 18
0
        static SQuery _Join(SDatabase db, Reader f)
        {
            f.GetInt();
            var st       = f.pos;
            var d        = SDict <int, string> .Empty;
            var c        = SDict <int, Serialisable> .Empty;
            var left     = f._Get(db) as SQuery ?? throw new Exception("Query expected");
            var outer    = f.GetInt() == 1;
            var joinType = (JoinType)f.GetInt();
            var right    = f._Get(db) as SQuery ?? throw new Exception("Query expected");
            var ab       = left.Display.First();
            var uses     = SDict <string, bool> .Empty;

            if (joinType.HasFlag(JoinType.Named))
            {
                var n = f.GetInt();
                for (var i = 0; i < n; i++)
                {
                    uses += (f.GetString(), true);
                }
            }
            var k = 0;

            for (var lb = left.cpos.First(); ab != null && lb != null; ab = ab.Next(), lb = lb.Next())
            {
                var col = lb.Value;
                var n   = ab.Value.Item2;
                if (right.names.Contains(n) &&
                    ((!joinType.HasFlag(JoinType.Natural)) || uses.Contains(n)))
                {
                    n = left.Alias + "." + n;
                }
                d += (k, n);
                c += (k, col.Item2);
                k++;
            }
            ab = right.Display.First();
            for (var rb = right.cpos.First(); ab != null && rb != null; ab = ab.Next(), rb = rb.Next())
            {
                if (joinType == JoinType.Natural && left.names.Contains(ab.Value.Item2))
                {
                    continue;
                }
                if (uses.Contains(ab.Value.Item2))
                {
                    continue;
                }
                var col = rb.Value;
                var n   = ab.Value.Item2;
                if (left.names.Contains(n) &&
                    ((!joinType.HasFlag(JoinType.Natural)) || uses.Contains(n)))
                {
                    n = right.Alias + "." + n;
                }
                d += (k, n);
                c += (k, col.Item2);
                k++;
            }
            f.pos = st;
            return(new SQuery(Types.STableExp, d, c, Context.Empty));
        }
Exemplo n.º 19
0
 SMTree(SList <TreeInfo <K> > ti, SITree?impl, int c) : base(c)
 {
     _info = ti;
     _impl = impl;
 }
Exemplo n.º 20
0
 public SSelectStatement(bool d, SDict <int, string> a, SDict <int, Serialisable> c,
                         SQuery q, SList <SOrder> or, Context cx)
     : base(Types.SSelect, a, c, new Context(q.names, cx))
 {
     distinct = d;  qry = q; order = or;
 }
Exemplo n.º 21
0
 internal SIndex(SIndex x, long t, SList <long> c) : base(x)
 {
     table   = t; cols = c;
     primary = x.primary;
     rows    = x.rows;
 }
Exemplo n.º 22
0
 internal SList(T e, SList <T> n) : base(n.Length + 1)
 {
     element = e;
     next    = n;
 }
Exemplo n.º 23
0
 protected SList() : base(0)
 {
     element = default(T); next = null;
 }                                                                // allow this one
Exemplo n.º 24
0
 internal SListBookmark(SList <T> s, int p = 0) : base(p)
 {
     _s = s;
 }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            // Tests for SList (unordered list)
            var sl = SList <string> .New("Red", "Blue", "Green");

            sl = sl.InsertAt("Yellow", 0);
            var s2 = sl;

            sl = sl.RemoveAt(3);
            sl = sl.UpdateAt("Pink", 1);
            sl = sl.InsertAt("Orange", 2);
            Check <string>(sl.ToArray(), "Yellow", "Pink", "Orange", "Blue");
            Check <string>(s2.ToArray(), "Yellow", "Red", "Blue", "Green");
            Console.WriteLine("SList done");
            // Tests for SArray
            var sa = new SArray <string>("Red", "Blue", "Green");

            sa = sa.InsertAt(0, "Yellow");
            sa = sa.RemoveAt(3);
            var sb = sa;

            sa = sa.InsertAt(2, "Orange", "Violet");
            Check(sa.ToArray(), "Yellow", "Red", "Orange", "Violet", "Blue");
            Check(sb.ToArray(), "Yellow", "Red", "Blue");
            Console.WriteLine("SArray done");
            // Tests for SSearchTree<string>
            var ss = SSearchTree <string> .New("InfraRed", "Red", "Orange", "Yellow", "Green", "Blue", "Violet");

            Check(ss.ToArray(), "Blue", "Green", "InfraRed", "Orange", "Red", "Violet", "Yellow");
            var si = SSearchTree <int> .New(56, 22, 24, 31, 23);

            Check(si.ToArray(), 22, 23, 24, 31, 56);
            Console.WriteLine("SSearchTree done");
            // Tests for SDict
            var sd = SDict <string, string> .Empty;

            sd = sd.Add("Y", "Yellow");
            sd = sd.Add("G", "Green");
            sd = sd.Add("B", "Blue");
            sd = sd.Remove("G");
            var sr = new string[sd.Count];
            var j  = 0;

            for (var b = sd.First(); b != null; b = b.Next())
            {
                sr[j++] = b.Value.key + ": " + b.Value.val;
            }
            Check(sr, "B: Blue", "Y: Yellow");
            Console.WriteLine("SDict done");
            // Tests for SMTree
            var ti = SList <TreeInfo> .Empty;

            ti = ti.InsertAt(new TreeInfo("0", 'D', 'D'), 0); // onDuplicate must be Disallow on all except last entry
            ti = ti.InsertAt(new TreeInfo("1", 'A', 'A'), 1);
            var sm   = new SMTree(ti);
            var test = new string[] { "BALTIM", "ANNU", "A", "ANNO", "BALTIC", "BRAIL" };

            for (var i = 0; i < test.Length; i++)
            {
                sm = Add(sm, test[i], i);
            }
            var sorted = new string[test.Length];

            j = 0;
            for (var b = sm.First(); b != null; b = b.Next())
            {
                sorted[j++] = test[((MTreeBookmark)b).value()];
            }
            // we are only sorting on the first two letters!
            // Check() we should offer some alternatives here
            Check(sorted, "A", "ANNU", "ANNO", "BALTIM", "BALTIC", "BRAIL");
            Console.WriteLine("SMTree done");
            File.Delete("strong");
            File.Create("strong").Close();
            var d  = SDatabase.Open("strong");
            var tr = new STransaction(d);

            tr = new STransaction(tr, new SString("This is Strong"));
            new STable(tr, "tbl");
            var c = tr.Commit();

            d.Close();
            d = SDatabase.Open("strong");
            Console.WriteLine(d.objects.First().Value.val.ToString());
            Console.ReadKey();
        }
Exemplo n.º 26
0
 public IndexRowSet(STransaction tr, STable t, SIndex ix, SCList <Variant> key, SList <Serialisable> wh)
     : base(Rdc(tr, ix, key), t, SDict <long, SFunction> .Empty, t.rows.Length)
 {
     _ix     = ix; _key = key; _wh = wh;
     _unique = key.Length == _ix.cols.Length;
 }