Example #1
0
        // We peek at the table expression to compute the set of columns of the join
        static SQuery _Join(ReaderBase f)
        {
            f.GetInt();
            var st       = f.buf.pos;
            var d        = SDict <int, (long, string)> .Empty;
            var c        = SDict <int, Serialisable> .Empty;
            var nms      = SDict <string, long> .Empty;
            var left     = f._Get() as SQuery ?? throw new StrongException("Query expected");
            var outer    = f.GetInt() == 1;
            var joinType = (JoinType)f.GetInt();
            var right    = f._Get() as SQuery ?? throw new StrongException("Query expected");
            var ab       = left.Display.First();
            var uses     = SDict <long, long> .Empty;

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

            for (var lb = left.cpos.First(); ab != null && lb != null; ab = ab.Next(), lb = lb.Next())
            {
                var col = lb.Value;
                var u   = ab.Value.Item2;
                d   += (k, u);
                c   += (k, col.Item2);
                nms += (u.Item2, u.Item1);
                k++;
            }
            ab = right.Display.First();
            for (var rb = right.cpos.First(); ab != null && rb != null; ab = ab.Next(), rb = rb.Next())
            {
                var u = ab.Value.Item2;
                var n = u.Item2;
                if (joinType == JoinType.Natural && nms.Contains(n))
                {
                    continue;
                }
                if (uses.Contains(u.Item1))
                {
                    continue;
                }
                var col = rb.Value;
                d += (k, u);
                c += (k, col.Item2);
                k++;
            }
            f.buf.pos = st;
            return(new SQuery(Types.STableExp, d, c));
        }
        internal SDbObject SName(string s)
        {
            long uid;

            if (names.Contains(s))
            {
                uid = names[s];
            }
            else
            {
                uid    = --_uid;
                names += (s, uid);
                uids  += (uid, s);
            }
            return(new SDbObject(Types.SName, uid));
        }
Example #3
0
        static void Show(StrongConnect c, DocArray da)
        {
            List <Column>       cols  = new List <Column>();                                         // of Column
            SDict <string, int> names = SDict <string, int> .Empty;
            SDict <int, SDict <string, string> > rows = SDict <int, SDict <string, string> > .Empty; // of string[]

            for (var b = c.description.First(); b != null; b = b.Next())
            {
                names = names + (b.Value.Item2, b.Value.Item1);
                cols.Add(new Column(b.Value.Item2, b.Value.Item2.Length));
            }
            for (int i = 0; i < da.items.Count; i++)
            {
                var dc  = da[i];
                var row = SDict <string, string> .Empty;
                for (var j = 0; j < dc.fields.Count; j++)
                {
                    var f = dc.fields[j];
                    if (f.Key.StartsWith("_"))
                    {
                        continue;
                    }
                    if (!names.Contains(f.Key))
                    {
                        throw new Exception("Unexpected column " + f.Key);
                    }
                    var k = names.Lookup(f.Key);
                    var s = f.Value.ToString();
                    if (s.Length > cols[k].width)
                    {
                        cols[k].width = s.Length;
                    }
                    row = row + (f.Key, s);
                }
                rows = rows + (rows.Length.Value, row);
            }
            DrawLine(cols);
            ShowHeads(cols);
            DrawLine(cols);
            for (var j = 0; j < rows.Length.Value; j++)
            {
                ShowRow(rows.Lookup(j), cols);
            }
            DrawLine(cols);
        }