public void Copy()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            var ope = new UoeDatabaseOperator(dlcPath);

            var stPath = Path.Combine(TestFolder, "copysource.st");

            File.WriteAllText(stPath, $"b .\nd \"Schema Area\" \"{TestFolder}\"");

            var srcDb = GetDb("copysource");
            var tgtDb = GetDb("copytarget");

            ope.Create(srcDb, stPath);
            Assert.IsTrue(srcDb.Exists());

            ope.Copy(tgtDb, srcDb, false, false);
            Assert.IsTrue(tgtDb.Exists());

            ope.Delete(tgtDb);
            Assert.IsFalse(tgtDb.Exists());

            ope.Copy(tgtDb, srcDb);
            Assert.IsTrue(tgtDb.Exists());
        }
Ejemplo n.º 2
0
        public void LoadSchemaDefinition()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            var ope    = new UoeDatabaseOperator(dlcPath);
            var db     = GetDb("loaddf");
            var dfPath = Path.Combine(TestFolder, $"{db.PhysicalName}.df");

            ope.Create(db);
            Assert.IsTrue(db.Exists());

            // create .df
            File.WriteAllText(dfPath, "ADD SEQUENCE \"sequence1\"\n  INITIAL 0\n  INCREMENT 1\n  CYCLE-ON-LIMIT no\n\nADD TABLE \"table1\"\n  AREA \"Schema Area\"\n  DESCRIPTION \"table one\"\n  DUMP-NAME \"table1\"\n\nADD FIELD \"field1\" OF \"table1\" AS character \n  DESCRIPTION \"field one\"\n  FORMAT \"x(8)\"\n  INITIAL \"\"\n  POSITION 2\n  MAX-WIDTH 16\n  ORDER 10\n\nADD INDEX \"idx_1\" ON \"table1\" \n  AREA \"Schema Area\"\n  PRIMARY\n  INDEX-FIELD \"field1\" ASCENDING\n");

            using (var dataAdmin = new UoeDatabaseAdministrator(dlcPath)) {
                dataAdmin.LoadSchemaDefinition(UoeDatabaseConnection.NewSingleUserConnection(db), dfPath);
            }

            ope.Delete(db);
            ope.Create(db);

            // create .df
            File.WriteAllText(dfPath, "ADD FIELD \"field1\" OF \"table1\" AS character \n  DESCRIPTION \"field one\"\n  FORMAT \"x(8)\"\n  INITIAL \"\"\n  POSITION 2\n  MAX-WIDTH 16\n  ORDER 10\n");

            using (var dataAdmin = new UoeDatabaseAdministrator(dlcPath)) {
                Assert.ThrowsException <UoeDatabaseException>(() => dataAdmin.LoadSchemaDefinition(UoeDatabaseConnection.NewSingleUserConnection(db), dfPath));
            }
        }
        public void Create()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            var ope = new UoeDatabaseOperator(dlcPath);
            var db  = GetDb("test1.db");

            ope.Create(db);

            Assert.IsTrue(db.Exists());

            ope.Delete(db);

            Assert.IsFalse(db.Exists());

            var stPath = Path.Combine(TestFolder, "test1.st");

            File.WriteAllText(stPath, "b .\nd \"Schema Area\" .\nd \"data\" .");

            ope.Create(db, stPath);

            Assert.IsTrue(db.Exists());
            Assert.IsTrue(File.Exists(Path.Combine(TestFolder, "test1_7.d1")));

            ope.Delete(db);

            Assert.IsFalse(db.Exists());

            File.WriteAllText(stPath, "b .\nd \"Schema Area\" ./sub\nd \"data\" ./data");

            ope.Create(db, stPath, DatabaseBlockSize.S4096, "utf", false, false);

            Assert.IsTrue(db.Exists());

            Assert.IsTrue(File.Exists(Path.Combine(TestFolder, "sub", "test1.d1")));
            Assert.IsTrue(File.Exists(Path.Combine(TestFolder, "data", "test1_7.d1")));

            ope.Delete(db);

            Assert.IsFalse(File.Exists(Path.Combine(TestFolder, "sub", "test1.d1")));
            Assert.IsFalse(File.Exists(Path.Combine(TestFolder, "data", "test1_7.d1")));
        }
        public void Backup_Restore()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }
            var ope = new UoeDatabaseOperator(dlcPath);
            var db  = GetDb("backuprest");

            ope.Copy(db, new UoeDatabaseLocation(Path.Combine(dlcPath, "sports2000")));
            Assert.IsTrue(db.Exists());

            var backupPath = Path.Combine(TestFolder, "backup.bkp");

            ope.Backup(db, backupPath);

            ope.Delete(db);
            Assert.IsFalse(db.Exists());

            ope.Restore(db, backupPath);
            Assert.IsTrue(db.Exists());
        }
        public void Delete()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            var db = new UoeDatabaseOperator(dlcPath);

            var deleteDir = Path.Combine(TestFolder, "delete");

            Directory.CreateDirectory(deleteDir);

            var stPath = Path.Combine(deleteDir, "test1.st");

            File.WriteAllText(stPath, @"
b .
d ""Schema Area"":6,32;1 .
d ""Data Area"":7,32;1 .
d ""Index Area"":8,32;8 .
d ""Data Area2"":9,32;8 .
d ""Data Area3"":12,32;8 .
");
            var loc = new UoeDatabaseLocation(Path.Combine(deleteDir, "test1.db"));

            db.Create(loc, stPath);

            Assert.AreEqual(9, Directory.EnumerateFiles(deleteDir, "*", SearchOption.TopDirectoryOnly).Count());

            File.Delete(stPath);

            db.Delete(loc);

            Assert.AreEqual(1, Directory.EnumerateFiles(deleteDir, "*", SearchOption.TopDirectoryOnly).Count(), "only the .st should be left (it has been recreated to list files to delete).");

            File.WriteAllText(stPath, @"
b ./2
a ./3 f 1024
a ./3 f 1024
a !""./3"" f 1024
t . f 4096
d ""Employee"",32 ./1/emp f 1024
d ""Employee"",32 ./1/emp
d ""Inventory"",32 ./1/inv f 1024
d ""Inventory"",32 ./1/inv
d ""Cust_Data"",32;64 ./1/cust f 1024
d ""Cust_Data"",32;64 ./1/cust
d ""Cust_Index"",32;8 ./1/cust
d ""Order"",32;64 ./1/ord f 1024
d ""Order"",32;64 ./1/ord
d ""Misc"",32 !""./1/misc data"" f 1024
d ""Misc"",32 !""./1/misc data""
d ""schema Area"" .
");

            db.CreateVoidDatabase(loc, stPath);

            Assert.AreEqual(20, Directory.EnumerateFiles(deleteDir, "*", SearchOption.AllDirectories).Count());

            db.Delete(loc);

            Assert.AreEqual(1, Directory.EnumerateFiles(deleteDir, "*", SearchOption.AllDirectories).Count());
        }