public void OeExecution_Test_DbConnection_fail()
        {
            if (!GetEnvExecution(out UoeExecutionEnv env))
            {
                return;
            }
            env.UseProgressCharacterMode = true;

            // try if connected well and can manage aliases
            env.DatabaseConnections = UoeDatabaseConnection.NewSingleUserConnection(new UoeDatabaseLocation(Path.Combine(TestFolder, "random.db"))).Yield();

            using (var exec = new UoeExecutionCustomTest(env)) {
                exec.NeedDatabaseConnection = true;
                exec.ExecuteNoWait();
                exec.WaitForExit();
                Assert.IsFalse(exec.ExecutionFailed, "failed");
                Assert.IsTrue(exec.ExecutionHandledExceptions, "ex");
                Assert.IsTrue(exec.DatabaseConnectionFailed, "no connection");
            }
            using (var exec = new UoeExecutionCustomTest(env)) {
                exec.NeedDatabaseConnection = false;
                exec.ExecuteNoWait();
                exec.WaitForExit();
                Assert.IsFalse(exec.ExecutionFailed, "failed2");
                Assert.IsTrue(exec.ExecutionHandledExceptions, "ex2");
                Assert.IsTrue(exec.DatabaseConnectionFailed, "no connection 2");
            }
            env.Dispose();
        }
Beispiel #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));
            }
        }
Beispiel #3
0
        public void DumpDf()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            var db     = GetDb("dumpdf");
            var dfPath = Path.Combine(TestFolder, $"{db.PhysicalName}.df");

            // 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.CreateWithDf(db, dfPath);

                var dfPathOut = Path.Combine(TestFolder, "dumpdf_out.df");
                dataAdmin.DumpSchemaDefinition(UoeDatabaseConnection.NewSingleUserConnection(db), dfPathOut);

                Assert.IsTrue(File.Exists(dfPathOut));
                Assert.IsTrue(File.ReadAllText(dfPathOut).Contains("field1"));

                var dumpOut = Path.Combine(TestFolder, "dump_custom.txt");
                dataAdmin.DumpCustomInfoExtraction(UoeDatabaseConnection.NewSingleUserConnection(db), dumpOut);

                Assert.IsTrue(File.Exists(dumpOut));
                Assert.IsTrue(File.ReadAllText(dumpOut).Contains("field1"));
            }
        }
        public void GetConnectionString_Multi_Single()
        {
            var cs = UoeDatabaseConnection.NewMultiUserConnection(new UoeDatabaseLocation("data")).ToString();

            Assert.IsTrue(!cs.Contains("-1") && !cs.Contains("-H"), $"Should have multi user connection string without hostname: {cs.PrettyQuote()}.");

            cs = UoeDatabaseConnection.NewSingleUserConnection(new UoeDatabaseLocation("data")).ToString();
            Assert.IsTrue(cs.Contains("-1") && cs.Contains("-db"), $"Should have single user connection string.");
        }
        public void OeExecutionDbExtractTableAndSequenceListTest_Dump_db()
        {
            if (!GetEnvExecution(out UoeExecutionEnv env))
            {
                return;
            }

            var base1Db = new UoeDatabaseLocation(Path.Combine(TestFolder, "base1.db"));
            var base2Db = new UoeDatabaseLocation(Path.Combine(TestFolder, "base2.db"));

            if (!base1Db.Exists())
            {
                var dfPath = Path.Combine(TestFolder, "base1.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");
                using (var dbAdministrator = new UoeDatabaseAdministrator(env.DlcDirectoryPath)) {
                    dbAdministrator.CreateWithDf(base1Db, dfPath);
                    dbAdministrator.CreateWithDf(base2Db, dfPath);
                }
            }

            env.DatabaseConnections = new [] { UoeDatabaseConnection.NewSingleUserConnection(base1Db), UoeDatabaseConnection.NewSingleUserConnection(base2Db) };
            env.DatabaseAliases     = new List <IUoeExecutionDatabaseAlias> {
                new UoeExecutionDatabaseAlias {
                    DatabaseLogicalName = "base1",
                    AliasLogicalName    = "alias1"
                }
            };

            using (var exec = new UoeExecutionDbExtractTableCrcAndSequenceList(env)) {
                exec.ExecuteNoWait();
                exec.WaitForExit();
                Assert.IsFalse(exec.ExecutionHandledExceptions, "ExecutionHandledExceptions");
                Assert.IsFalse(exec.DatabaseConnectionFailed, "DbConnectionFailed");

                Assert.AreEqual("base1.sequence1,alias1.sequence1,base2.sequence1", string.Join(",", exec.Sequences), "sequences");
                Assert.AreEqual("base1.table1,alias1.table1,base1._Sequence,alias1._Sequence,base2.table1,base2._Sequence", string.Join(",", exec.TablesCrc.Keys), "tables");
            }
            env.Dispose();
        }
Beispiel #6
0
        public void Execute()
        {
            if (!GetEnvExecution(out UoeExecutionEnv env))
            {
                return;
            }

            var base1Db = new UoeDatabaseLocation(Path.Combine(TestFolder, "base1.db"));
            var base2Db = new UoeDatabaseLocation(Path.Combine(TestFolder, "base2.db"));

            var beforeSchemaLoad = DateTime.Now;

            if (!base1Db.Exists())
            {
                var dfPath = Path.Combine(TestFolder, "base1.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");
                using (var dbAdministrator = new UoeDatabaseAdministrator(env.DlcDirectoryPath)) {
                    dbAdministrator.CreateWithDf(base1Db, dfPath);
                    dbAdministrator.CreateWithDf(base2Db, dfPath);
                }
            }

            var afterSchemaLoad = DateTime.Now;

            env.DatabaseConnections = new [] { UoeDatabaseConnection.NewSingleUserConnection(base1Db), UoeDatabaseConnection.NewSingleUserConnection(base2Db) };

            using (var exec = new UoeExecutionDbExtractLastSchemaUpdate(env)) {
                exec.ExecuteNoWait();
                exec.WaitForExit();
                Assert.IsFalse(exec.ExecutionHandledExceptions, "ExecutionHandledExceptions");
                Assert.IsFalse(exec.DatabaseConnectionFailed, "DbConnectionFailed");

                Assert.AreEqual(2, exec.LastSchemaUpdates.Count);
                Assert.IsTrue(beforeSchemaLoad.CompareTo(exec.LastSchemaUpdates["base1"]) < 0, $"{beforeSchemaLoad} > {exec.LastSchemaUpdates["base1"]}");
                Assert.IsTrue(afterSchemaLoad.CompareTo(exec.LastSchemaUpdates["base1"]) > 0, $"{exec.LastSchemaUpdates["base1"]} > {afterSchemaLoad}");
            }
            env.Dispose();
        }
Beispiel #7
0
        public void Execute()
        {
            if (!GetEnvExecution(out UoeExecutionEnv env))
            {
                return;
            }

            var base1Db = new UoeDatabaseLocation(Path.Combine(TestFolder, "base1.db"));

            if (!base1Db.Exists())
            {
                var dfPath = Path.Combine(TestFolder, "base1.df");
                File.WriteAllBytes(dfPath, Resources.Resources.GetBytesFromResource("Database.complete.df"));
                using (var dbAdministrator = new UoeDatabaseAdministrator(env.DlcDirectoryPath)) {
                    dbAdministrator.CreateWithDf(base1Db, dfPath);
                }
            }

            env.DatabaseConnections = new [] { UoeDatabaseConnection.NewSingleUserConnection(base1Db) };
            using (var exec = new UoeExecutionDbExtractDefinition(env)) {
                exec.ExecuteNoWait();
                exec.WaitForExit();
                Assert.IsFalse(exec.ExecutionHandledExceptions, exec.ExecutionHandledExceptions ? exec.HandledExceptions[0].ToString() : "ok");
                Assert.IsFalse(exec.DatabaseConnectionFailed, "DbConnectionFailed");
                var db = exec.GetDatabases()[0];

                Assert.AreEqual(DatabaseBlockSize.S4096, db.BlockSize);
                Assert.AreEqual("iso8859-1", db.Charset);
                Assert.AreEqual("basic", db.Collation);
                Assert.AreEqual("base1", db.LogicalName);
                Assert.AreEqual("base1", db.PhysicalName);
                Assert.AreEqual(2, db.Sequences.Count);
                Assert.AreEqual(true, db.Sequences[0].CycleOnLimit);
                Assert.AreEqual(2, db.Sequences[0].Increment);
                Assert.AreEqual(20, db.Sequences[0].Initial);
                Assert.AreEqual(200, db.Sequences[0].Max);
                Assert.AreEqual(null, db.Sequences[0].Min);
                Assert.AreEqual("theseq1", db.Sequences[0].Name);
                Assert.AreEqual(2, db.Tables.Count);
                Assert.AreEqual("Data Area", db.Tables[0].Area);
                Assert.AreEqual(5575, db.Tables[0].Crc);
                Assert.AreEqual("thedesc1", db.Tables[0].Description);
                Assert.AreEqual("thedump1", db.Tables[0].DumpName);
                Assert.AreEqual("theforeignname", db.Tables[0].Foreign);
                Assert.AreEqual(false, db.Tables[0].Frozen);
                Assert.AreEqual(false, db.Tables[0].Hidden);
                Assert.AreEqual("thelabel1", db.Tables[0].Label);
                Assert.AreEqual("T", db.Tables[0].LabelAttribute);
                Assert.AreEqual("thetable1", db.Tables[0].Name);
                Assert.AreEqual("thereplication1", db.Tables[0].Replication);
                Assert.AreEqual("false", db.Tables[0].ValidationExpression);
                Assert.AreEqual("not true", db.Tables[0].ValidationMessage);
                Assert.AreEqual("R", db.Tables[0].ValidationMessageAttribute);
                Assert.AreEqual(3, db.Tables[0].Fields.Count);
                Assert.AreEqual(true, db.Tables[0].Fields[0].CaseSensitive);
                Assert.AreEqual(null, db.Tables[0].Fields[0].ClobCharset);
                Assert.AreEqual(null, db.Tables[0].Fields[0].ClobCollation);
                Assert.AreEqual(0, db.Tables[0].Fields[0].ClobType);
                Assert.AreEqual("thecollabel1", db.Tables[0].Fields[0].ColumnLabel);
                Assert.AreEqual("T", db.Tables[0].Fields[0].ColumnLabelAttribute);
                Assert.AreEqual(UoeDatabaseDataType.Character, db.Tables[0].Fields[0].DataType);
                Assert.AreEqual(0, db.Tables[0].Fields[0].Decimals);
                Assert.AreEqual("thedesc1", db.Tables[0].Fields[0].Description);
                Assert.AreEqual(2, db.Tables[0].Fields[0].Extent);
                Assert.AreEqual("x(10)", db.Tables[0].Fields[0].Format);
                Assert.AreEqual("T", db.Tables[0].Fields[0].FormatAttribute);
                Assert.AreEqual("thehelp1", db.Tables[0].Fields[0].Help);
                Assert.AreEqual("T", db.Tables[0].Fields[0].HelpAttribute);
                Assert.AreEqual("theinitial1", db.Tables[0].Fields[0].InitialValue);
                Assert.AreEqual("T", db.Tables[0].Fields[0].InitialValueAttribute);
                Assert.AreEqual("thelabel1", db.Tables[0].Fields[0].Label);
                Assert.AreEqual("T", db.Tables[0].Fields[0].LabelAttribute);
                Assert.AreEqual(null, db.Tables[0].Fields[0].LobArea);
                Assert.AreEqual(0, db.Tables[0].Fields[0].LobBytes);
                Assert.AreEqual(null, db.Tables[0].Fields[0].LobSize);
                Assert.AreEqual(true, db.Tables[0].Fields[0].Mandatory);
                Assert.AreEqual("thefield1", db.Tables[0].Fields[0].Name);
                Assert.AreEqual(10, db.Tables[0].Fields[0].Order);
                Assert.AreEqual(2, db.Tables[0].Fields[0].Position);
                Assert.AreEqual(null, db.Tables[0].Fields[0].Triggers);
                Assert.AreEqual(44, db.Tables[0].Fields[0].Width);
                Assert.AreEqual(false, db.Tables[0].Fields[1].CaseSensitive);
                Assert.AreEqual(null, db.Tables[0].Fields[1].ClobCharset);
                Assert.AreEqual(null, db.Tables[0].Fields[1].ClobCollation);
                Assert.AreEqual(0, db.Tables[0].Fields[1].ClobType);
                Assert.AreEqual(null, db.Tables[0].Fields[1].ColumnLabel);
                Assert.AreEqual(null, db.Tables[0].Fields[1].ColumnLabelAttribute);
                Assert.AreEqual(UoeDatabaseDataType.Integer, db.Tables[0].Fields[1].DataType);
                Assert.AreEqual(0, db.Tables[0].Fields[1].Decimals);
                Assert.AreEqual("", db.Tables[0].Fields[1].Description);
                Assert.AreEqual(0, db.Tables[0].Fields[1].Extent);
                Assert.AreEqual("9999", db.Tables[0].Fields[1].Format);
                Assert.AreEqual(null, db.Tables[0].Fields[1].FormatAttribute);
                Assert.AreEqual("", db.Tables[0].Fields[1].Help);
                Assert.AreEqual("", db.Tables[0].Fields[1].HelpAttribute);
                Assert.AreEqual("0", db.Tables[0].Fields[1].InitialValue);
                Assert.AreEqual(null, db.Tables[0].Fields[1].InitialValueAttribute);
                Assert.AreEqual(null, db.Tables[0].Fields[1].Label);
                Assert.AreEqual(null, db.Tables[0].Fields[1].LabelAttribute);
                Assert.AreEqual(null, db.Tables[0].Fields[1].LobArea);
                Assert.AreEqual(0, db.Tables[0].Fields[1].LobBytes);
                Assert.AreEqual(null, db.Tables[0].Fields[1].LobSize);
                Assert.AreEqual(true, db.Tables[0].Fields[1].Mandatory);
                Assert.AreEqual("thefield2", db.Tables[0].Fields[1].Name);
                Assert.AreEqual(20, db.Tables[0].Fields[1].Order);
                Assert.AreEqual(3, db.Tables[0].Fields[1].Position);
                Assert.AreEqual(1, db.Tables[0].Fields[1].Triggers.Count);
                Assert.AreEqual(4, db.Tables[0].Fields[1].Width);
                Assert.AreEqual(3, db.Tables[0].Indexes.Count);
                Assert.AreEqual(true, db.Tables[0].Indexes[0].Active);
                Assert.AreEqual("Index Area", db.Tables[0].Indexes[0].Area);
                Assert.AreEqual(36396, db.Tables[0].Indexes[0].Crc);
                Assert.AreEqual("thedesc1", db.Tables[0].Indexes[0].Description);
                Assert.AreEqual("theindex1", db.Tables[0].Indexes[0].Name);
                Assert.AreEqual(1, db.Tables[0].Indexes[0].Fields.Count);
                Assert.AreEqual(false, db.Tables[0].Indexes[0].Primary);
                Assert.AreEqual(false, db.Tables[0].Indexes[0].Unique);
                Assert.AreEqual(true, db.Tables[0].Indexes[0].Word);
                Assert.AreEqual(true, db.Tables[0].Indexes[1].Active);
                Assert.AreEqual("Index Area", db.Tables[0].Indexes[1].Area);
                Assert.AreEqual(16650, db.Tables[0].Indexes[1].Crc);
                Assert.AreEqual("desc2", db.Tables[0].Indexes[1].Description);
                Assert.AreEqual(1, db.Tables[0].Indexes[1].Fields.Count);
                Assert.AreEqual(false, db.Tables[0].Indexes[1].Fields[0].Abbreviate);
                Assert.AreEqual(true, db.Tables[0].Indexes[1].Fields[0].Ascending);
                Assert.AreEqual("theindex2", db.Tables[0].Indexes[1].Name);
                Assert.AreEqual(true, db.Tables[0].Indexes[1].Primary);
                Assert.AreEqual(true, db.Tables[0].Indexes[1].Unique);
                Assert.AreEqual(false, db.Tables[0].Indexes[1].Word);
                Assert.AreEqual(1, db.Tables[0].Triggers.Count);
                Assert.AreEqual(0, db.Tables[0].Triggers[0].Crc);
                Assert.AreEqual(UoeDatabaseTriggerEvent.Create, db.Tables[0].Triggers[0].Event);
                Assert.AreEqual(true, db.Tables[0].Triggers[0].Overridable);
                Assert.AreEqual("theproc1", db.Tables[0].Triggers[0].Procedure);
                Assert.AreEqual("Data Area", db.Tables[1].Area);
                Assert.AreEqual(94, db.Tables[1].Crc);
                Assert.AreEqual("", db.Tables[1].Description);
                Assert.AreEqual("thetable2", db.Tables[1].DumpName);
                Assert.AreEqual(11, db.Tables[1].Fields.Count);
                Assert.AreEqual(null, db.Tables[1].Foreign);
                Assert.AreEqual(false, db.Tables[1].Frozen);
                Assert.AreEqual(false, db.Tables[1].Hidden);
                Assert.AreEqual(null, db.Tables[1].Indexes);
                Assert.AreEqual(null, db.Tables[1].Label);
                Assert.AreEqual(null, db.Tables[1].LabelAttribute);
                Assert.AreEqual("thetable2", db.Tables[1].Name);
                Assert.AreEqual(null, db.Tables[1].Replication);
                Assert.AreEqual(null, db.Tables[1].Triggers);
                Assert.AreEqual(UoeDatabaseTableType.T, db.Tables[1].Type);
                Assert.AreEqual(null, db.Tables[1].ValidationExpression);
                Assert.AreEqual("", db.Tables[1].ValidationMessage);
                Assert.AreEqual(null, db.Tables[1].ValidationMessageAttribute);
            }

            env.Dispose();
        }
Beispiel #8
0
        public void AppendDatabaseConnection()
        {
            var args = new UoeProcessArgs().Append(new List <UoeDatabaseConnection> {
                UoeDatabaseConnection.NewMultiUserConnection(new UoeDatabaseLocation("data")), UoeDatabaseConnection.NewSingleUserConnection(new UoeDatabaseLocation("data"))
            });

            Assert.AreEqual(5, args.Count(), "should have -db data -db data -1");
        }