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

            // create .df
            var dfPath = Path.Combine(TestFolder, "bindb.df");

            File.WriteAllText(dfPath, "ADD 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 FIELD \"field2\" OF \"table1\" AS integer \n  DESCRIPTION \"field two\"\n  FORMAT \"9\"\n  INITIAL 0\n  POSITION 3\n  ORDER 20\n");

            using (var dataAdmin = new UoeDatabaseAdministrator(dlcPath)) {
                var db = GetDb("dumploadbin");
                dataAdmin.CreateWithDf(db, dfPath);

                var dataDirectory = Path.Combine(TestFolder, "bindb_data");
                Directory.CreateDirectory(dataDirectory);
                try {
                    var table1Path = Path.Combine(dataDirectory, "table1.d");
                    // load data from .d
                    File.WriteAllText(table1Path, "\"value1\" 1\n\"value2\" 2\n");
                    dataAdmin.LoadData(dataAdmin.GetDatabaseConnection(db), dataDirectory);
                    File.Delete(table1Path);

                    // dump binary
                    dataAdmin.DumpBinaryData(db, "table1", dataDirectory);
                    var binDataFilePath = Path.Combine(dataDirectory, "table1.bd");
                    Assert.IsTrue(File.Exists(binDataFilePath));

                    // recreate db
                    dataAdmin.Delete(db);
                    dataAdmin.CreateWithDf(db, dfPath);

                    // load binary
                    dataAdmin.LoadBinaryData(db, binDataFilePath);

                    // re-rebuild index
                    dataAdmin.RebuildIndexes(db, new UoeProcessArgs().Append("table", "table1") as UoeProcessArgs);

                    // dump data .d
                    dataAdmin.DumpData(dataAdmin.GetDatabaseConnection(db), dataDirectory, "table1");
                    Assert.IsTrue(File.Exists(table1Path));
                    var dataContent = File.ReadAllText(table1Path);
                    Assert.IsTrue(dataContent.Contains("\"value1\" 1"));

                    // truncate table
                    dataAdmin.TruncateTableData(dataAdmin.GetDatabaseConnection(db), "table1");

                    // dump empty data .d
                    dataAdmin.DumpData(dataAdmin.GetDatabaseConnection(db), dataDirectory, "table1");
                    Assert.IsFalse(File.ReadAllText(table1Path).Contains("\"value1\" 1"));
                } finally {
                    Directory.Delete(dataDirectory, true);
                }
            }
        }
Esempio n. 2
0
        public void Data()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            var db = GetDb("datad");

            // create .df
            var dfPath = Path.Combine(TestFolder, "data.df");

            File.WriteAllText(dfPath, "ADD 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 FIELD \"field2\" OF \"table1\" AS integer \n  DESCRIPTION \"field two\"\n  FORMAT \"9\"\n  INITIAL 0\n  POSITION 3\n  ORDER 20\n");

            using (var dataAdmin = new UoeDatabaseAdministrator(dlcPath)) {
                dataAdmin.CreateWithDf(db, dfPath);

                var dataDirectory = Path.Combine(TestFolder, "data");
                Directory.CreateDirectory(dataDirectory);
                try {
                    var table1Path = Path.Combine(dataDirectory, "table1.d");
                    // load data
                    File.WriteAllText(table1Path, "\"value1\" 1\n\"value2\" 2\n");
                    dataAdmin.LoadData(dataAdmin.GetDatabaseConnection(db), dataDirectory);

                    // dump seq
                    File.Delete(table1Path);
                    dataAdmin.DumpData(dataAdmin.GetDatabaseConnection(db), dataDirectory);

                    Assert.IsTrue(File.Exists(table1Path));
                    var dataContent = File.ReadAllText(table1Path);
                    Assert.IsTrue(dataContent.Contains("\"value1\" 1"));
                    Assert.IsTrue(dataContent.Contains("\"value2\" 2"));
                } finally {
                    Directory.Delete(dataDirectory, true);
                }
            }
        }