Example #1
0
        //--- persistence Mk II

        // Store the persistent catalog and modified tables, local only
        // note: for Sql, only used to create new empty catalog
        public void StoreToTable()
        {
            Logger.WriteLine(2, "Save catalog for '{0}'", DatabaseName);
            var ctm   = CatalogTableMaker.Create(_catalogtableheading);
            var table = ctm.AddEntries(PersistentVars.GetEntries()).Table;

            if (SqlFlag)
            {
                DataTableSql.Create(CatalogTableName, table);
            }
            else
            {
                Persist.Create(DatabasePath, true).Store(CatalogTableName, RelationValue.Create(table));
                var savers = PersistentVars.GetEntries().Where(e => e.IsUnsaved);
                Logger.WriteLine(2, $"Persist {savers.Count()} entries");
                foreach (var entry in savers)
                {
                    Persist.Create(DatabasePath, true).Store(entry.Name, entry.Value);
                }
            }
        }
Example #2
0
        // Get the value of a relation from a database
        // Entry previously created by peeking
        public bool LinkRelvar(string name)
        {
            var entry = GlobalVars.FindEntry(name);

            Logger.Assert(entry != null && entry.IsDatabase);

            var heading = entry.DataType.Heading;

            if (SqlFlag)
            {
                var sqlheading = SqlTarget.Current.GetTableHeading(name);
                if (sqlheading == null)
                {
                    throw ProgramError.Fatal("Catalog", "sql table not found: '{0}'", name);
                }
                // TODO: smarter test, but still may not match exactly
                //if (!heading.Equals(sqlheading))
                if (heading.Degree != sqlheading.Degree)
                {
                    throw ProgramError.Fatal("Catalog", "sql table schema mismatch: '{0}'", name);
                }
                var table = DataTableSql.Create(name, heading);
                GlobalVars.SetValue(entry, RelationValue.Create(table));
            }
            else
            {
                var tablev = Persist.Create(DatabasePath, false).Load(name);
                if (tablev == null)
                {
                    throw ProgramError.Fatal("Catalog", "local table not found: '{0}'", name);
                }
                if (!heading.Equals(tablev.Heading))
                {
                    throw ProgramError.Fatal("Catalog", "local table schema mismatch: '{0}'", name);
                }
                GlobalVars.SetValue(entry, RelationValue.Create(tablev.AsTable()));
            }
            return(true);
        }