Beispiel #1
0
        public static bool RowSet_Next(RowSet p, ref long rowid)
        {
            Debug.Assert(p != null);

            // Merge the forest into a single sorted list on first call
            if ((p.Flags & ROWSET.NEXT) == 0)
            {
                RowSetToList(p);
            }

            // Return the next entry on the list
            if (p.Entry != null)
            {
                rowid   = p.Entry.V;
                p.Entry = p.Entry.Right;
                if (p.Entry == null)
                {
                    RowSet_Clear(p);
                }
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public static RowSet RowSet_Init(Context ctx, object space, uint n)
        {
            RowSet p = new RowSet(ctx, (int)n);

            return(p);
        }
Beispiel #3
0
        public static bool RowSet_Test(RowSet rowSet, byte batch, long rowid)
        {
            // This routine is never called after sqlite3RowSetNext()
            Debug.Assert(rowSet != null && (rowSet.Flags & ROWSET.NEXT) == 0);

            // Sort entries into the forest on the first test of a new batch
            RowSetEntry p, tree;

            if (batch != rowSet.Batch)
            {
                p = rowSet.Entry;
                if (p != null)
                {
                    RowSetEntry prevTree = rowSet.Forest;
                    if ((rowSet.Flags & ROWSET.SORTED) == 0)
                    {
                        p = RowSetEntrySort(p);
                    }
                    for (tree = rowSet.Forest; tree != null; tree = tree.Right)
                    {
                        prevTree = tree.Right;
                        if (tree.Left == null)
                        {
                            tree.Left = RowSetListToTree(p);
                            break;
                        }
                        else
                        {
                            RowSetEntry aux = new RowSetEntry(), tail = new RowSetEntry();
                            RowSetTreeToList(tree.Left, ref aux, ref tail);
                            tree.Left = null;
                            p         = RowSetEntryMerge(aux, p);
                        }
                    }
                    if (tree == null)
                    {
                        prevTree = tree = RowSetEntryAlloc(rowSet);
                        if (tree != null)
                        {
                            tree.V     = 0;
                            tree.Right = null;
                            tree.Left  = RowSetListToTree(p);
                        }
                    }
                    rowSet.Entry  = null;
                    rowSet.Last   = null;
                    rowSet.Flags |= ROWSET.SORTED;
                }
                rowSet.Batch = batch;
            }

            // Test to see if the iRowid value appears anywhere in the forest. Return 1 if it does and 0 if not.
            for (tree = rowSet.Forest; tree != null; tree = tree.Right)
            {
                p = tree.Left;
                while (p != null)
                {
                    if (p.V < rowid)
                    {
                        p = p.Right;
                    }
                    else if (p.V > rowid)
                    {
                        p = p.Left;
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }