public static IEnumerable <BTreeCellData> WalkTableBTree(BTreePage node)
        {
            if (node is BTreeInteriorTablePage asInterior)
            {
                return(WalkTableBTree(asInterior));
            }

            if (node is BTreeLeafTablePage asLeaf)
            {
                return(WalkTableBTree(asLeaf));
            }

            throw new ArgumentException("Did not receive a compatible BTreePage", nameof(node));
        }
Exemplo n.º 2
0
        private void InitializeMasterTable()
        {
            // Parse table on Page 1, the sqlite_master table
            BTreePage rootBtree = BTreePage.Parse(_reader, 1);

            // Fake the schema for the sqlite_master table
            Sqlite3SchemaRow schemaRow = new Sqlite3SchemaRow
            {
                Database  = this,
                Type      = "table",
                Name      = "sqlite_master",
                TableName = "sqlite_master",
                RootPage  = rootBtree.Page,
                Sql       = "CREATE TABLE sqlite_master (type TEXT, name TEXT, tbl_name TEXT, rootpage INTEGER, sql TEXT);"
            };

            Sqlite3Table table = new Sqlite3Table(_reader, rootBtree, schemaRow);

            _masterTable = new Sqlite3MasterTable(this, table);
        }
Exemplo n.º 3
0
        public bool TryGetTable(string name, out Sqlite3Table table)
        {
            IEnumerable <Sqlite3SchemaRow> tables = GetTables();

            foreach (Sqlite3SchemaRow tbl in tables)
            {
                if (tbl.TableName != name || tbl.Type != "table")
                {
                    continue;
                }

                // Found it
                BTreePage root = BTreePage.Parse(_reader, tbl.RootPage);

                table = new Sqlite3Table(_reader, root, tbl);
                return(true);
            }

            table = null;
            return(false);
        }
        private static IEnumerable <BTreeCellData> WalkTableBTree(BTreeInteriorTablePage interior)
        {
            // Walk sub-pages and yield their data
            foreach (BTreeInteriorTablePage.Cell cell in interior.Cells)
            {
                BTreePage subPage = BTreePage.Parse(interior.Reader, cell.LeftPagePointer);

                foreach (BTreeCellData data in WalkTableBTree(subPage))
                {
                    yield return(data);
                }
            }

            if (interior.Header.RightMostPointer > 0)
            {
                // Process sibling page
                BTreePage subPage = BTreePage.Parse(interior.Reader, interior.Header.RightMostPointer);

                foreach (BTreeCellData data in WalkTableBTree(subPage))
                {
                    yield return(data);
                }
            }
        }
 internal Sqlite3Table(ReaderBase reader, BTreePage rootPage, Sqlite3SchemaRow table)
 {
     SchemaDefinition = table;
     _reader          = reader;
     RootPage         = rootPage;
 }